跳到正文

科技·工程

Card 官方说明

RAYMOND_7约 29 分钟
原文
文章信息与版本

文章信息

发布
2025年3月6日
收录
2025年12月12日
更新
2026年11月20日
篇幅
约 29 分钟

版本

  1. v1当前
  • 规则:

一共五组 bot ,期望难度递增,全部挑战成功通关。

第三组和第四组挑战失败有一次复活机会

每个 bot 采取七局四胜制。

每一局中,双方在每一回合轮流出牌,用户先手。

输入 nn,得到 nn 种手牌权值和当前数量。

出牌规则是,取出自己可重集真子集,计算双方出牌集合对应权值总和比值。

对于比例根据 checkcheck 函数,计算谁获胜/打平。

失败方卡牌归属获胜方。

checkcheck 函数具有一定的随机性。

  • 特殊奖励/惩罚

三连胜会获得随机抽取对手若干张牌给用户。

两连败会失去若干张牌给对手。

每 55 个回合折算最近五个回合胜负数量,例如 3:23:2,4:14:1,先手胜得到奖励,后手胜会得到期望更少奖励和对先手较小惩罚。

  • 特殊指令
  1. All_in 命令,打出所有手牌。

  2. Random 命令,随机打出手牌。

  3. Half 命令,打出每种一半手牌(上取整)。

  4. Throw S 命令,打完 SS 集合内对应种类手牌。

所有的不合法请求会被过滤。

交互库会分析你之前决策辅助自己相对随机决策,而不会参考你当前决策。

C++
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <random>
#include <ctime>
#include <cassert>
#include <unistd.h>

using namespace std;

#define PII pair<int,int>
#define x first
#define y second
#define For(i, l, r) for(int i = l; i <= r; i ++)
#define Rep(i, l, r) for(int i = l; i >= r; i --)

bool START;

