POJ 2000 Gold Coins

题目描述



国王用付给他忠诚的骑士金币。在服役的第一天,骑士收到了一枚金币。在之后两天的每一天(服役的第二第三天),骑士收到两枚金币。在之后三天的每一天(服役的第四五六天),骑士收到三枚金币。这种支付模式将不限期地继续下去:在连续的 n 天每天收到 n 枚金币之后,骑士将会在接下来的 n+1 天每天收到 n+1 枚金币,这里 n 是一个任意的正整数。

你的程序要判定在任意给定的天数骑士累计收到了多少枚金币(从第一天开始)。

输入



输入包含至少一,但是至多二十一行。输入的每行(除了最后一行)包含问题的一组测试实例,一组实例是一个整数(在 1...10000 范围内),代表天数。输入的结束以包含一个数 0 的行表示。

输出



对于每组测试实例将有一行。这一行包含来自对应输入行的天数,接下来是一个空格和从第一天到给定的天数里,骑士收到的金币数。

来源



Rocky Mountain 2004

思路



数据比较小,直接模拟。另外算一下的话可以 O(1),这里就不算了。

代码


#include <stdio.h>

const int MAXN = 10000 + 5;
int pay[MAXN];

int main()
{
  int now = 1;
  int cnt = 0;
  for (int i = 1; i < MAXN; i++) {
    pay[i] = now;
    cnt++;
    if (cnt == now) {
      now++;
      cnt = 0;
    }
  }
  for (int i = 1; i < MAXN; i++)
    pay[i] += pay[i - 1];
  for (int n; scanf("%d", &n) && n; )
    printf("%d %d\n", n, pay[n]);
  return 0;
}

  

时间: 2024-10-15 17:04:01

POJ 2000 Gold Coins的相关文章

[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 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

HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)

Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of the baskets, each gold coin weighs w grams. In the one exceptional basket, each gold coin weighs w-d grams. A wizard appears on the

hust 1170 - Baskets of Gold Coins

题目描述 You are given N baskets of gold coins. The baskets are numbered from 1 to N. In all except one of the baskets, each gold coin weighs w grams. In the one exceptional basket, each gold coin weighs w-d grams. A wizard appears on the scene and takes

H - Gold Coins(2.4.1)

H - Gold Coins(2.4.1) Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Status 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

codechef - Bytelandian gold coins 题解

In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to ma

UVALive3045 POJ2000 ZOJ2345 Gold Coins

Regionals 2004 >> North America - Rocky Mountain 问题链接:UVALive3045 POJ2000 ZOJ2345 Gold Coins.基础练习题,用C语言编写. 题意简述:骑士第1天获得1个金币,之后的2天获得2个金币,之后的3天获得3个金币,......,之后的i天获得i个金币,.......问到第n天总共获得多少个金币. 问题分析:这是一个数列求和问题,用程序解决比用数学解决方便很多. 程序中,用数组ans[]存储金币之和,即ans[i]

Baskets of Gold Coins

Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1862    Accepted Submission(s): 1108 Problem Description You are given N baskets of gold coins. The baskets are numbered fro

HDU2401 Baskets of Gold Coins【水题】【推理】

Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1648    Accepted Submission(s): 966 Problem Description You are given N baskets of gold coins. The baskets are numbered fro