Codeforces1485 D. Multiples and Power Differences(思维,lcm,构造)
作者:互联网
题意:
解法:
lc=lcm(1,2,3,...16)<1e6.
由于限制条件是对相邻格子设立的,
对矩阵黑白染色,那么相同颜色就不会互相影响了,
之后将黑色位置设为lc,白色位置设为lc+a[i][j]^4即可,
显然这样一定满足条件.
code:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=500+5;
int a[maxm][maxm];
int n,m;
int lcm(int a,int b){
return a/__gcd(a,b)*b;
}
int cal(int x){
return x*x*x*x;
}
inline void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
}
}
int lc=1;
for(int i=1;i<=16;i++)lc=lcm(lc,i);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if((i+j)&1)cout<<lc<<' ';
else cout<<lc+cal(a[i][j])<<' ';
}
cout<<endl;
}
}
signed main(){
solve();
return 0;
}
标签:Codeforces1485,return,lc,Power,int,Differences,long,maxm,lcm 来源: https://blog.csdn.net/weixin_44178736/article/details/116381389