Magic (csdn programming challenge) and magic csdn programming challenge
Magic question details:
You have three types of magic. You can use the first magic to convert a gram of sand into B grams of metal. You can use the second magic to turn c grams of metal into d grams of gold, you can use the third magic to turn e-grams of gold into f-grams of sand.
Can you use the limited amount of sand, metal, and gold to get an unlimited amount of gold?
Input Format:
Multiple groups of data, each group has only one row containing six integers a, B, c, d, e, f
(0 <= a, B, c, d, e, f <= 1000)
Output Format:
Each group outputs a row. "YES" and "NO" indicate whether there can be an infinite amount of gold.
Q & A description:
Input example
100 200 250 150 200 250
100 50 50 200 200 100
1 1 0 1 1 1
100 1 100 1 0 1
Output example:
YES
NO
YES
YES
The value must be set to 0.
Code:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>int main(){ int a,b,c,d,e,f; while(~scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f)) { if(d==0) printf("NO\n"); else if(c==0) printf("YES\n"); else if(b==0) printf("NO\n"); else if(a==0) printf("YES\n"); else if(f==0) printf("NO\n"); else if(e==0) printf("YES\n"); else if(b*d*f>a*c*e) printf("YES\n"); else printf("NO\n"); }}