HDOJ 2401 Baskets of Gold Coins
来源:互联网 发布:淘宝货到付款回款周期 编辑:程序博客网 时间:2024/05/18 17:41
HDACM 2401
题目的意思:
有N个篮子,编号1—N,篮子中有很多金币,每个重w.但是有一个编号的篮子中,每个金币重w-d.女巫从第一个篮子中拿1个金币,第二个篮子中拿2个……第N-1中拿N-1个,第N中不拿,给出这些金币的总重量s,问:是第几个篮子中的金币重量较轻?
题解:
先求1—N篮子金币应有的总重量yuan=w*(1+n-1)(n-1)/2,然后求差值cha=原-s ,再除以金币重量差值d则得出轻金币的个数。若为0,则必在编号N的篮子中;若不为0,得到较轻金币的个数,即为所求编号。
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 x = sc.nextInt(); int sum = (n - 1) * n / 2 * w - x; if (sum == 0) { System.out.println(n); }else{ System.out.println(sum/d); } } sc.close(); }}
阅读全文
0 0
- HDOJ 2401 Baskets of Gold Coins
- HDOJ 2401 Baskets of Gold Coins
- Baskets of Gold Coins 2401
- HDOJ 2401 Baskets of Gold Coins(数学,等差数列求和)
- HDOJ 2401 Baskets of Gold Coins (数学题)
- HDOJ(HDU) 2401 Baskets of Gold Coins(数列、)
- 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 2401 (简单数学题)
- HDU 2401:Baskets of Gold Coins
- hdu 2401 Baskets of Gold Coins
- hdu2401 Baskets of Gold Coins
- 杭电acm- 2401 Baskets of Gold Coins
- HDU 2401 Baskets of Gold Coins(数学题)
- HDU2401 Baskets of Gold Coins【水题】【推理】
- 11.28 学习笔记
- 数据分析之《菜鸟侦探挑战数据分析》-5-r语言-聚类分析
- 简单的vue日历组件
- 深入理解Java虚拟机之判断对象是否存活
- 2017-11
- HDOJ 2401 Baskets of Gold Coins
- HTML Web图形样式基础1
- 打包及签名文件
- xml文件--SAX方式解析xml文件
- centos 7 硬盘扩容
- 基础篇 5.会话跟踪
- JVM工作流程
- 第一次学习总结
- print函数用法