问题标题: 酷町堂:1801 换小额钞票

0
0
已解决
王子桐
王子桐
高级光能
高级光能

1801   换小额钞票

题目描述 Description

小明妈妈是开超市的,每天都要卖很多东西,需要准备很多零钱,某一天超市零钱不够了,于是她去银行换钞票,想把n张100元的钞票兑换成10元、20元、50元小钞票形式。请问有多少种兑换的方式呢?

输入描述 Input Description

100元的钞票的数量n张(1<=n<=10000)

输出描述 Output Description

多少种换法

样例输入 Sample Input

1

样例输出 Sample Output

10

Time Limit Exceeded 40:

  • #include<iostream>
  • using namespace std;
  • /*小明妈妈是开超市的,
  • 每天都要卖很多东西,
  • 需要准备很多零钱,
  • 某一天超市零钱不够了,
  • 于是她去银行换钞票,
  • 想把n张100元的钞票兑换成10元、20元、50元小钞票形式。
  • 请问有多少种兑换的方式呢*/
  • long long n,cnt;
  • int main(){
  • cin>>n;
  • for(int i=0;i<=n*100/50;i++){
    • for(int j=0;j<=n*100/20;j++){
      • int k=n*100-i*50-j*20; if(k>=0){
        • cnt++;
      • }
    • }
  • }
  • cout<<cnt;
  • return 0;
  • }
  • 为什么超时了???
王子桐在2021-03-29 12:01:26追加了内容

已AC


0
0
王子桐
王子桐
高级光能
高级光能



int n,cnt=0;
cin>>n;
for(int i=0;i<=n*2;i++){
for(int j=0;j<=n*5;j++){
int k=n*100-i*50-j*20;
if(k>=0){
cnt++;
}
}
}
cout<<cnt;
 

我要回答