Issue C: Grind time limit: 1 Sec memory limit: MB
Submitted by: 39 Resolution:
Submitted State [Discussion Version] [Propositional person:Admin] The topic describes sharpening is a fastidious work, can only be carried out under the N℃, so the first thing we have to do is to increase the surface temperature of the knife to N℃.
There are two ways to handle the body temperature of a knife:
1. Quenching, so that the body temperature increase a℃;
2. Ice compress to reduce the body temperature b℃.
Boa elder sister wants to know, can pass many times treatment, make the body temperature reaches N℃. Enter each set of inputs containing one line: contains three nonnegative integers n, a, B, meaning as above, the data range is not more than 2^63, the input has EOF end output according to the calculation, output "YES" or "NO". Sample input
3 6 9
Sample output
YES
Tip For the first sample ice deposited the body temperature to 9 ℃, in the hardening of the body temperature to 3 ℃.
The starting temperature of the knife body is 0.
General ideas: 1, the first eye to think of BFS, in fact, no, the data returned too large, after all
data range not exceeding 2^63! 2, use Longlong to store all the data! 3, the subject is an equation: a*x+b*y=n, X is the number of times a sharpening, Y is the number of knives! Of course, X and Y will have negative values when applying the extended Euclidean algorithm, and they need to be removed from the situation |! 4, the initial temperature of 0, see ' tips ' to get information! A little flaw!
1#include <iostream>2#include <stdio.h>3#include <string.h>4#include <string>5#include <algorithm>6 #definell Long Long7 using namespacestd;8 #defineN 1009 Ten ll EXGCD (ll a,ll b,ll x,ll y) { One if(!b) A { -x=1; y=0;returnA; - } the Else{ - -ll R=EXGCD (b,a%b,y,x); -y-=a/b*x; + returnR; - } + A } at - intMain () { - ll N,a,b; - while(SCANF ("%lld%lld%lld", &n,&a,&b)! =EOF) { - ll R, X, y; -R=EXGCD (a,b,x,y); in if(n%r==0&&x>=0&&y>=0) -printf"yes\n"); to Else +printf"no\n"); - } the * return 0; $}
View Code
2018/7/31-zznu-oj-Problem C: Sharpening-"Extending the basic application of Euclidean algorithm"