一、Description

The king pays his loyal knight in gold coins. On the first day of his service, the knight receives one gold coin. On each of the next two days (the second and third days of service), the knight receives two gold coins. On each
of the next three days (the fourth, fifth, and sixth days of service), the knight receives three gold coins. On each of the next four days (the seventh, eighth, ninth, and tenth days of service), the knight receives four gold coins. This pattern of payments
will continue indefinitely: after receiving N gold coins on each of N consecutive days, the knight will receive N+1 gold coins on each of the next N+1 consecutive days, where N is any positive integer.



Your program will determine the total number of gold coins paid to the knight in any given number of days (starting from Day 1).

Input

The input contains at least one, but no more than 21 lines. Each line of the input file (except the last one) contains data for one test case of the problem, consisting of exactly one integer (in the range 1..10000), representing
the number of days. The end of the input is signaled by a line containing the number 0.

Output

There is exactly one line of output for each test case. This line contains the number of days from the corresponding line of input, followed by one blank space and the total number of gold coins paid to the knight in the given
number of days, starting with Day 1.

二、题解

       水题不多说!!值得祝贺,今天连克三道水题,水果30。

三、Java代码

import java.util.Scanner; 

public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n,i,j,sum,total;
while((n=cin.nextInt())!=0){
i=0;
sum=0;
j=0;
total=0;
while(sum<=n){
i++;
sum+=i;
}
j=n-(sum-i);
for(int m=1;m<i;m++){
total+=m*m;
}
total=total+j*i;
System.out.println(n+" "+total);
}
}
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

poj 2000 Gold Coins(水题)的更多相关文章

  1. OpenJudge/Poj 2000 Gold Coins

    1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...

  2. poj 2000 Gold Coins

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

  3. POJ 1488 Tex Quotes --- 水题

    POJ 1488 题目大意:给定一篇文章,将它的左引号转成 ``(1的左边),右引号转成 ''(两个 ' ) 解题思路:水题,设置一个bool变量标记是左引号还是右引号即可 /* POJ 1488 T ...

  4. POJ 3641 Oulipo KMP 水题

    http://poj.org/problem?id=3461 直接KMP就好.水题 #include<cstdio> #include<cstring> const int M ...

  5. poj 1006:Biorhythms(水题,经典题,中国剩余定理)

    Biorhythms Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 110991   Accepted: 34541 Des ...

  6. poj 1002:487-3279(水题,提高题 / hash)

    487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 236746   Accepted: 41288 Descr ...

  7. poj 1003:Hangover(水题,数学模拟)

    Hangover Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 99450   Accepted: 48213 Descri ...

  8. poj 2105 IP Address(水题)

    一.Description Suppose you are reading byte streams from any device, representing IP addresses. Your ...

  9. POJ 2365【YY水题】

    题目链接:POJ 2365 Rope Rope Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7488   Accepted ...

随机推荐

  1. POJ 2856 Y2K Accounting Bug【简单暴力】

    链接: http://poj.org/problem?id=2586 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26733#probl ...

  2. php自定义函数: amr转mp3格式

    <?php function amr2mp3($file){ if (file_exists($file . '.mp3') == true) { return; } else { $param ...

  3. iOS 邓白氏编码的申请

    http://www.cocoachina.com/ios/20161214/18225.html

  4. Linux安装python3.7.2详细操作步骤

    1.下载Python依赖环境 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ...

  5. selenium鼠标悬停操作

    有些网页一打开会有一个弹窗,弹窗不消失无法进行取元素操作,只有把鼠标悬停在上面弹窗才会消失,这时就用到了selenium的悬停操作 鼠标悬停  move_to_element() 定位到要悬停的元素 ...

  6. link_to嵌套

    = link_to theses_path, :class=>"btn" do .text-center 购买

  7. iOS 流媒体 基本使用 和方法注意

    项目里面需要添加视频方法   我自定义 选用的是 avplayer  没选择 MediaPlayer  原因很简单 , avplayer 会更容易扩展  有篇博客 也很好地说明了 使用avplayer ...

  8. CSS3垂直图标菜单

    在线演示 本地下载

  9. hbase shell-namespace(命名空间指令)

    hbase shell命名空间namespace篇: 1. alter_namespace (一般用于添加删除一个属性,很少使用) hbase(main)::> help 'alter_name ...

  10. Shiro 集成 Web

    Web 集成 Shiro 的练习项目. Servlet + Shiro 项目结构 新建Maven项目,pom配置如下 <project xmlns="http://maven.apac ...