杭电2410Baskets_Of_Gold_Coins
2016-12-22 20:13
204 查看
/* * 题目: Baskets_Of_Gold_Coins(篮子里的金币) 翻译:给你N个篮子装金币。也就是说篮子的数量是从1到N个,在所有篮子中除了一个篮子,每个普通篮子里金币的重量都是 w 克 在那个特殊的篮子里面金币的重量为 d ,一个巫师现在从1号个篮子里面取出 1 个硬币,从2号篮子中取出2个金币,一次类推 从n-1号篮子里面取出n-1个金币。但是他没有在第N个篮子中取出任何一个金币(也就是说第n个篮子不取)。他计算了取出来金币一共的重量, (也就是说把取出来的金币拿去称的出总共的重量)。现在你的任务就是给出你 n w d 和取出的总重量 输入文件将包含一个或多个行,每一行将包含数据问题的一个实例。更具体地说,每一行将包含四个正整数,每个数据将由一个空格分隔。 前三个整数分别是,N,w,d,第四个整数是权衡选择的硬币的结果。 N的数据大小将至少8000以上。w的值最大为30,d的值要小于w。 为每个实例的问题,您的程序将生成一行输出,包含一个正整数:包含轻硬币的篮子的数量比另一个篮子。 有一个坑要注意(d的) */ package Baskets_Of_Gold_Coins; 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 sumw = sc.nextInt(); int sum = (((1 + n) * n) / 2 - n) * w; //金币应有的总重量 int result = (sum - sumw) / d; if (result == 0) { System.out.println(n); } else { System.out.println(result); } } } }
相关文章推荐
- 杭电acm- 2401 Baskets of Gold Coins
- hdu2401 Baskets of Gold Coins
- HDU2401 Baskets of Gold Coins【水题】【推理】
- hust 1170 - Baskets of Gold Coins
- HDU 2401.Baskets of Gold Coins
- HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
- HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
- HDOJ 2401 Baskets of Gold Coins
- HDOJ 2401 Baskets of Gold Coins (数学题)
- HDU 2401 Baskets of Gold Coins
- HDU-2401-Baskets of Gold Coins
- hdoj 2401 Baskets of Gold Coins
- HDU 2401 Baskets of Gold Coins
- hdu 2401 Baskets of Gold Coins
- hdu 2401 Baskets of Gold Coins
- hdu 2401 Baskets of Gold Coins
- Baskets of Gold Coins
- Baskets of Gold Coins
- HDU 2401:Baskets of Gold Coins
- Baskets of Gold Coins 2401