"ZOJ1003" Crashing Balloon (DFS)

Source: Internet
Author: User

Crashing Balloon Time limit: 2 Seconds Memory Limit: 65536 KB

On every June 1st, the children's Day, there'll be a game named "Crashing Balloon" on TV.   The rule is very sim ple.  on the ground there is labeled balloons, with the numbers 1 to 100.  after the referee shouts "let ' s Go! "The 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 in the balloons they crash.  after a minute, the little audiences is 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 was not determined until the disputes was resolved.  The player who claims the lower score are entitled to challenge His\her opponent ' s score.  the player with the lower Score is presumed to has told the truth, because if he\she were to lie on His\her score, He\she would surely come up W ith a bigger better lie.  the challenge is upheld if the player with the higher score have a score that cannot be Achi Eved with balloons not crashed by the challenging player.  so, if the challenge is successful, the player claiming th E lower score wins.

So, for example, if one player claims 343 points and the other claims, then clearly the first player is lying; The only-to-score 343 is by crashing balloons labeled 7 and, and the-only-to-score is by crashing a balloon  Labeled 49. Since each of the scores requires crashing the balloon labeled, the one claiming 343 points are presumed to be lying.

On the other hand, if one player claims 162 points and the other claims Bayi, it's possible for both to be telling the Trut H (e.g. one crashes balloons 2, 3 and, while the other crashes balloon Bayi), so the challenge would isn't be upheld.

By the the-the-the-challenger made a mistake on calculating his/her score and then the challenge would isn't be upheld. For example, if one player claims 10001 points and the other claims 10003, then clearly none of them is telling the truth . The challenge would not being upheld.

Unfortunately, anyone who are willing to referee a game of crashing balloon are likely to get over-excited in the hot ATMOSP  Here's he\she could not reasonably is expected to perform the intricate calculations that refereeing requires. Hence the need for your, sober programmer, to provide a software solution.

Input

Pairs of unequal, positive numbers, with all pair on a single line, that is claimed scores from a game of crashing Ballo On.

Output

Numbers, one to a line, that is the winning scores, assuming that the player with the lower score always challenges the O Utcome.

Sample Input
343 493599 61062 36
Sample Output
4961062

Test instructions: On the ground there are 100 balloons numbered 1~100 Two people step on the balloon the initial score is 1 step to the corresponding number of balloons, the score multiplied by the corresponding number of the last two people reported their score score high winning but there may be people who lie low scores of people can question the high scores of people If a person with a high score does not own a score, then the question is that the player with the low score is the winner, for example, a player with a high score must have to step on a balloon that has a low score, and the balloons that are sure to step on it will be questioned if the two-person score counts incorrectly.

The problem: According to the topic request simulation first will score high assignment n fraction of the assignment m and then through the recursive factorization to determine whether there is a common factor because the balloon number is 1~100, so starting from 100 down to judge the factor is good if there is a low-score player is the winner if there is no score high player is the winner if all lies or All right then judge high score wins

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 7 BOOLat, BT;8 9 voidDfsintNintMintp);Ten  One intMain () { A     intN, M; -      while(SCANF ("%d%d", &n, &m)! =EOF) { -         if(N < m) {//Assigning m with a low fraction of the assigned value of a high score the swap (n, m); -         } -  -at =false;//assign a B to a lie first +BT =false; -  +DFS (n, M, -);//Recursive Factoring A  at         if(!at && BT) {//only high scores of lies will output low scores -printf"%d\n", m); -         } -         Else{//high scores do not lie or all lie, or all are correct. Output High score -printf"%d\n", n); -         } in     } -     return 0; to } +  - voidDfsintNintMintp) { the     if(n = =1&& m = =1){//Two people are not lying. Assign at value to not lie. *at =true; $         return ;Panax Notoginseng     } -     if(M = =1){//Low-score people don't lie . theBT =true; +     } A  the      while(P >1){//Factoring +         if(n% p = =0){ -DFS (n/p, M, p1); $         } $         if(m% p = =0){ -DFS (n, m/p, p1); -         } the  ---p;Wuyi     } the}
Alpha

"ZOJ1003" Crashing Balloon (DFS)

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.