1. 程式人生 > >hdu1495非常可樂

hdu1495非常可樂

col input acm sample code clu hdu1495 sca 如果

大家一定覺的運動以後喝可樂是一件很愜意的事情,但是seeyou卻不這麽認為。因為每次當seeyou買了可樂以後,阿牛就要求和seeyou一起分享這一瓶可樂,而且一定要喝的和seeyou一樣多。但seeyou的手中只有兩個杯子,它們的容量分別是N 毫升和M 毫升 可樂的體積為S (S<101)毫升 (正好裝滿一瓶) ,它們三個之間可以相互倒可樂 (都是沒有刻度的,且 S==N+M,101>S>0,N>0,M>0) 。聰明的ACMER你們說他們能平分嗎?如果能請輸出倒可樂的最少的次數,如果不能輸出"NO"。

Input三個整數 : S 可樂的體積 , N 和 M是兩個杯子的容量,以"0 0 0"結束。Output如果能平分的話請輸出最少要倒的次數,否則輸出"NO"。Sample Input

7 4 3
4 1 3
0 0 0

Sample Output

NO
3
 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5 int gcd(int a,int b)
 6 {
 7     return b==0?a:gcd(b,a%b);
 8 }
 9 int main()
10 {
11     int x,y,z;
12     while(scanf("%d%d%d",&x,&y,&z)&&x+y+z)
13 { 14 x/=gcd(y,z); 15 if(x&1) 16 cout<<"NO"<<endl; 17 else 18 cout<<x-1<<endl; 19 } 20 return 0; 21 }

hdu1495非常可樂