毕业设计,毕业论文代写。专业水平。钻石水准,黄金品质。

计算机专业毕业设计,论文,设计代写。电邮:elevenor@gmail.com。专业水平,质优价廉。

原创 浙江大学ACM试题解答(四月)收藏

新一篇: 华容道游戏与算法 | 旧一篇: 浙江大学ACM试题解答(三月)

 (3)

Crashing Balloon

Time limit: 1 Seconds   Memory limit: 32768K  
Total Submit: 7795   Accepted Submit: 1925  

On every June 1st, the Children's Day, there will be a game named "crashing balloon" on TV.   The rule is very simple.  On the ground there are 100 labeled balloons, with the numbers 1 to 100.  After the referee shouts "Let's go!" the two players, who each starts with a score of  "1", race to crash the balloons by their feet and, at the same time, multiply their scores by the numbers written on the balloons they crash.  After a minute, the little audiences are allowed to take the remaining balloons away, and each contestant reports his\her score, the product of the numbers on the balloons he\she's crashed.  The unofficial winner is the player who announced 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\her opponent's score.  The player with the lower score is presumed to have told the truth, because if he\she were to lie about his\her score, he\she 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 balloons not crashed 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 crashing balloons labeled 7 and 49, and the only way to score 49 is by crashing a balloon labeled 49.  Since each of two scores requires crashing the balloon 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 crashes balloons 2, 3 and 27, while the other crashes balloon 81), so the challenge would not be upheld.

By the way, if the challenger made a mistake on calculating his/her score, then the challenge would not be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them are telling the truth. In this case, the challenge would not be upheld.

Unfortunately, anyone who is willing to referee a game of crashing balloon is likely to get over-excited in the hot atmosphere that he\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 crashing balloon.

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

Problem Source: Zhejiang University Local Contest 2001
Submit   Back   Status

Zhejiang University Online Judge V1.0 Book

Sorce Code 1:

#include <stdio.h>
int flag1,flag2;
void dfs ( int n , int m , int fac )
{
if(flag1== 1 )
return ;
if(m==1 && n==1 )
{
flag1=1;
flag2=1;
return;
}
if(m==1)
flag2=1;
if(fac<2 )     
return;
if(n%fac==0)
dfs(n/fac,m,fac-1);
if(m%fac== 0 )
dfs(n,m/fac,fac-1);
dfs(n,m,fac-1);
}
int main()
{
int tmp,n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
if(m>n)
{
tmp=m ;
m=n ;
n=tmp;
}
flag1=flag2=0;
dfs(n,m,100);
if(flag1||!flag2)
printf("%d\n",n);
else if(flag2==1&&flag1==0)
printf("%d\n",m);
}
return 0;
}

Sorce Code 2:

一段本人编写的相形见绌的代码