void in(int &x)
{
	char c = getchar(); int op = 1;
	while(c > '9' || c < '0') op *= (c == '-' ? -1 : 1), c = getchar();
	for(x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; x *= op;
}

const int N=1400;

int n,m,a[N],V=10,b[N],c[N],d[N],v[N],Z[N];
mt19937 seed(time(0));
uniform_int_distribution<int> d1;

int gen(int x){return d1(seed)%x+1;}
int Gen(int x){return d1(seed)%(x+1);}

int check(double k)
{
	if(k>1&&k<=2)return 1;
	if(k>2&&k<3.5)return Gen(2)==2;
	if(k>=3.5&&k<=5)return 1;
	if(k>5&&k<7)return Gen(3)==3;
	if(k>=7)return gen(k*1.5)>1;
	return 0;
}
int win[N];
int p1[N<<4],p2[N<<4];

bool ENDPOS = 0;
int solve1(int tst)
{
	double bili=1;
	if(tst==1)bili=1.2;
	else if(tst==2)bili=1;
	else if(tst==3) bili=0.9;
	else if(tst==4) bili=0.8;
	else bili=0.75;
	int win1=0,win2=0;
	int f2=0,f1=0,Case=7;
	puts("Match Begins!!");
	For(us,1,Case)
	{
		For(i,1,6)puts("\n");
		puts("---------------------");
		cout<<"Match "<<us<<endl;
	cout<<"input n\n";
	in(n);
	cout<<"Here are the values\n";
	For(i,1,n)v[i]=gen(V);sort(v+1,v+n+1);
	For(i,1,n)cout<< v[i] <<" ";cout<<endl;
	// For(i,1,n)a[i]=c[i]=2;
	For(i,1,n)Z[i]=Gen(5)+7, a[i]=Gen(Z[i]*bili),a[i]=min(a[i],Z[i]),a[i]=max(a[i],1), c[i]=Z[i]-a[i];
	double av=0;
	int w1=0,w2=0,my,his;
	For(ks,1,1000)
	{
		For(i,1,n)d[i]=Gen(c[i]);
		int ss=0,own=0,sa=0,sc=0,ns=0;
		For(i,1,n)sa+=a[i],sc+=c[i];
		For(i,1,n)own+=v[i]*a[i];
		if(ks>1) own=own*av/(ks-1)+1;
		else own=gen(own);
		For(i,1,n)ss+=v[i]*d[i],ns+=c[i]*v[i];
		int ps=0,sui=gen(ns);
		while(!ss||ps<=10)
		{
			if(ks==1) {if(ss>=sui)break;}
			if(ks>1) if((ss>own&&check(ss*1.0/own))||(ss<own&&!check(1.0*own/ss)))break;
			For(i,1,n)d[i]=Gen(c[i]);
			ss=0;
			For(i,1,n)ss+=v[i]*d[i];
			ps++;
		}
		// printf("ss=%d,own=%d\n",ss,own);
		puts("---------------");
		printf("Round #%d\n",ks);
		printf("Card numbers : %d / %d\n",sa,sc);
		cout<<"Give Your Choise\n";
		For(i,1,n) printf("%d ", a[i]);puts("");
		string Boot;
		cin>>Boot;
		For(i,1,n)b[i]=0;
		if(Boot=="All_in") For(i,1,n)b[i]=a[i];
		else if(Boot=="Random")
		{
			For(i,1,n)if(a[i]) b[i]=gen(a[i]);
		}
		else if(Boot=="Half")
		{
			For(i,1,n)if(a[i])b[i]=(a[i]+1)/2;
		}
		else if(Boot=="Throw")
		{
			string Kt;cin>>Kt;for(char c:Kt)b[c-'A'+1]=a[c-'A'+1];
		}
		else for(char c:Boot)b[c-'A'+1]++;
		int zon=0;
		int ca=0;
		For(i,1,n)
		{
			zon+=a[i]*v[i];
			if(b[i]>a[i])b[i]=a[i];ca+=b[i]*v[i];
		}
		av+=1.0*ca/zon;
		while(!ca)
		{
			puts("Wrong Format! input Again!\n");
			cin>>Boot;
			For(i,1,n)b[i]=0;
			for(char c:Boot)b[c-'A'+1]++;
			ca=0;
			For(i,1,n)
			{
				if(b[i]>a[i])b[i]=a[i];ca+=b[i]*v[i];
			}
		}
		printf("current value = %d\n",ca);
		puts("Now wait -----");sleep(1);
		For(i,1,n)For(j,1,d[i])printf("%c", i+'A'-1); printf("\nenermy_val = %d\n", ss);
		if(ca==ss){puts("Tie");win[ks]=0;w1=w2=0;}
		else if((ca>ss&&check(1.0*ca/ss))||(ca<ss&&!check(1.0*ss/ca)))
		{
			printf("You get his cards! /fendou\n");
			For(i,1,n)a[i]+=d[i],c[i]-=d[i];
			win[ks]=1;w1++;w2=0;
		}
		else
		{
			printf("He gets your cards! /ll\n");
			For(i,1,n)c[i]+=b[i],a[i]-=b[i];
			win[ks]=-1;w2++;w1=0;
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break; 0;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break; 0;}
		puts("\n");
		if(w1==3)
		{
			vector<int> vec;
			For(i,1,n)if(c[i])vec.push_back(i);
			shuffle(vec.begin(), vec.end(),seed);
			// c[vec[0]]--;a[vec[0]]++;
			int sz=vec.size();
			For(j,0,min(sz-1,gen(6)+4))c[vec[j]]--,a[vec[j]]++;
			printf("Hat-trick win!\n");
			w1=0;
		}
		if(w2==2)
		{
			vector<int> vec;
			For(i,1,n)if(a[i])vec.push_back(i);
			shuffle(vec.begin(), vec.end(),seed);
			// a[vec[0]]--;c[vec[0]]++;
			int sz=vec.size();
			For(j,0,min(sz-1,gen(4)+2))c[vec[j]]++,a[vec[j]]--;
			printf("Double lose!\n");
			w2=0;
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break; 0;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break; 0;}
		if(ks%5==0)
		{
			int no=0,g1=0,g2=0;
			For(j,ks-4,ks)no+=win[j],g1+=(win[j]==1),g2+=(win[j]==-1);
			p1[0]=p2[0]=0;
			For(i,1,n)For(j,1,a[i])p1[++p1[0]]=i;
			For(i,1,n)For(j,1,c[i])p2[++p2[0]]=i;
			shuffle(p1+1,p1+p1[0]+1,seed);
			shuffle(p2+1,p2+p2[0]+1,seed);
			puts("\n\n\n");
			printf("Part Score %d : %d\n",g1,g2);
			puts("/----------------------/");
			if(!no)
			{
				puts("Both Excellent!!\nReward You And Bot!!");
				int u=gen(6);
				printf("number = %d\n",u);
				For(i,1,u)
				{
					int x=gen(n),y=gen(n);
					printf("New card : %c %c\n",x+'A'-1,y+'A'-1);
					a[x]++;c[y]++;
				}
			}
			else if(no>0)
			{
				puts("You Are Better than Bot!!\nThis Is For You!!");
				int u=gen(8)+8;
				if(no>1)
				{
					if(no==2)u=gen(10)+10;
					else if(no==3) u=gen(12)+12;
					else u=15+gen(15);
				}
				printf("number = %d\n",u);
				For(i,1,u)
				{
					int x=gen(n);a[x]++;
					printf("New card %c\n", x+'A'-1);
				}
			}
			else
			{
				puts("Bot is Great!!\nYou should work harder!!");
				int u=gen(3)+3,v=gen(4)+4;u=min(u,p1[0]);
				if(no<-1)
				{
					if(no==-2)v=gen(5)+5;
					else if(no==-3) v=gen(5)+6;
					else v=gen(6)+6;
				}
				For(i,1,u)
				{
					a[p1[i]]--;
					printf("Delete card(You) : %c\n", p1[i]+'A'-1);
				}
				puts("=======");
				For(i,1,v)
				{
					int x=gen(n);c[x]++;
					printf("New card(Bot) : %c\n", x+'A'-1);
				}
			}
			puts("/----------------------/");
			puts("\n\n\n");
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break;}
		printf("my = %d, his = %d\n",my,his);
		if(ks%2==0)
		{
			printf("val_s -> ");For(i,1,n)printf("%d ", v[i]);puts("");
		}
	}
	f1+=my;f2+=his;
	if(win1==4||win2==4)break;
	}
	puts("\n\n\n\n\n\n\n\n");
	puts("-----------------");
	printf("The Total Score is %d : %d\n",win1,win2);
	printf("Mark is %d : %d\n",f1,f2);
	// puts("Game Over!!\nWelcome next time!");
	puts("-----------------------------------------");
	For(i,1,15) puts("");
	return win1>win2;
}
int dd[N],ee[N];
int sl,sr;
int Win(int x,int y)
{
	if(x==y) return 0;
	if(x>y) return check(x*1.0/y);
	return -check(y*1.0/x);
}

int calc(int ss)
{
	int res=0;
	For(x,sl,sr)
	{
		res+=Win(ss,x);
	}
	return res;
}

int solve2(int tst)
{
	double bili=1;
	if(tst==1)bili=1.3;
	else if(tst==2)bili=1.15;
	else if(tst==3) bili=1;
	else if(tst==4) bili=0.9;
	else bili=0.75;
	int win1=0,win2=0;
	int f2=0,f1=0,Case=7;
	puts("Match Begins!!");
	For(us,1,Case)
	{
		For(i,1,6)puts("\n");
		puts("---------------------");
		cout<<"Match "<<us<<endl;
	cout<<"input n\n";
	in(n);
	cout<<"Here are the values\n";
	For(i,1,n)v[i]=gen(V);sort(v+1,v+n+1);
	For(i,1,n)cout<< v[i] <<" ";cout<<endl;
	// For(i,1,n)a[i]=c[i]=2;
	For(i,1,n)Z[i]=Gen(5)+7, a[i]=Gen(Z[i]*bili),a[i]=min(a[i],Z[i]),a[i]=max(a[i],1), c[i]=Z[i]-a[i];
	double av=0;
	int w1=0,w2=0,my,his;
	For(ks,1,1000)
	{
		For(i,1,n)d[i]=Gen(c[i]);
		int ss=0,own=0,sa=0,sc=0,ns=0;
		For(i,1,n)sa+=a[i],sc+=c[i];
		For(i,1,n)own+=v[i]*a[i];ns=own;
		if(ks>1) own=own*av/(ks-1)+1;
		sl=max(1,own-70);
		sr=min(own+70,ns);
		For(i,1,n)ss+=v[i]*d[i];
		int ps=0;
		if(ks==1)
		{
			ss=0;
			For(i,1,n)d[i]=Gen(c[i]*1.8),d[i]=min(d[i],c[i]),ss+=v[i]*d[i];
			if(!ss) {For(i,1,n)if(c[i]){d[i]=1;ss+=v[i]; break;}}
		}
		else 
		{
			int ans=-1;
			For(i,1,n)ee[i]=d[i];
			if(!ss)
			{
				For(i,1,n)if(c[i]){ee[i]=1;break;}ans=0;
			}
			while(ps<=20)
			{
				if(ss)
				{
					int tmp=calc(ss);
					if(tmp>ans){ans=tmp;For(i,1,n)ee[i]=d[i];}
					// if((ss>own&&check(ss*1.0/own))||(ss<own&&!check(1.0*own/ss)))break;
				}
				For(i,1,n)d[i]=Gen(c[i]*1.1),d[i]=min(d[i],c[i]);
				ss=0;
				For(i,1,n)ss+=v[i]*d[i];
				ps++;
			}
			ss=0;
			For(i,1,n)d[i]=ee[i],ss+=v[i]*d[i];
		}
		// printf("ss=%d,own=%d\n",ss,own);
		puts("---------------");
		printf("Round #%d\n",ks);
		printf("Card numbers : %d / %d\n",sa,sc);
		cout<<"Give Your Choise\n";
		For(i,1,n) printf("%d ", a[i]);puts("");
		string Boot;
		cin>>Boot;
		For(i,1,n)b[i]=0;
		if(Boot=="All_in") For(i,1,n)b[i]=a[i];
		else if(Boot=="Random")
		{
			For(i,1,n)if(a[i]) b[i]=gen(a[i]);
		}
		else if(Boot=="Half")
		{
			For(i,1,n)if(a[i])b[i]=(a[i]+1)/2;
		}
		else if(Boot=="Throw")
		{
			string Kt;cin>>Kt;for(char c:Kt)b[c-'A'+1]=a[c-'A'+1];
		}
		else for(char c:Boot)b[c-'A'+1]++;
		int zon=0;
		int ca=0;
		For(i,1,n)
		{
			zon+=a[i]*v[i];
			if(b[i]>a[i])b[i]=a[i];ca+=b[i]*v[i];
		}
		av+=1.0*ca/zon;
		while(!ca)
		{
			puts("Wrong Format! input Again!\n");
			cin>>Boot;
			For(i,1,n)b[i]=0;
			for(char c:Boot)b[c-'A'+1]++;
			ca=0;
			For(i,1,n)
			{
				if(b[i]>a[i])b[i]=a[i];ca+=b[i]*v[i];
			}
		}
		printf("current value = %d\n",ca);
		puts("Now wait -----");sleep(1);
		For(i,1,n)For(j,1,d[i])printf("%c", i+'A'-1); printf("\nenermy_val = %d\n", ss);
		if(ca==ss){puts("Tie");win[ks]=0;w1=w2=0;}
		else if((ca>ss&&check(1.0*ca/ss))||(ca<ss&&!check(1.0*ss/ca)))
		{
			printf("You get his cards! /fendou\n");
			For(i,1,n)a[i]+=d[i],c[i]-=d[i];
			win[ks]=1;w1++;w2=0;
		}
		else
		{
			printf("He gets your cards! /ll\n");
			For(i,1,n)c[i]+=b[i],a[i]-=b[i];
			win[ks]=-1;w2++;w1=0;
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break; 0;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break; 0;}
		puts("\n");
		if(w1==3)
		{
			vector<int> vec;
			For(i,1,n)if(c[i])vec.push_back(i);
			shuffle(vec.begin(), vec.end(),seed);
			// c[vec[0]]--;a[vec[0]]++;
			int sz=vec.size();
			For(j,0,min(sz-1,gen(6)+4))c[vec[j]]--,a[vec[j]]++;
			printf("Hat-trick win!\n");
			w1=0;
		}
		if(w2==2)
		{
			vector<int> vec;
			For(i,1,n)if(a[i])vec.push_back(i);
			shuffle(vec.begin(), vec.end(),seed);
			// a[vec[0]]--;c[vec[0]]++;
			int sz=vec.size();
			For(j,0,min(sz-1,gen(4)+2))c[vec[j]]++,a[vec[j]]--;
			printf("Double lose!\n");
			w2=0;
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break; 0;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break; 0;}
		if(ks%5==0)
		{
			int no=0,g1=0,g2=0;
			For(j,ks-4,ks)no+=win[j],g1+=(win[j]==1),g2+=(win[j]==-1);
			p1[0]=p2[0]=0;
			For(i,1,n)For(j,1,a[i])p1[++p1[0]]=i;
			For(i,1,n)For(j,1,c[i])p2[++p2[0]]=i;
			shuffle(p1+1,p1+p1[0]+1,seed);
			shuffle(p2+1,p2+p2[0]+1,seed);
			puts("\n\n\n");
			printf("Part Score %d : %d\n",g1,g2);
			puts("/----------------------/");
			if(!no)
			{
				puts("Both Excellent!!\nReward You And Bot!!");
				int u=gen(6);
				printf("number = %d\n",u);
				For(i,1,u)
				{
					int x=gen(n),y=gen(n);
					printf("New card : %c %c\n",x+'A'-1,y+'A'-1);
					a[x]++;c[y]++;
				}
			}
			else if(no>0)
			{
				puts("You Are Better than Bot!!\nThis Is For You!!");
				int u=gen(8)+8;
				if(no>1)
				{
					if(no==2)u=gen(10)+10;
					else if(no==3) u=gen(12)+12;
					else u=15+gen(15);
				}
				printf("number = %d\n",u);
				For(i,1,u)
				{
					int x=gen(n);a[x]++;
					printf("New card %c\n", x+'A'-1);
				}
			}
			else
			{
				puts("Bot is Great!!\nYou should work harder!!");
				int u=gen(3)+3,v=gen(4)+4;u=min(u,p1[0]);
				if(no<-1)
				{
					if(no==-2)v=gen(5)+5;
					else if(no==-3) v=gen(5)+6;
					else v=gen(6)+6;
				}
				For(i,1,u)
				{
					a[p1[i]]--;
					printf("Delete card(You) : %c\n", p1[i]+'A'-1);
				}
				puts("=======");
				For(i,1,v)
				{
					int x=gen(n);c[x]++;
					printf("New card(Bot) : %c\n", x+'A'-1);
				}
			}
			puts("/----------------------/");
			puts("\n\n\n");
		}
		my=0,his=0;
		For(i,1,n)my+=v[i]*a[i],his+=c[i]*v[i];
		if(his==0){printf("my = %d, his = %d\n",my,his);puts("You Win!!!");win1++; break;}
		if(!my){printf("my = %d, his = %d\n",my,his);puts("You Lose!!!");win2++; break;}
		printf("my = %d, his = %d\n",my,his);
		if(ks%2==0)
		{
			printf("val_s -> ");For(i,1,n)printf("%d ", v[i]);puts("");
		}
	}
	f1+=my;f2+=his;
	if(win1==4||win2==4)break;
	}
	puts("\n\n\n\n\n\n\n\n");
	puts("-----------------");
	printf("The Total Score is %d : %d\n",win1,win2);
	printf("Mark is %d : %d\n",f1,f2);
	// puts("Game Over!!\nWelcome next time!");
	puts("-----------------------------------------");
	For(i,1,15) puts("");
	return win1>win2;
}

int main()
{
	puts("There are five monsters here waiting for your challenge");
	string name;
	int fuhuo=0;
	puts("input your favourite TEAM");
	cin>>name;
	puts("Let's Go!!!");
	For(i,1,5)
	{
		int x=gen(2),y;
		if(i==5)x=2;
		printf("TYPE = %d\n",x);
		if(i==1) printf("1/8 Final!!!\n");
		if(i==2) printf("1/4 Final!!!\n");
		if(i==3) printf("1/2 Final!!!\n");
		if(i==4) printf("Western/Eastern Final!!!\n");
		if(i==5) printf("Last Final!!!\n");
		if(x==1) y=solve1(i);
		else y=solve2(i);
		if(!y)
		{
			if(!fuhuo&&i>=3&&i<5)
			{
				fuhuo=1;
				i--;continue;
			}
			printf("Final Standing\n");
			if(i==1) printf("One Round Tour\n");
			if(i==2) printf("1/8 Final\n");
			if(i==3) printf("1/4 Final\n");
			if(i==4) printf("1/2 Final\n");
			if(i==5) printf("Western/Eastern Champion\n");
			puts("Game Over!!\nWelcome next time!");return 0;
		}
	}
	printf("Whole Champion!!!!\n");
	cout <<name<<" ";
	puts("is the champion!!!");
}
原文