M Cook Pancakes!
对于N个饼,显然需要fry 2N次;
考虑最优的情况,显然在每次都同时fry K次
即答案为 【2N/K】
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,K;
cin>>N>>K;
if(N<=K)cout<<2<<endl;
else{
cout<<ceil(2.0*N/K);
}
}
G Xor Transformation
显然 X xor X=0 、 Y xor 0=Y 则 X xor X xor Y=Y;
由于X只能在[0,x)范围内异或,所以考虑两种情况
1: X xor Y > X
则 (X xor Y) xor X =Y
2: X xor Y < X
则 X xor (X xor Y) =Y
#include<bits/stdc++.h>
using namespace std;
int main(){
long long x,y;cin>>x>>y;
if((x^y)>x){
cout<<2<<endl;
cout<<y<<' '<<x;
}
else{
cout<<1<<endl;
cout<<(x^y);
}
}
C Stone Game
a[1]表示有一个石头的堆,以此类推。
则a[3]具有以下性质:1:和其他堆合并不花费coins;2:和其他堆合并不改变 (c mod 3)的值; 因此,不考虑有a[3]。
#include<bits/stdc++.h>
using namespace std;
int main(){
vector<long long > a(4);
cin>>a[1]>>a[2]>>a[3];
if(a[1]>=a[2])
{
cout<<(a[1]-a[2])/3*3+2*a[2]+(((a[1]-a[2])%3==2)?1:0);
}
else{
cout<<2*a[1]+(a[2]-a[1])/3*6+(((a[2]-a[1])%3==2)?(int)4:0);
}
}