Codeforces Round 893 (Div. 2)
Codeforces Round 893 (Div. 2)
A - Buttons
思路:将第三种按钮平分给两人,若第一个人的按钮数大于第二个人则First
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=200+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int a,b,c;cin>>a>>b>>c; a+=((c+1)/2),b+=(c/2); if(a>b)cout<<"First\n"; else cout<<"Second\n"; return; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }
B - The Walkway
思路:由于n的范围为[1,1e9],m的范围为[1,1e5],枚举出移除每个店之后吃掉的饼干总数;
先求出不算上在店吃的饼干总数,每两个店之间的饼干数为(f[i]-f[i-1]-1)/d,枚举移除每个店时,加上m-1即可;
在位置1时一定要吃饼干,令f[0]为1的上一个要吃饼干的位置,即f[0]=1-d;在位置n时不一定吃饼干,将n放进求饼干数的范围内,即f[m+1]=1+n;
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=250+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void init(){ } void solve(){ int n,m,d;cin>>n>>m>>d; vector<int>f(m+5); for(int i=1;i<=m;++i)cin>>f[i]; f[m+1]=n+1,f[0]=1-d; int sum=0,mi=INF; for(int i=1;i<=m+1;++i)sum+=(f[i]-f[i-1]-1)/d;//(l,r) vector<int>le(m+5); for(int i=1,s;i<=m;++i){ s=sum; s-=((f[i]-f[i-1]-1)/d+(f[i+1]-f[i]-1)/d); s+=(f[i+1]-f[i-1]-1)/d; s+=(m-1); le[i]=s; mi=min(mi,le[i]); } int cnt=0; for(int i=1;i<=m;++i)cnt+=(le[i]==mi); cout<<mi<<' '<<cnt<<'\n'; return; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; cin>>t; init(); while(t--){ solve(); } return 0; }
C - Yet Another Permutation Problem
思路:对于(ai,ai+1),当ai要贡献时(gcd为ai),至少ai+1=2ai;
最多有(1,2)(2,4)(3,6)(4,8)(5,10)...(n/2,n)对,即最多有n/2个;
i从1开始枚举,后面接2i(2i<=n)即可
#include<bits/stdc++.h> using namespace std; #define int long long //#define int __int128 #define double long double typedef pair<int,int>PII; typedef pair<string,int>PSI; typedef pair<string,string>PSS; const int N=200+5,INF=0x3f3f3f3f,Mod=1e9+7,mod=998244353; const double eps=1e-6; void solve(){ int n;cin>>n; vector<int>st(n+1,0); vector<int>ans; ans.push_back(1);st[1]=1; for(int i=2,j;i<=n;++i){ if(st[i])continue; j=i; while(j<=n){ ans.push_back(j);st[j]=1; j*=2; } } for(auto v:ans)cout<<v<<' ';cout<<'\n'; return; } signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int t=1; cin>>t; while(t--){ solve(); } return 0; }