码迷,mamicode.com
首页 > 其他好文 > 详细

poj 2000 Gold Coins

时间:2014-07-12 08:51:24      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   for   

题目链接: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 }

 

poj 2000 Gold Coins,布布扣,bubuko.com

poj 2000 Gold Coins

标签:style   blog   http   color   os   for   

原文地址:http://www.cnblogs.com/qq-star/p/3835126.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!