题目链接
题解
t表示t天.
j表示这次循环该有几次.
i表示这是第几天.
最后发够了a天钱就不发了.
题目比代码难懂.
认真读题.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#include<cstdio> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> using namespace std ; template<class T>void read(T &x){ x=0;int f=0;char ch=getchar(); while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();} while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();} x=f?-x:x; return ; } int main () { int a,t=0,sum=0; read(a); for(int j=1;;j++) for(int i=1;i<=j;i++){ sum+=j; t ++; if(t==a){printf("%d",sum);return 0;} } return 0 ; } |
By:Wahacer
2017.11.28
15:14