本文主要是介绍Codeforces Round #818 (Div. 2) A-C,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
人类智慧
A.
题意:求满足1<=a,b<=n且lcm(a,b)/gcd(a,b)<=3的(a,b)的个数
转化
a/gcd*b*gcd<=3
可以划归为1*2 1*1 2*1 3*1 1*3 则可以转变成一个统计倍数问题
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define int long long
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int qmi(int a,int b,int mod){int res=1;while(b){if(b&1)res=res*a%mod;b>>=1;a=a*a%mod;}return res;}int n,q,m;// int e[N],ne[N],w[N],h[N],idx;
// void add(int a,int b,int c){// e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
// }void solve()
{cin>>n;cout<<n+(n/2+n/3)*2<<"\n";}signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;cin>>_;//_ = 1;while(_--)solve();return 0;
}
B.经典的构造经典的不会
很平凡的容易想到斜着填数字,但是你知道把基本块扩展一下就好了
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define int long long
const int N = 1e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int qmi(int a,int b,int mod){int res=1;while(b){if(b&1)res=res*a%mod;b>>=1;a=a*a%mod;}return res;}int n,q,m,k,r,c;// int e[N],ne[N],w[N],h[N],idx;
// void add(int a,int b,int c){// e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
// }void solve()
{cin>>n>>k>>r>>c; for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)if(((i+j-r-c)%k+k)%k==0)cout<<"X";else cout<<".";cout<<"\n"; }}signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;cin>>_;//_ = 1;while(_--)solve();return 0;
}
C.又是经典的构造 经典的不会
容易想到a大于b肯定不行,然后只要不会出现 ai 还没到达上界 但是bi>bi+1+1都合法 很正确
但是想不到,也不是难就是菜
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define int long long
const int N = 2e5+10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int qmi(int a,int b,int mod){int res=1;while(b){if(b&1)res=res*a%mod;b>>=1;a=a*a%mod;}return res;}
int a[N];
int b[N];int n;// int e[N],ne[N],w[N],h[N],idx;
// void add(int a,int b,int c){// e[idx] = b,ne[idx] = h[a],w[idx] = c,h[a] = idx++;
// }void solve()
{cin>>n;for(int i=1;i<=n;i++)cin>>a[i];for(int i=1;i<=n;i++)cin>>b[i];for(int i=1;i<=n;i++){if(a[i]>b[i]){cout<<"NO\n";return;}}for(int i=1;i<=n;i++){if(a[i]==b[i])continue;if(b[i]>b[i%n+1]+1){cout<<"NO\n";return;}}cout<<"YES\n";}signed main()
{ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);int _;cin>>_;//_ = 1;while(_--)solve();return 0;
}
这篇关于Codeforces Round #818 (Div. 2) A-C的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!