Codeforces Round 873 (Div. 2)
思路:每个数为i时都为i的倍数,前n个数和为Sn=n*(n+1)/2,可知每个数再乘n,Sn必为n的倍数
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>PII; typedef pair<string,int>PSI; const int N=3e5+5,INF=0x3f3f3f3f,Mod=998244353; const double eps=1e-6; typedef long long ll; //#define int long long int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t,n; cin>>t; while(t--){ cin>>n; for(int i=1;i<=n;++i)cout<<i*2<<' '; cout<<'\n'; } return 0; }View Code
思路:求出每个数到最终位置的移动距离,求gcd
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>PII; typedef pair<string,int>PSI; const int N=2e5+5,INF=0x3f3f3f3f,Mod=998244353; const double eps=1e-6; typedef long long ll; //#define int long long int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t,n,a[N],b[N]; cin>>t; while(t--){ cin>>n; int ans; for(int i=0;i<=n;++i)b[i]=0; for(int i=1;i<=n;++i){ cin>>a[i]; if(i==1)ans=abs(a[i]-i); else ans=__gcd(ans,abs(a[i]-i)); } cout<<ans<<'\n'; } return 0; }View Code
思路:对于每个bi,统计a中大于其的个数;将b和a排序,用二分即可,统计时要减去已确定的bi
#include<bits/stdc++.h> using namespace std; typedef pair<int,int>PII; typedef pair<string,int>PSI; const int N=2e5+5,INF=0x3f3f3f3f,Mod=1e9+7; const double eps=1e-6; typedef long long ll; //#define int long long bool cmp(int a,int b){ return a>b; } int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t,n,a[N],b[N]; cin>>t; while(t--){ cin>>n; for(int i=0;i<n;++i)cin>>a[i]; for(int i=0;i<n;++i)cin>>b[i]; sort(b,b+n,cmp); sort(a,a+n); ll res=1; for(int i=0;i<n;++i){ int p= upper_bound(a,a+n,b[i])-a; int c=n-p;//cout<<c<<' '; if(p==-1||c-i<0){ res=0; break; } res=(res*(c-i)*1ll)%Mod; } cout<<res<<'\n'; } return 0; }View Code
标签:typedef,const,int,Codeforces,cin,long,873,tie,Div From: https://www.cnblogs.com/bible-/p/17405035.html