Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 21767 | Accepted: 13641 |
Description
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 number of days. The end of the input is signaled by a line containing the number 0.
Output
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
意思就是国王第一天能得到一个金币,接下来两天每天能得到两个金币,以此类推,计算金币的总数#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream> using namespace std; int main()
{
int n;
while(~scanf("%d",&n)&&n!=0)
{
int sum=0;
int ans=1;
for(int i=1;i<=n;)
{
for(int j=1;j<=ans&&i<=n;j++,i++)
{
sum+=ans;
}
ans++;
}
printf("%d %d\n",n,sum);
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏的更多相关文章
- 哈希-Gold Balanced Lineup 分类: POJ 哈希 2015-08-07 09:04 2人阅读 评论(0) 收藏
Gold Balanced Lineup Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13215 Accepted: 3873 ...
- PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...
- POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏
POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("% ...
- SQL 存储过程 分页 分类: SQL Server 2014-05-16 15:11 449人阅读 评论(0) 收藏
set ANSI_NULLS ON set QUOTED_IDENTIFIER ON go -- ============================================= -- Au ...
- 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏
DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...
- max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...
- SQL 分组 加列 加自编号 自编号限定 分类: SQL Server 2014-11-25 15:41 283人阅读 评论(0) 收藏
说明: (1)日期以年月形式显示:convert(varchar(7),字段名,120) , (2)加一列 (3)自编号: row_number() over(order by 字段名 desc) a ...
- SQL 按月统计(两种方式) 分类: SQL Server 2014-08-04 15:36 154人阅读 评论(0) 收藏
(1)Convert 函数 select Convert ( VARCHAR(7),ComeDate,120) as Date ,Count(In_code) as 单数,Sum(SumTrueNum ...
- Sort List 分类: leetcode 算法 2015-07-10 15:35 1人阅读 评论(0) 收藏
对链表进行排序,要求时间复杂度为O(n log n) ,不使用额外的空间. 我一开始的想法是借助quicksort的思想,代码如下: # time O(nlog(n)) # Definition fo ...
随机推荐
- 【Origin】jquery.barddialog.js
/// <reference path="jquery-2.1.1.min.js" /> /** * @license jquery.bardDialog 1.0.0 ...
- HDU 4899 Hero meet devil(状压DP)(2014 Multi-University Training Contest 4)
Problem Description There is an old country and the king fell in love with a devil. The devil always ...
- (三)开关检测来控制LED灯的亮灭
开关检测案例一: 具体电路图如下: K1--K4闭合,控制 D1—D4 亮灭 产生的问题: 1.关于 R8 R9 R7 R10 的阻值选择问题,倘若太大的话, 比如10K 不管开关断开还是闭合,好像 ...
- 一天弹出一次广告cookie
function setCookie(name, value, expire) { window.document.cookie = name + "=" + escape(val ...
- 救火必备linux命令
系统参数: cat /proc/cpuinfo cpu相关参数 cat /proc/meminfo 内存相关参数 cat /proc/loadavg 负载情况 性能参数: )top M:按内存使用排序 ...
- 使用sublime text3的一些事
因为在第一次接触网页设计的时候,使用的是Dreamweaver,它的设计是一款所见即所得的网页编辑器,而且当你写好元素之后的“:”时,就会有代码提示功能,对一些初学者来说,是一个不错的选择.但是慢慢地 ...
- SQL SERVER2000中订阅与发布的具体操作
同步过程 一.准备工作,如果完成则可跳过. 1.内网DB服务器作为发布服务器,外网DB服务器作为订阅服务器. 发布服务器和订阅服务器上分别创建Windows用户jl,密码jl,隶属于administr ...
- android 学习随笔二十七(JNI:Java Native Interface,JAVA原生接口 )
JNI(Java Native Interface,JAVA原生接口) 使用JNI可以使Java代码和其他语言写的代码(如C/C++代码)进行交互. 问:为什么要进行交互? 首先,Java语言提供的类 ...
- Mongodb 笔记05 创建副本集
创建副本集 1. 副本集:副本集时一组服务器,其中有一个主服务器(primary),用于处理客户端请求:还有多个备份服务器(secondary),用于保存主服务器的数据副本.如果主服务器崩溃了,备份服 ...
- CC2541的任务与事件,以及红外捕捉.
因为红外遥控要占用的系统中断时间可能超过了80ms, 极有可能导致蓝牙断线, 特别是连续两次按键, 100%断线. 后来根据蓝牙技术群里的哥们提示, 觉得不能在一个中断中delay得太久, 只能用任务 ...