#include "stdio.h"
#define max 100
#define snock -1
#define flaga 1
#define flagb 2
#define true 1
#define false 0
int totala=0,totalb=0,counta=0,countb=0;
int tempa[max+2]={0},tempb[max+2]={0};
int rega[max*2+2]={0},regb[max*2+2]={0};
int Judge(int,int,int,int);
int Start(int,int);
int FindHead(int,int);
int FindNext(int,int);
int main()
{
int i;
int numa,numb,t;
while(scanf("%d %d",&numa,&numb)!=EOF)
{
t=(numa>numb)?numa:numb;
numb=(numa<numb)?numa:numb;
numa=t;
for(i=0;i<max;i++)
tempa[i]=tempb[i]=0;
for(i=0;i<max*2;i++)
rega[i]=regb[i]=0;
totala=0;
totalb=0;
counta=0;
countb=0;
for(i=2;i<=max;i++)
Judge(0,i,numa,flaga);
for(i=2;i<=max;i++)
Judge(0,i,numb,flagb);
if(totalb==0)
printf("%d\n",numa);
else
if(totala==0)
printf("%d\n",numb);
else
{
i=Start(0,0);
if(i==true)
printf("%d\n",numa);
else
if(i==false)
printf("%d\n",numb);
}
}
return 1;
}
int Judge(int pos,int start,int rem,int flag)
{
int i,t;
if(start>max||rem%start!=0)
return 0;
if(rem/start==1)
{
if(flag==flaga)
{
tempa[pos]=start;
for(i=0;i<=pos;i++)
rega[counta++]=tempa[i];
rega[counta++]=snock;
totala++;
}
else
{
tempb[pos]=start;
for(i=0;i<=pos;i++)
regb[countb++]=tempb[i];
regb[countb++]=snock;
totalb++;
}
}
for(i=start+1;i<=rem/start;i++)
{
if(flag==flaga)
tempa[pos]=start;
else
tempb[pos]=start;
Judge(pos+1,i,rem/start,flag);
}
return 1;
}
int Start(int pa,int pb)
{
if(pa>=counta)
return false;
else
if(regb[pb]==snock)
{
if(rega[pa+1]==snock)
return true;
else
Start(pa+1,FindHead(flagb,pb));
}
else
if(rega[pa]==regb[pb])
{
pb=FindNext(flagb,pb);
pa=FindHead(flaga,pa);
if(pb>=countb)
{
pb=0;
pa=FindNext(flaga,pa);
}
Start(pa,pb);
}
else
Start(pa,pb+1);
}
int FindHead(int flag,int p)
{
int i=p;
if(flag==flaga)
{
if(rega[p]==snock)
i--;
for(;i>=0;i--)
if(rega[i]==snock)
break;
}
else
if(flag==flagb)
{
if(regb[p]==snock)
i--;
for(;i>=0;i--)
if(regb[i]==snock)
break;
}
if(i==0)
return 0;
else
return i+1;
}
int FindNext(int flag,int p)
{
int i;
if(flag==flaga)
{
for(i=p;i<=counta;i++)
if(rega[i]==snock)
break;
}
else
if(flag==flagb)
{
for(i=p;i<=countb;i++)
if(regb[i]==snock)
break;
}
return i+1;
}

更多内容:

麻省理工算法导论翻译
http://blog.csdn.net/ctu_85/archive/2007/06/08/1643179.aspx
浙江大学ACM试题解答(四月)
http://blog.csdn.net/ctu_85/archive/2007/04/24/1576831.aspx
浙江大学ACM试题解答(三月)
http://blog.csdn.net/ctu_85/archive/2007/03/20/1535556.aspx
华容道游戏与算法
http://blog.csdn.net/ctu_85/archive/2007/05/15/1610722.aspx
中国象棋对战程序C语言源代码
http://blog.csdn.net/ctu_85/archive/2007/05/04/1596351.aspx
三维建筑物图像的二维建模
http://blog.csdn.net/ctu_85/archive/2006/12/20/1451106.aspx
分段线性骨架
http://blog.csdn.net/ctu_85/archive/2006/06/15/799847.aspx
基于图论的图像分割技术
http://blog.csdn.net/ctu_85/archive/2006/06/15/799857.aspx
Linux文件系统
http://blog.csdn.net/ctu_85/archive/2006/06/12/791644.aspx
分层模型
http://blog.csdn.net/ctu_85/archive/2006/06/07/777997.aspx
汉语编程企业管理应用软件可行性研究报告
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490139.aspx
汉语编程企业管理应用软件需求说明书
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490136.aspx
计算机专业操作系统课程设计报告
http://blog.csdn.net/ctu_85/archive/2007/01/22/1490130.aspx
软件可行性报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775894.aspx
软件需求分析报告
http://blog.csdn.net/ctu_85/archive/2006/06/06/775892.aspx
两种计算Ack(m,n)的非递归算法
http://blog.csdn.net/ctu_85/archive/2006/11/29/1419396.aspx
浙江大学计算机复试解答1
http://blog.csdn.net/ctu_85/archive/2006/10/15/1334936.aspx
浙江大学计算机复试解答2
http://blog.csdn.net/ctu_85/archive/2006/10/16/1336101.aspx
浙江大学计算机复试解答3
http://blog.csdn.net/ctu_85/archive/2006/11/02/1363159.aspx

发表于 @ 2007年04月24日 01:26:00|评论(loading...)|编辑

新一篇: 华容道游戏与算法 | 旧一篇: 浙江大学ACM试题解答(三月)

评论

#manysource 发表于2007-10-21 11:22:52  IP: 221.221.30.*
都没有注释……
#manysource 发表于2007-10-21 11:31:17  IP: 221.221.30.*
输入sample input,输出的却不是sample output?
#係り員 发表于2008-11-18 13:54:50  IP: 121.92.15.*
不倫おっぱいアダルト
发表评论  


登录
Csdn Blog version 3.1a
Copyright © ctu_85