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

传送门

题意: 给定一个矩阵 a a a,让你构造一个矩阵 b b b,要求矩阵 b b b的每个元素是 a a a对应位置元素的倍数,且矩阵 b b b的每两个相邻元素相差为 k 4 ( k > = 1 ) k^4(k>=1) k4(k>=1)注意 a a a的元素范围是 1 < = a < = 16 1<=a<=16 1<=a<=16

思路: 先解决倍数的问题。看到 a a a的元素范围如此的小,一定是有用的。考虑倍数跟 l c m lcm lcm有关系,所以我们不妨求一下每个数的 l c m lcm lcm,即 l c m ( 1 , 2 , . . . , 16 ) lcm(1,2,...,16) lcm(1,2,...,16),可以发现最大是 720720 < 1 e 6 720720<1e6 720720<1e6,这样就简单了,我们直接把 b b b的每个数都写成 720720 720720 720720,这样就保证了都是 a a a的倍数了。
下面我们解决相邻差 k 4 k^4 k4。可以发现 1 6 4 + 720720 < 1 e 6 16^4+720720<1e6 164+720720<1e6,所以我们考虑将某些数加上 a i , j 4 a_{i,j}^4 ai,j4。显然可以根据 i + j i+j i+j分出来奇偶,选奇数加上 a i , j 4 a_{i,j}^4 ai,j4即可。

//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid (tr[u].l+tr[u].r>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;

//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

const int N=510,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;

int n,m;
int a[N][N];

int lcm(int a,int b)
{
    
    
    return a/__gcd(a,b)*b;
}

int main()
{
    
    
//	ios::sync_with_stdio(false);
//	cin.tie(0);

    int lc=1;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&a[i][j]),lc=lcm(lc,a[i][j]);
    for(int i=1;i<=n;i++)
    {
    
    
        for(int j=1;j<=m;j++)
        {
    
    
            if((i+j)%2==1) printf("%d ",lc);
            else printf("%d ",lc+a[i][j]*a[i][j]*a[i][j]*a[i][j]);
        }
        puts("");
    }


	return 0;
}
/*

*/



猜你喜欢

转载自blog.csdn.net/m0_51068403/article/details/114128233