poj 2000

Gold Coins










Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 20802   Accepted: 13018

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.

Sample Input

10
6
7
11
15
16
100
10000
1000
21
22
0

Sample Output

10 30
6 14
7 18
11 35
15 55
16 61
100 945
10000 942820
1000 29820
21 91
22 98

Source

Rocky Mountain 2004

简单构造法模拟,没什么说的


 1 #include <iostream>
2 #include<cstdio>
3 using namespace std;
4 int a[10001];
5 int main()
6 {
7 int n,j=1,i=1,temp=1,sum=0;
8
9 for(int i = 1;i<=10000;)
10 {
11 int k = j;
12 while(k>0)
13 {
14 sum += temp;
15 a[i++] = sum;
16 k--;
17 }
18 temp++;
19 j++;
20 }
21 while(scanf("%d",&n)!=EOF&&n!=0)
22 {
23 printf("%d %d\n",n,a[n]);
24 }
25 return 0;
26 }

poj 2000,布布扣,bubuko.com

时间: 2024-11-05 21:06:18

poj 2000的相关文章

[ACM] POJ 2000 Gold Coins

Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20913   Accepted: 13098 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

POJ 2000 Gold Coins

题目描述 国王用付给他忠诚的骑士金币.在服役的第一天,骑士收到了一枚金币.在之后两天的每一天(服役的第二第三天),骑士收到两枚金币.在之后三天的每一天(服役的第四五六天),骑士收到三枚金币.这种支付模式将不限期地继续下去:在连续的 n 天每天收到 n 枚金币之后,骑士将会在接下来的 n+1 天每天收到 n+1 枚金币,这里 n 是一个任意的正整数. 你的程序要判定在任意给定的天数骑士累计收到了多少枚金币(从第一天开始). 输入 输入包含至少一,但是至多二十一行.输入的每行(除了最后一行)包含问题

poj 2411 Mondriaan&#39;s Dream(状压DP)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12232   Accepted: 7142 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

HDU 3296 &amp; POJ 3138 Acm Team Section(数学)

题目链接: HDU: http://acm.hdu.edu.cn/showproblem.php?pid=3296 POJ:  http://poj.org/problem?id=3138 Acm Team Section Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 159    Accepted Submission(s): 47

POJ 2018 Best Cow Fences

斜率优化DP...<浅谈数形结合思想在信息学竞赛中的应用 安徽省芜湖一中 周源>例题... Best Cow Fences Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 9311   Accepted: 2986 Description Farmer John's farm consists of a long row of N (1 <= N <= 100,000)fields. Each field c

POJ 1041 John&#39;s trip 无向图的【欧拉回路】路径输出

欧拉回路第一题TVT 本题的一个小技巧在于: [建立一个存放点与边关系的邻接矩阵] 1.先判断是否存在欧拉路径 无向图: 欧拉回路:连通 + 所有定点的度为偶数 欧拉路径:连通 + 除源点和终点外都为偶数 有向图: 欧拉回路:连通 + 所有点的入度 == 出度 欧拉路径:连通 + 源点 出度-入度=1 && 终点 入度 - 出度 = 1 && 其余点 入度 == 出度: 2.求欧拉路径 : step 1:选取起点(如果是点的度数全为偶数任意点为S如果有两个点的度数位奇数取一

POJ 2367 topological_sort

Genealogical tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2920 Accepted: 1962 Special Judge Description The system of Martians' blood relations is confusing enough. Actually, Martians bud when they want and where they want. They ga

POJ 3666 Making the Grade [DP]

题意: 给定一个序列,以最小代价将其变成单调不增或单调不减序列,这里的代价看题目公式. 思路: 很容易想到是DP. 1. 对前i个序列,构成的最优解其实就是与两个参数有关.一个是这个序列处理后的最大值mx,和这个序列处理的代价值cost. 显然最大值mx最小最好(这样第i+1个值可以不花代价直接接在其后面的可能性更大),cost最小也最好(题意要求),但是两者往往是鱼和熊掌. 用dp[i][j]表示:前i个数构成的序列,这个序列最大值为j,dp[i][j]的值代表相应的cost. 所以状态转移方

POJ 2492 A Bug&#39;s Life

A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 35756   Accepted: 11730 Description Background Professor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different gender