钞票面值问题

1.Otoshidama - AtCoder abc085_c - Virtual Judge (vjudge.net)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 
 4 int n,Y;
 5 
 6 int main()
 7 {
 8     while(cin >> n >> Y)
 9     {
10         Y /= 1000;
11         if(n * 10 < Y || n > Y){
12             cout<<-1<<" "<<-1<<" "<<-1<<endl;
13             continue;
14         }
15         int flag=0;
16         for(int i=n;i>=0;i--){
17             for(int j=n-i;j>=0;j--){
18                 for(int l=n-i-j;l>=0;l--){
19                     if((i+j+l==n)&&(i*10+j*5+l==Y)){
20                         cout<<i<<" "<<j<<" "<<l<<endl;
21                         flag=1;
22                         return 0;
23                     }
24                 }
25             }
26         }
27         if(!flag) cout<<-1<<" "<<-1<<" "<<-1<<endl;
28     }
29     return 0;
30 }
View Code

 

posted @ 2023-11-09 12:09  rw156  阅读(14)  评论(0)    收藏  举报