2018.10.06 测试

T1

搜索水题,然后辣鸡南瓜学到了许多...比如Linux下用换底公式会gg,就只能直接调用log2这个函数,然后是string居然可以直接比大小???还可以直接相加????zz南瓜还手写判断合并然后炸了,自闭现场

#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#define maxn 8000000
using namespace std;

bool flag;
int r,p,s,sum,len;
int a[maxn],c[maxn];

int read()
{
	int xx=0,kk=1;char ch=' ';
	while(!isdigit(ch)){ch=getchar();if(ch=='-')kk=-1;}
	while(isdigit(ch)){xx=xx*10+ch-'0';ch=getchar();}
	return kk*xx;
}

bool check()
{
	for(int i=1;i<=3;++i)
		if(a[i]<0) return false;
	return true;
}

void dfs(int now,int pos,int dep)
{
	if(a[now]<0) return;
	c[pos]=now;
	if(dep==len) return;
	int tmp=now%3+1;a[tmp]--;
	dfs(tmp,pos<<1,dep+1);
	dfs(now,pos<<1|1,dep+1);
}

string write(int pos,int dep)
{
	if(dep==len)
	{
		if(c[pos]==1) return "P";
		if(c[pos]==2) return "R";
		if(c[pos]==3) return "S";
	}
	string a=write(pos<<1,dep+1),b=write(pos<<1|1,dep+1);
	return a<b?a+b:b+a;
}

int main()
{
	freopen("rps.in","r",stdin);
	freopen("rps.out","w",stdout);
	r=read(),p=read(),s=read();
	sum=r+p+s,len=log2(sum)
	for(int i=1;i<=3;++i)
	{
		a[1]=p,a[2]=r,a[3]=s;
		a[i]--;dfs(i,1,0);
		if(check())
		{
			flag=true;
			break;
		} 
	}
	if(flag) cout<<write(1,0)<<endl;
	else puts("IMPOSSIBLE");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40942982/article/details/82952056