微软2014实习生及校招秋令营技术类职位在线测试第二题


ime Limit: 10000ms
Case Time Limit: 1000ms
Memory Limit: 256MB


Description

Consider a string set that each of them consists of {0, 1} only. All strings in the set have the same number of 0s and 1s. Write a program to find and output the K-th string according to the dictionary order. If s​uch a string doesn’t exist, or the input is not valid, please output “Impossible”. For example, if we have two ‘0’s and two ‘1’s, we will have a set with 6 different strings, {0011, 0101, 0110, 1001, 1010, 1100}, and the 4th string is 1001.


Input


The first line of the input file contains a single integer t (1 ≤ t ≤ 10000), the number of test cases, followed by the input data for each test case.
Each test case is 3 integers separated by blank space: N, M(2 <= N + M <= 33 and N , M >= 0), K(1 <= K <= 1000000000). N stands for the number of ‘0’s, M stands for the number of ‘1’s, and K stands for the K-th of string in the set that needs to be printed as output.

Output


For each case, print exactly one line. If the string exists, please print it, otherwise print “Impossible”. 

Sample In


3
2 2 2
2 2 7
4 7 47


Sample Out


0101
Impossible
01010111011



#include <iostream>
using namespace std;
int d2(int n)
{
	int s=1;
	if(n==0)
		return 1;
	for(int i=1;i<=n;i++)
		s=s*2;
	return s;
}
int main(void)
{	
	int m,i,j,ci,n[10000][5];
	int s[100][100],p=0,q=0,u=0,v=0,l=0,f=0,k=0;
	cin>>m;
	for(i=0;i<m;i++)
		for(j=0;j<3;j++)
			cin>>n[i][j];
	for(f=0;f<m;f++)
	{
		ci=n[f][0]+n[f][1];
	//	cout<<"ci="<<ci<<endl;
		for(i=0;i<d2(ci);i++)
		{
		//	cout<<"d2(ci)="<<d2(ci)<<endl;
			k=i;
			q=0;
			for(j=0;j<ci;j++)
			{
				
				s[p][q]=k%2;
				k=k/2;
				if(s[p][q]==0)
					u++;
				else
					v++;
				q++;
			}
			if(u==n[f][0]&&v==n[f][1])
			{
				p++;
			}
			u=0;
			v=0;
		}
		if(n[f][2]<=p)
			{
				l=n[f][2]-1;
				for(i=ci-1;i>=0;i--)
					cout<<s[l][i];
				cout<<endl;
			}
		else
			cout<<"Impossible"<<endl;
		p=0;
	
	}
    return 0;
}



你可能感兴趣的:(微软2014实习生及校招秋令营技术类职位在线测试第二题)