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 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
 
题意:给四个数 n,w,d,m  代表n个篮子,每个篮子中放很多金币(大于等于n)每个金币的重量都是w但是有一个篮子中的金币重量是w-d,现在从篮子中拿出来金币,从第一个篮子中拿出一个,第二个篮子拿出两个,第n-1个篮子拿出n-1个第n个篮子不拿,现在给你拿出来的所有金币的总重量m问你第几个个篮子中的金币重量是w-d
题解:计算出当所有的金币重量都是w时按照此方法拿出的金币总重量sum减去m,得到ans则可知  x=ans/d;注意当ans==0时证明,第n个篮子中金币重量为w-d
#include<stdio.h>
#include<string.h>
#define LL long long
int main()
{
int w,d,n;
int i;
LL m,sum,ans;
while(scanf("%d%d%d%lld",&n,&w,&d,&m)!=EOF)
{
sum=0;
for(i=1;i<n;i++)
sum+=i*w;
ans=sum-m;
if(ans==0)
printf("%d\n",n);
else
printf("%lld\n",ans/d);
}
return 0;
}

  

hdoj 2401 Baskets of Gold Coins的更多相关文章

  1. 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 ...

  2. Baskets of Gold Coins

    Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

  3. Baskets of Gold Coins_暴力

    Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...

  4. Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏

    Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21767   Accepted: 13641 Desc ...

  5. OpenJudge/Poj 2000 Gold Coins

    1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...

  6. H - Gold Coins(2.4.1)

    H - Gold Coins(2.4.1) Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:3000 ...

  7. poj 2000 Gold Coins(水题)

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

  8. poj 2000 Gold Coins

    题目链接:http://poj.org/problem?id=2000 题目大意:求N天得到多少个金币,第一天得到1个,第二.三天得到2个,第四.五.六天得到3个....以此类推,得到第N天的金币数. ...

  9. Gold Coins

    http://poj.org/problem?id=2000 #include<stdio.h> ; int main() { int coin[N]; ,j,k; j = ; k = ; ...

随机推荐

  1. 玩转HTML5移动页面(优化篇)

    原文:http://www.grycheng.com/?p=472 承接上文<玩转HTML5移动页面(动效篇)>,上次说的是让页面动起来的一些小技巧.而页面动起来的根基是功能可用的页面,因 ...

  2. (转载)MVC + JQUERY + AJAX的几种方式

    MVC + JQUERY + AJAX的几种方式 // 传过去一个简单值,获取一个简单值 $.ajax({            type: "GET",         url: ...

  3. bootstrap-datepicker 日期拾取器

    最近开发的项目界面用的是bootstrap的框架,发现开源的东西真的很多,慢慢的我会记录到上面来 地址  http://www.bootcss.com/p/bootstrap-datetimepick ...

  4. ListToDataTable

    public static DataTable ToDataTable<T>(IEnumerable<T> collection)       {           var ...

  5. 详解C/C++函数指针声明

    要理解一个C程序,仅仅理解组成该程序的符号是不够的.程序员还必须理解这些符号是如何组合成声明.表达式.语句和程序的. 我们先来看看下面的一个语句: 1 ( *( void(*)())0)(); 这是当 ...

  6. VIM一些常用命令,方法,配置

    配置文件地址 github 工具只是为了更好的工具,选择一种,坚持使用学习记忆,熬过瓶颈期就可以了. 现在我基本大的项目是IDE+vim 插件,写小代码是VIM. 常用的操作,便捷的方法 1.如何选中 ...

  7. 【技术帖】解决 Hudson jenkins 连接等待中 - Waiting for next av

    今天构建项目发现如下问题: jenkins 连接等待中 - Waiting for next available executor 左下角那块一直不运行构建,一直在连接等待. 于是,进入一级页面, 右 ...

  8. front-end

    http://info.1688.com/detail/1139720782.html http://segmentfault.com/q/1010000000136513 http://h5apps ...

  9. POJ 1778 All Discs Considered(拓扑排序)

    点我看题目 题意 :其实题意我也说不清楚,因为比赛的时候我盯着看了1个小时也没看懂....就是两个磁盘,第一个有n1的安装包,编号为1~n1,第二个有n2个安装包,编号为n1~n2.给你d对关系,(x ...

  10. php 文件下载 以及 file_exists找不到文件的解决方案

    链接:<a href="upload/file/download.php?filename=雨人工作室.doc" target="_blank" > ...