hdu 1416Gizilch(dfs 深搜)

本文介绍了一种名为Gizilch的游戏,玩家通过吃编号葡萄来累计分数,最终分数由葡萄编号相乘得出。文章分析了如何判断玩家是否虚报分数,并提供了一个算法解决方案,确保了游戏的公平性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Problem Description

The game of gizilch has very simple rules. First 100 grapes are labeled, in nontoxic ink, with the numbers 1 to 100. Then, with a cry of GIZILCH!'', the referee fires the grapes up into the air with a giant gizilcher. The two players, who each start with a score of1’’, race to eat the falling (or, shortly thereafter, fallen) grapes and, at the same time, multiply their scores by the numbers written on the grapes they eat. After a minute, the hungry squirrels are let loose to finish the remaining grapes, and each contestant reports his score, the product of the numbers on the grapes he’s eaten. The unofficial winner is the player who announces the highest score.
Inevitably, though, disputes arise, and so the official winner is not determined until the disputes are resolved. The player who claims the lower score is entitled to challenge his opponent’s score. The player with the lower score is presumed to have told the truth, because if he were to lie about his score, he would surely come up with a bigger better lie. The challenge is upheld if the player with the higher score has a score that cannot be achieved with grapes not eaten by the challenging player. So, if the challenge is successful, the player claiming the lower score wins.

So, for example, if one player claims 343 points and the other claims 49, then clearly the first player is lying; the only way to score 343 is by eating grapes labeled 7 and 49, and the only way to score 49 is by eating a grape labeled 49. Since each of two scores requires eating the grape labeled 49, the one claiming 343 points is presumed to be lying.

On the other hand, if one player claims 162 points and the other claims 81, it is possible for both to be telling the truth (e.g. one eats grapes 2, 3 and 27, while the other eats grape 81), so the challenge would not be upheld.

Unfortunately, anyone who is willing to referee a game of gizilch is likely to have himself consumed so many grapes (in a liquid form) that he or she could not reasonably be expected to perform the intricate calculations that refereeing requires. Hence the need for you, sober programmer, to provide a software solution.

Input

Pairs of unequal, positive numbers, with each pair on a single line, that are claimed scores from a game of gizilch.

Output

Numbers, one to a line, that are the winning scores, assuming that the player with the lower score always challenges the outcome.

Sample Input

343 49
3599 610
62 36

Sample Output

49
610
62
题意:两个人比赛吃葡萄,葡萄的编号是1~100,每吃一个葡萄就会相应的乘以这个葡萄的编号。吃完后报两个数,代表自己的成绩。有可能虚报。如果两个人都有可能虚报或者都没有虚报,就是数字大的人获胜。如果数字大的人说谎了,就是数字小的人获胜了。
分析:由于每个葡萄只有一个,所以就像第一个样例343和49,49*7=343。但是编号49的葡萄只有一个,那么343就说谎了。如果说49说谎了,那为什么不说大了??这样看来,就是343说谎了,获胜的就是49。如果a(声明得分是a的人)
吃了葡萄i,必须a%i==0
如果搜索到i,以前a的得分是s[i-1],b的是t[i-1];
那么i如果是 a吃,必须
(a/s[i-1])%i == 0

在吃i后,s[i]=s[i-1]*i;

如果到某步后,a=s[i];且b=t[i],
说明a,b都是真实的,否则有一个是不真实的。
代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int flag;
int fuck;
int maxx;
int minn;
int f[101];

int dfs(int t)
{
	if(t==1)
	{
		if(flag==0)
		{
			fuck=1;
			flag=1;
			if(dfs(maxx)) return 1;
			else
			{
				flag=0;
				return 0;
			}
		}
		return 1;
	}
	int len=100<t?100:t;
	for(int i=2;i<=len;i++)
	{
		if(t%i==0&&f[i]==0)
		{
			f[i]=1;
			if(dfs(t/i)) return 1;
			f[i]=0;
		}
	}
	return 0;
}
int main()
{
	int x,y;
	while(scanf("%d%d",&x,&y)!=EOF)
	{
		int ans;
		flag=0;
		fuck=0;
		maxx=max(x,y);
		minn=min(x,y);
		memset(f,0,sizeof(f));
		int tt = dfs(minn);
		if(fuck==0) ans=maxx;
		else if(fuck==1&&tt==1) ans=maxx;
		else ans=minn;
		printf("%d\n",ans);
	}
	return 0;
}

努力加油a啊,(o)/~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值