1004 Black Magic
题意:给出n个方块,每个方块的左/右都可能是黑或白。将这些方块排成一列,如果两个相邻方块相连接的面都是黑色,那么这两个方块会连在一起。求连通块的最大/最小数量。
思路:最小数量:要尽可能的将L , R 凑成一对,对于凑不成的只能单独一个,因此直接找m a x ( L , R ) 即可,B 可以放在L / R的旁边就能形成一个。
最大数量:L L L L R R R R 这样排列每个L 和R都是独立的,如果有B的话,可以选一个B放在L与R的交界处,剩下的B只能与E交错着放。
#include<iostream>
using namespace std;
typedef long long ll;
void solve()
{
int e,l,r,b;
cin>>e>>l>>r>>b;
int t=max(l,r);
int minn;
if(t==0)
minn=e+min(1,b);
else
minn=t+e;
int maxn;
if(e==0)
maxn=l+r+min(1,b);
else
{
if(b<=2)
maxn=l+r+b+e;
else
{
e--;
b-=2;
maxn=l+r+3;
if(b>e) maxn+=e*2;
else maxn+=b+e;
}
}
cout<<minn<<" "<<maxn<<endl;
}
signed main()
{
int t;
t=1;
cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
return 0;
}
1008 Triangle Game
题意:给一个合法的三角形的三边长度,我们和另一个人轮流让三角形的某边递减且仍然是三角形,如果某个人无法继续操作了就输了,我们先手。
思路:这是一个NIM游戏的变形博弈论。 只有在( a − 1 ) ^ ( b − 1 ) ^ ( c − 1 ) ! = 0的时候,先手必胜。
#include<iostream>
#include<cstring>
#include<algorithm>
//#define int long long
using namespace std;
typedef long long ll;
void solve()
{
int a,b,c;
cin>>a>>b>>c;
if((a-1)^(b-1)^(c-1)) puts("Win");
else puts("Lose");
}
signed main()
{
int t;
t=1;
cin>>t;
for(int i=1;i<=t;i++)
{
solve();
}
return 0;
}