More Flowers,More Love Time Limit:1000MS Memory Limit:65536KTotal Submit:30 Accepted:13 Description Valentine's Day is coming,while girls are preparing chocolate for their boys, we boys is also in preparation of choosing presents for the sweet to love carefully. Tom is Tom,Tom does not know too much about how to flattering the girl in his heart, so he just decides to buy flowes for his girl as what the knights in middle ages have already done. However thought he could do more than buying flowers, he wants to use out all the money in his pockets on flowers,because he loves his girl too much. There are three kinds of flowers in the florist: Rose, Carnation and Rosebush. Tom wants to know if he could use out of his money. Please tell him, our genius programmer. Input The input file contains multiple lines, and each line contains four numbers in sequence, the total money that Tom has, the price of Rose, the price of Carnation and of Rosebush. Output For each test case output Yes if Tom could use out his money or No if not. Sample Input 100 1 1 1 50 3 3 3 Sample Output Yes No Source #include"iostream" using namespace std; struct { int money; int rose; int ca; int rb; }a[100]; bool use(int i) { int m,j,k; for(m=0;m<=a[i].money/a[i].rose;m++) for(j=0;j<=a[i].money/a[i].ca;j++) for(k=0;k<=a[i].money/a[i].rb;k++) if(m*a[i].rose+j*a[i].ca+k*a[i].rb==a[i].money)return true; return false; } int main() { int i=0,j; while(cin>>a[i].money>>a[i].rose>>a[i].ca>>a[i].rb) i++; for(j=0;j<i;j++) if(use(j))cout<<"Yes"<<endl; else cout<<"No"<<endl; return 1; }

评论