1003 Crashing Balloon, crashingballoon

Source: Internet
Author: User

1003 Crashing Balloon, crashingballoon

Evaluate the application of DFS and determine the two factors.

 1 #include <stdio.h> 2  3 int f1,f2; 4  5 void DFS(int m,int n,int k){ 6     if(n==1){ 7         f2=1; 8         if(m==1) 9             f1=1;10     }11     if(f1&&f2||k==1)12         return;13     if(m%k==0)14         DFS(m/k,n,k-1);15     if(n%k==0)16         DFS(m,n/k,k-1);17     DFS(m,n,k-1);18 }19 20 int main(){21     int a,b,temp;22     while(scanf("%d %d",&a,&b)>=0){23         if(a<b){24             temp=a;25             a=b;26             b=temp;27         }28         f1=f2=0;29         DFS(a,b,100);30         temp=(!f1&&f2)?b:a;31         printf("%d\n",temp);32     }33     return 0;34 }

 


Zoj 1003 question: Where is my program wrong? Why do I always fail to submit

// Zju 1003 Crashing Balloon
# Include <stdio. h>
# Include <string. h>
Int used [101];
Int scoremin, scoremax;
Int dive (int n, int cnt)
{
Int I;
If (n = 1)
Return 1;
For (I = cnt; I <= 100; I ++)
If (n % I = 0)
{
If (dive (n/I, I + 1 ))
Return 1;
}
Return 0;
}
Int DFSb (int n, int cnt)
{
Int I;
If (n = 1)
Return 1;
For (I = cnt; I <101; I ++)
{
If (used [I] = 0)
{
If (n % I = 0)
{
If (DFSb (n/I, I + 1 ))
Return 1;
}
}
}
Return 0;
}
Int DFSa (int n, int cnt)
{
Int I;
If (n = 1)
{
If (DFSb (scoremax, 2 ))
Return 1;
Return 0;
}
For (I = cnt; I <101; I ++)
{
If (n % I = 0)
{
Used [I] = 1;
If (DFSa (n/I, I + 1 ))
Return 1;
Used [I] = 0;
}
}
Return 0;
}
Int main ()
{
Int temp, flag1, flag2, I;
While (scanf ("% d", & scoremin, & scoremax )! = EOF)
{
If (scoremin> scoremax)
{
Temp = scoremin;
Scoremin = scoremax;
Scoremax = temp;
}
If (scoremin = scoremax)
{
Printf ("% d \ n", scoremin );
Continue;
}
Flag1 = flag2 = 0;
If (scoremin = 1 & scoremax> 1)
{
If (dive (scoremax, 2 ))
Printf ("% d \ n", scoremax );
Else
... The remaining full text>

What does Crashing Balloon mean?

Baidu found it as a game .....
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.
That's it.
Study it slowly ~~~~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.