zoj 2345 Gold Coins

原创 2012年03月31日 12:40:42
//这题主要是找一下规律就可以了:1^2 + 2^2 + 3^2 + ..... + n^2
#include "iostream"
#include "memory.h"
using namespace std;

int main()
{
	int testcase, i, days, coins, temp, remain;
	cin >> testcase;
	while (testcase--)
	{
		while (cin >> days && days)
		{
			coins = 0;
			temp = 1;
			for (i = 1; temp <= days; i++, temp += i)
			{
				coins += i * i;
			}
			remain = (days - (temp-i)) * i;
			coins += remain;
			cout << days << " " << coins << endl;
		}
		if (testcase)
			cout << endl;
	}
}

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

相关文章推荐

杭电2410Baskets_Of_Gold_Coins

/* * 题目: Baskets_Of_Gold_Coins(篮子里的金币) 翻译:给你N个篮子装金币。也就是说篮子的数量是从1到N个,在所有篮子中除了一个篮子,每个普通篮子里金币的重量都是 w...

Free FIFA 15 ps4 ultimate team coins Giveaway for Everyone Liking Gold4fans Facebook

What Ruben seems 100% Winning Rate: Get Free FIFA 15 coins by clicking "Like" on Gold4fans faceb...

YT15-HDU-Harry's parents had left him a lot of gold coins

Problem Description   Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wiza...

POJ 2000 Gold Coins

Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22762   Ac...

poj 2000 Gold Coins(水题)

一、Description The king pays his loyal knight in gold coins. On the first day of his service, the kni...

Gold Coins

Description The king pays his loyal knight in gold coins. On the first day of his service, the kn...

POJ-2000 Gold Coins

Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21914   Ac...

[ACM] POJ 2000 Gold Coins

Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 20913   Ac...

HDOJ 2401 Baskets of Gold Coins (数学题)

HDOJ 2401 Baskets of Gold Coins (数学题) 题意: 有N个篮子,编号1—N,篮子中有很多金币,每个重w. 但是有一个编号的篮子中,每个金币重d.现从第...

HDU 2401 Baskets of Gold Coins(数学题)

Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)