您的位置:首页 > 编程语言 > Go语言

poj 2000 Gold Coins

2015-10-12 14:17 405 查看
题目链接:http://poj.org/problem?id=2000
题目大意:求N天得到多少个金币,第一天得到1个,第二、三天得到2个,第四、五、六天得到3个、、、、以此类推,得到第N天的金币数。

1 #include <iostream>
2 #include <cstdio>
3 #include <cmath>
4 using namespace std;
5 int main ()
6 {
7    int x,n,p;
8    while(cin>>n)
9    {
10        if (n==0)
11        break;
12        x=p=1;
13        int sum=0;
14        while(x<=n)
15        {
16            for(int i=x;i<x+p&&i<=n;i++)
17            sum+=p;
18            x=x+p;
19            p++;
20        }
21        cout<<n<<" "<<sum<<endl;
22    }
23    return 0;
24 }


 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: