Codeforces Round #701 (Div. 2) D. Multiples and Power Differences(构造)

题意:

给出一个 n ⋅ m n \cdot m nm 的矩阵a,构造出一个矩阵b,满足b的大小和a一样, b [ i ] [ j ] b[i][j] b[i][j] a [ i ] [ j ] a[i][j] a[i][j]的倍数,且b中相邻元素之差的绝对值是 k 4 k^4 k4,k为任意整数。

题解:

先考虑两个数x,y,可以先将他们同时变成变成 l c m ( x , y ) lcm(x,y) lcm(x,y),再将y变成 l c m ( x , y ) + y 4 lcm(x,y)+y^4 lcm(x,y)+y4,这样就可以满足要求。

然后再考虑给哪些数加上4次方:每隔一个加

10101 1 0 1 0 1 10101

01010 0 1 0 1 0 01010

就像这个样子。

代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<ctime>
#define iss ios::sync_with_stdio(false)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int>pii;
const int MAXN=1e5+2;
const int mod=100000000;
const int inf=0x3f3f3f3f;
int maze[505][505];
int gcd(int a,int b)
{
    
    
    return b?gcd(b,a%b):a;
}
int main()
{
    
    
    int n,m;
    cin>>n>>m;
    int lc;
    for(int i=1;i<=n;i++)
    {
    
    
        for(int j=1;j<=m;j++)
        {
    
    
            cin>>maze[i][j];
            if(i==1&&j==1) lc=maze[i][j];
            else lc=lc*maze[i][j]/gcd(lc,maze[i][j]);
        }
    }
    int flag;
    for(int i=1;i<=n;i++)
    {
    
    
        if(i&1) flag=0;
        else flag=1;
        for(int j=1;j<=m;j++)
        {
    
    
            if(flag==0)
            {
    
    
                cout<<lc<<" ";
            }
            else cout<<lc+maze[i][j]*maze[i][j]*maze[i][j]*maze[i][j]<<" ";
            flag^=1;
        }
        cout<<endl;
    }
}

猜你喜欢

转载自blog.csdn.net/weixin_45755679/article/details/113820443