1 Buttons
博弈题,先找公共再找自己
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+1;
const int M=1e3+1;
const int MOD=10000007;
void solve(){
int a,b,c;
cin>>a>>b>>c;
int c1=c/2+c%2;
int c2=c-c1;
// cout<<c1<<" "<<c2;
if((a+c1)>(b+c2)) cout<<"First"<<endl;
else cout<<"Second"<<endl;
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
2. The Walkway
读题读了半天后来发现都去写c了,题目不难就是难理解,注意商家在第一个位置的特判
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+1;
const int M=1e3+1;
const int MOD=10000007;
int a[N],b[N];
void solve(){
int n,m,d;
cin>>n>>m>>d;
for(int i=1;i<=m;i++) cin>>a[i];
a[0]=0,b[0]=0;
if(a[1]==1) b[1]=0;
else b[1]=a[1]-2;
for(int i=2;i<=m;i++){
b[i]=a[i]-a[i-1]-1;
}
b[m+1]=n-a[m];
map<int,int>mp;
int res=0;
if(a[1]!=1) res++;
for(int i=1;i<=m;i++){
res+=b[i]/d+1;
}
res+=b[m+1]/d;
int mx=0;
for(int i=2;i<=m;i++){
int x1=b[i]/d+b[i+1]/d+1;
int x2=(b[i]+b[i+1]+1)/d;
mx=max(mx,x1-x2);
mp[x1-x2]++;
}
// 第一个位置的特判
if(a[1]==1){
int x1=b[2]/d+1;
int x2=b[2]/d+1;
mp[x1-x2]++;
mx=max(mx,x1-x2);
}
else{
int x1=b[1]/d+b[2]/d+1;
int x2=(b[1]+b[2]+1)/d;
mx=max(mx,x1-x2);
mp[x1-x2]++;
}
cout<<res-mx<<" "<<mp[mx]<<endl;
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
3.Yet Another Permutation Problem
只要按照1 2 4 8……3 6 12……这样输出就行,输出以后记得标记,避免重复输出,记得清空数组,第一次没清wa了一发
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=3e5+1;
const int M=1e3+1;
const int MOD=10000007;
int a[N];
void solve(){
memset(a,0,sizeof a);
int n;
cin>>n;
cout<<"1"<<" ";
a[1]=1;
for(int i=2;i<=n;i++){
int tmp=i;
while(tmp<=n){
if(!a[tmp]) cout<<tmp<<" ";
a[tmp]=1;
tmp=tmp*2;
}
}
cout<<endl;
}
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}