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 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 1 coin from
Basket 1, 2 coins from Basket 2, and so on, up to and including N-1 coins from Basket N-1. He does not take any coins from Basket N. He weighs the selected coins and concludes which of the N baskets contains the lighter coins. Your mission is to emulate the
wizard‘s computation.

Input

The input file will consist of one or more lines; each line will contain data for one instance of the problem. More specifically, each line will contain four positive integers, separated by one blank space. The first three integers are, respectively, the numbers
N, w, and d, as described above. The fourth integer is the result of weighing the selected coins.

N will be at least 2 and not more than 8000. The value of w will be at most 30. The value of d will be less than w.

Output

For each instance of the problem, your program will produce one line of output, consisting of one positive integer: the number of the basket that contains lighter coins than the other baskets.

Sample Input

10 25 8 1109

10 25 8 1045

8000 30 12 959879400

Sample Output

2

10

50

Source

ACM/ICPC 2008 Warmup(2)——测试帐号(杭州)

题目大意:有N个篮子,编号为1~N,篮子理由很多金币,只有一个篮子中每个金币中w-d,

其他篮子中每个金币都重w。现在从第1个篮子里拿1个金币,从第2个篮子里拿2个金币,…,

一直到到第N-1个篮子里拿N-1个金币。第N个篮子不拿。给出这些金币的全部重量和all,问:

第几个篮子里的金币是轻的,求出轻金币的个数。

思路:数学题,1~N个篮子里金币应有的总重量为:(N-1)*N/2*w,减去这些金币的全部重量

和all,得到总的轻金币比普通金币差的重量,每个轻金币和普通金币差的重量为d,两者相除,

得出轻金币的个数。

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int N,w,d,all;
    while(cin >> N >> w >> d >> all)
    {
        if((N-1)*N/2*w - all == 0)
            cout << N << endl;
        else
            cout << ((N-1)*N/2*w - all)/d << endl;
    }

    return 0;
}
时间: 2024-08-26 10:08:33

HDU2401 Baskets of Gold Coins【水题】【推理】的相关文章

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

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

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

hdoj 2401 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): 1855    Accepted Submission(s): 1104 Problem Description You are given N baskets of gold coins. The baskets are numbered fro

Gold Coins(闲来无事水一发)

Gold Coins Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21155 Accepted: 13265 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 (th

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

5.1个人赛解题报告(区间dp,按位与或,图论等水题)

这次5.1打了一场个人赛,已经连赛了三周了,有点疲惫感觉,可能自己太水了,每次都有点小紧张. 这次只解出来三道题,然而有一道按位与按位或的水题不知道思路实在是做题太少,还有就是第一题区间DP,也消耗了不少的时间,但是没有成功的写出来,还是不够熟练啊. 下面写报告 A. System Administrator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4