TJU 3249. Happy Coins
ACCEPTED
Earlier i was trying to code what was written in the problem statement. Then i found that its hard to decide programatically. So i took paper & pen started finding the repeating pattern.
I found this pattern
if we take
lxh->0
hhb->1
Then
=================
when n=2
input1 input2 Ans
0 0 1(hhb)
0 1 0(lxh)
1 0 0(lxh)
1 1 1(hhb)
=====================
when n=3
input1 input2 input3 Ans
0 0 0 0(lxh)
0 0 1 1(hhb)
0 1 0 1(hhb)
0 1 1 0(lxh)
1 0 0 1(hbb)
1 0 1 0(lxh)
1 1 0 0(lxh)
1 1 1 1(hhb)
==================
when n=4
inp1 inp2 inp3 inp4 ans
0 0 0 0 1
0 0 0 1 0
0 0 1 0 0
0 0 1 1 1
0 1 0 0 0
0 1 0 1 1
0 1 1 0 0
0 1 1 1 0
1 0 0 0 0
1 0 0 1 1
1 0 1 0 1
1 0 1 1 0
1 1 0 0 1
1 1 0 1 0
1 1 1 0 0
1 1 1 1 1
====================
my AC code
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main()
{
int cases;
cin>>cases;
int n,turn,zero,one;
string s;
while(cases--){
s="";
cin>>n;
zero=0;one=0;
int tmp=n;
while(tmp--){
cin>>s;
if(s=="lxh") ++zero;
else if(s=="hhb") ++one;
}
if(n%2==0){
if(one%2==0) printf("hhb\n");
else printf("lxh\n");
}
else{
if(one%2!=0) printf("hhb\n");
else printf("lxh\n");
}
}
return 0;
}



Recent Comments