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 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(数列、)的更多相关文章
- hdoj 2401 Baskets of Gold Coins
Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Baskets of Gold Coins
Baskets of Gold Coins Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Baskets of Gold Coins_暴力
Problem Description You are given N baskets of gold coins. The baskets are numbered from 1 to N. In ...
- HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化)
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数 ...
- HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解)
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #in ...
- HDU 5783 Divide the Sequence(数列划分)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏
Gold Coins Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 21767 Accepted: 13641 Desc ...
- OpenJudge/Poj 2000 Gold Coins
1.链接地址: http://bailian.openjudge.cn/practice/2000 http://poj.org/problem?id=2000 2.题目: 总Time Limit: ...
- H - Gold Coins(2.4.1)
H - Gold Coins(2.4.1) Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:3000 ...
随机推荐
- Java异常之try,catch,finally,throw,throws
Java异常之try,catch,finally,throw,throws 你能区分异常和错误吗? 我们每天上班,正常情况下可能30分钟就能到达.但是由于车多,人多,道路拥挤,致使我们要花费更多地时间 ...
- struts_ognl详解
- IK分词算法设计总结
IK分词算法设计思考 加载词典 IK分词算法初始化时加载了“敏感词”.“主词典”.“停词”.“量词”,如果这些词语的数量很多,怎么保证加载的时候内存不溢出 分词缓冲区 在分词缓冲区中进行分词操作,怎么 ...
- spring集成 log4j + slf4j
以maven web项目为例, 首先.在pom文件引入相关依赖,如下(spring官网文档有介绍): <dependencies> <!-- spring 相关 --> < ...
- angularjs sortbale
参考地址:http://kamilkp.github.io/angular-sortable-view 案例:jsp: <div sv-root sv-part="vm.dataLis ...
- [转帖]MATLAB曲线绘制及颜色类型
信号源产生的方法 来源:http://www.2cto.com/kf/201401/270494.html matlab的checkerboard说明,GOOD! 来源:http://www.chi ...
- Kettle的集群排序 2——(基于Windows)
5.使用kettle集群模式对相关的数据进行排序 既然,基于Carte服务程序所搭建的集群已经在Spoon中设定好了, 可以首先,先来启动四个节点: "以管理员身份运行"打开 四个 ...
- SDWebImage 在多线程下载图片时防止错乱的策略
在我们使用sd的时候,对tableView 上cell得图片进行异步下载的时候会遇到这样一个问题: 由于cell的重用机制,在我们加载出一个cell的时候imageView数据源开启一个下载任务并返 ...
- maven mirror
国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. ====================国内OSChina提供的镜像,非常不错=========== ...
- jacob 操作word
1. 首先下载jacob-1.18.zip,解压后有两个文件jacob.jar 和 jacob.dll.需要把jacob.jar放到你工程的classpath中并且把jacob.dll放到jdk的bi ...