1 solutions
-
0
模拟()
- 先枚举发放的金币数目,在枚举发放枚金币的第天,总天数为的时候结束循环.
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int day=0; int coins=0; for(int i=1;i<=n;i++) //枚举发多少枚金币 { for(int j=1;j<=i;j++) //发i枚金币的第j天 { day++; //天数增加 coins+=i; //金币数目增加 if(day==n) //已经发了对应的天数了 { cout<<coins; return 0; } } } return 0; }
模拟()
- 枚举发放的金币数目,然后通过计算判断发放枚金币是否可以结束。
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int days=0,coins=0; for(int i=1;i<=n;i++) { int t=n-days; if(t<=i) //发放i枚金币的时候可以结束 { coins+=i*t; break; } else //发放i枚金币的时候还不可以结束 { coins+=i*i; } days+=i; } cout<<coins; return 0; }
- 1
Information
- ID
- 1047
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 10
- Tags
- # Submissions
- 4
- Accepted
- 3
- Uploaded By