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个篮子,编号1—N,篮子中有很多金币,每个重w.但是有一个编号的篮子中,每个金币重d.现从第一个篮子中拿1个金币,第二个篮子中拿2个……第N-1中拿N-1个,第N中不拿,给出这些金币的总重量wei,问:是第几个篮子中的金币重量较轻?

分析:一道数学题,先求1—N篮子金币应有的总重量w*(1+n-1)(n-1)/2-wei 等差数列求和,再乘每个金币应有的重量,所求和减去wei得到金币重量的差值。若为0,则必为编号N;若不为0,除以d,得到较轻金币的个数,即为所求编号。

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
Scanner sc= new Scanner(System.in); while(sc.hasNext()){
int n =sc.nextInt();
int w = sc.nextInt();
int d = sc.nextInt();
int p =sc.nextInt(); int sum = ((n-1)*(n-1+1)/2)*w-p;
if(sum==0){
System.out.println(n);
}else{
System.out.println(sum/d);
}
}
}
}

HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)的更多相关文章

  1. hdoj 2401 Baskets of Gold Coins

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

  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. HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)

    HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...

  5. HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)

    HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...

  6. HDU 5783 Divide the Sequence(数列划分)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

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

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

  8. OpenJudge/Poj 2000 Gold Coins

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

  9. H - Gold Coins(2.4.1)

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

随机推荐

  1. spring事务回滚无法捕捉

    这篇文章讲解了怎么配置才能让spring事务捕捉异常 http://www.360doc.com/content/12/1109/18/6161903_246870991.shtml 需要正确配置sp ...

  2. C# 里窗体里(windows form)怎么播放音乐

    在.NET的winform里面,没有托管的音乐播放器,API只能播放WAV格式,对于MP3等形式的音频文件,就要依赖于 MediaPlayer里,嘿嘿 使用的方法: 在toolbox上点右键,选择“选 ...

  3. TCP与UDP区别

    原文链接:http://blog.sina.com.cn/s/blog_493309600100clrw.html TCP与UDP区别 TCP---传输控制协议,提供的是面向连接.可靠的字节流服务.当 ...

  4. 记一次网站服务器迁移(my)

    遇到的难题: 基本没有遇到太大的问题,因为服务器环境是配好的阿里云环境,最后再nginx的rewrite配置遇到了一点问题,最后也算解决. 收获小点: 1) vim替换命令: 利用 :s 命令可以实现 ...

  5. session marked for kill处理oracle中杀不掉的锁

    ora-00031:session marked for kill处理oracle中杀不掉的锁   一些ORACLE中的进程被杀掉后,状态被置为"killed",但是锁定的资源很长 ...

  6. PHP 开发API接口 注册,登录,查询用户资料

    服务端 <?php require 'conn.php'; header('Content-Type:text/html;charset=utf-8'); $action = $_GET['ac ...

  7. 初探grunt.js

    package.js { "name": "ttd_v3", "version": "0.1.0", "aut ...

  8. 控制寄存器 CR*

    控制寄存器(CR0-CR3)用于控制和确定处理器的操作模式以及当前执行任务的特性,如图4-3所示.CR0中含有控制处理器操作模式和状态的系统控制标志:CR1保留不用:CR2含有导致页错误的线性地址:C ...

  9. php之上传小案例,根据时间:月日分创建目录并随机生成文件名

    <?php /* 接收文件,并分目录存储,生成随机文件名 1.根据时间戳,并按一定规则创建目录 2.获取文件名的后缀名 3.判断大小 */ //根据月日分计算并创建目录 function mk_ ...

  10. opencv在VS2010命令行编译过程

    最近这两天一直在研究命令行参数的编译,现代吗如下: #include <highgui.h> #include <math.h> #include <cv.h> I ...