## B - Unlucky Teacher

Ali is a teacher in one of Kuwait universities. Last week he made a multi-choice test for his students. After the test, he marked some papers before collecting all papers and going home. However, he discovered that he forgot the solution key at the university. He is sure that he didn’t make any mistake in correcting papers, so in order to complete the correction process, he decided to extract the solution key from the papers that have already been marked.

Ali knows that each question should have one and only one correct choice, can you help him with extracting the correct answers for all the questions?

Input
The first line of the input is a single integer T, the number of test cases. Each test case will consist of several lines. The first line contains 2 integers separated by a single space: (1 ≤ Q ≤ 100 and 0  ≤ M ≤ 100) representing the number of questions in the test, and the number of the corrected papers, respectively. Each of the next M lines will contain 2Q upper case letters separated by single spaces: qi ai ( {‘A’,‘B’,‘C’,‘D’} and {‘T’,‘F’}) representing the student answer for the ith question (from a corrected paper) and the status of the student answer ‘T’ if it is True or ‘F’ if it is False.

Output
For each test case, print a single line contains Q characters separated by single spaces: {‘A’,‘B’,‘C’,‘D’,’?’}) representing the correct answer of ith question that could be extracted from the given corrected papers or ‘?’ in case it could not be determined.

Examples
Input
2
3 2
A F B F C T
B T C F D F
1 3
A F
B F
C F
Output
B ? C
D

``````#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
vector<int>G[110],val[110],ans;
map<int,int>S;
int main()
{

int t;
cin>>t;
while(t--)
{

int q,m;
cin>>q>>m;
S.clear();
ans.clear();
for(int i=1;i<=m;i++)
{

val[i].clear();
G[i].clear();
for(int j=1;j<=q;j++)
{

char a[2],b[2];
cin>>a>>b;
G[i].push_back(a[0]-'A'+1);
if(b[0]=='T')
val[i].push_back(1);
else
val[i].push_back(0);
}
}
for(int i=0;i<=q-1;i++)
{

S.clear();
for(int j=1;j<=m;j++)
{

int cc=G[j][i];
int value=val[j][i];
if((int)ans.size()==i+1)
break;
if(value==1)
ans.push_back(cc);
else
S[cc]=1;
}
if((int)ans.size()==i+1)
continue;
int id=-1,cnt=0;
for(int j=1;j<=4;j++)
{

if(S[j]==0)
{

id=j;
cnt++;
}
}
if(cnt==1)
ans.push_back(id);
else
ans.push_back(0);
}
for(int i=0;i<=ans.size()-1;i++)
{

printf("%c%c",ans[i]?ans[i]+'A'-1:'?',i==(int)ans.size()-1?'\n':' ');
}
}
return 0;
}

``````

## I - Salem Gym - 100814I

Salem is known to be one of the best competitive programmers in the region. However, he always finds a hard time understanding the concept of the hamming distance. The hamming distance of two numbers is defined as the number of different digits in their binary representations (leading zeros are used if necessary to make the binary representations have the same length). For example the hamming distance between 12 and 5 is 2 since their binary representations are 1100 and 0101 respectively and they differ in the first and fourth positions.

Recently, Salem got a problem that he needs your help to solve. He is given N integers and asked to get the maximum among the hamming distances of all possible pairs of the given integers.

Input
The first line of the input will be a single integer T representing the number of test cases. Followed by T test cases. Each test case will start with a line with single integer (2 ≤ N ≤ 100) representing the number of the integers. Each of the following N lines contains one of the integers (1 ≤ Ai ≤ 10, 000) from the list of the integers.

Output
For each test case print one line consists of one integer representing the maximum hamming distance between all possible pairs from the given integers.

Examples
Input
2
2
12
5
3
1
2
3
Output
2
2

``````#include<bits/stdc++.h>
using namespace std;
int arr[105];
signed main()
{

int n;
cin>>n;
while(n--)
{

int t;
cin>>t;
for(int i=1;i<=t;i++)
{

cin>>arr[i];
}
int ans = -1;
for(int i=1;i<=t;i++)
{

for(int j=i+1;j<=t;j++)
{

int a = arr[i],b = arr[j];
int cnt = 0;
while(a||b){

if((a&1)!=(b&1))cnt++;
a>>=1;b>>=1;
}
ans = max(ans,cnt);
}
}
cout<<ans<<endl;
}
return 0;
}
``````

### Guess you like

Origin blog.csdn.net/a675891/article/details/114935266
Recommended
Ranking
Daily