一、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. js跨浏览器复制: ZeroClipboard

    实例结构: demo.html <script type="text/javascript" src='http://code.jquery.com/jquery.js'&g ...

  2. Java基础 - 常量与变量

    A:常量 内存中的一小块区域,在程序执行过程中,其值不可以发生改变的量称为常量 常量的几种表现形式: a:字符串常量 "HelloWorld" b:整数常量 12 c:小数常量 1 ...

  3. 我的Android进阶之旅------>如何将Activity变为半透明的对话框?

    我的Android进阶之旅------>如何将Activity变为半透明的对话框?可以从两个方面来考虑:对话框和半透明. 在定义Activity时指定Theme.Dialog主题就可以将Acti ...

  4. spring AOP简单实现代码存放

    @Before:使用Before增强处理只能在目标方法执行之前织入增强,如果Before增强处理没有特殊处理,目标方法总会自动执行,如果Before处需要阻止目标方法的执行,可通过抛出一个异常来实现. ...

  5. 【leetcode刷题笔记】Binary Tree Preorder Traversal

    Given a binary tree, return the preorder traversal of its nodes' values. For example:Given binary tr ...

  6. PHP操作MySQL事务处理

    PHP操作MySQL事务处理 /*************** 用begin,rollback,commit来实现 ***************/ /*方法二*/ $conn = mysqli_co ...

  7. X-real-ip与X-Forwarded-For

    经过反向代理后,客户端与web服务器之间添加了中间层,因此: 1.代理服务器使用$remote_addr拿到的会是客户端的ip 2. web服务器使用$remote_addr拿到的会是代理服务器的ip ...

  8. AJAX请求时status返回状态明细表

    AJAX请求时status返回状态明细表 readyState的五种状态2010-03-04 18:24对于readyState的五种状态的描述或者说定义,很多Ajax书(英文原版)中大都语焉不详 在 ...

  9. vim 的复制粘贴命令,以及使用寄存器来存放要复制的内容;

    一,y(yanks)复制,p(paste)粘贴: yy 复制当前行,2yy,复制2行: Y  复制整行:Y=yy; p 粘贴到光标后: P 粘贴到光标前: 注意vim会知道你复制内容的是整行还是一个矩 ...

  10. oracle 从select的结果update其他表

    update a set a.id=(selelct b.id from temp b where b.line = a.line)  where a.line = (select line from ...