HDU1416 POJ1078 UVA653 LA5507 GizilchDFS
Posted 海岛Blog
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU1416 POJ1078 UVA653 LA5507 GizilchDFS相关的知识,希望对你有一定的参考价值。
Gizilch
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 497 Accepted Submission(s): 142
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 of ``1’', 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
Source
ACM暑期集训队练习赛(一)
问题链接:HDU1416 POJ1078 UVA653 LA5507 Gizilch
问题简述:(略)
问题分析:用DFS来解决,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* HDU1416 POJ1078 UVA653 LA5507 Gizilch */
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 100;
int maxab, minab, flagmax, flagmin, vis[N + 1];
int dfs(int n)
if (n == 1)
if (flagmax == 0)
flagmax = flagmin = 1;
if (dfs(maxab)) return 1;
else
flagmax = 0;
return 0;
return 1;
else
for (int i = 2; i <= min(n, N); i++)
if (n % i == 0 && vis[i] == 0)
vis[i] = 1;
if (dfs(n / i)) return 1;
vis[i] = 0;
return 0;
int main()
int a, b;
while (~scanf("%d%d", &a, &b))
maxab = max(a, b);
minab = min(a, b);
flagmax = flagmin = 0;
memset(vis, 0, sizeof vis);
int flag = dfs(minab);
printf("%d\\n", flagmin == 0 || flag == 1 ? maxab : minab);
return 0;
以上是关于HDU1416 POJ1078 UVA653 LA5507 GizilchDFS的主要内容,如果未能解决你的问题,请参考以下文章
UVA1416(LA4080) Warfare And Logistics (单源最短路)
UVA1416/LA4080 Warfare And Logistics
UVA1445 LA4636 POJ3802 Cubist Artwork贪心
UVA275 LA5384 POJ1140 Expanding Fractions循环节
UVA12081 LA3413 POJ2769 Reduced ID Numbers同余
UVA326 LA5434 POJ1538 Extrapolation Using a Difference Table二项式