UVa 10489 - Boxes of Chocolates
来源:互联网 发布:一知f君张碧晨 编辑:程序博客网 时间:2024/06/11 04:09
题目:有B个盒子,没个盒子中有a1个小盒子,每个小盒子里面还有a2个更小的盒子,...;
最小的盒子里有ak个巧克力,问把巧克力分给N个人后的余数。
分析:模拟,大整数乘法,余数运算。直接利用Java的大数类求解。
说明:(⊙_⊙)类名要是Main。
import java.util.Scanner; import java.math.BigInteger; class Main{ public static void main(String[] args) { Scanner cin = new Scanner(System.in); int T = cin.nextInt(); int N, B, K; while (T -- > 0) { N = cin.nextInt(); B = cin.nextInt(); BigInteger ans = BigInteger.valueOf(0); while (B -- > 0) { K = cin.nextInt(); BigInteger tmp = BigInteger.valueOf(1); while (K -- > 0) { tmp = tmp.multiply(BigInteger.valueOf(cin.nextInt())); } ans = ans.add(tmp); } System.out.println((ans.remainder(BigInteger.valueOf(N))).toString()); } } }
0 0
- UVa 10489 - Boxes of Chocolates
- Boxes of Chocolates Again UVA
- uva 10590 Boxes of Chocolates Again
- UVa:10590 Boxes of Chocolates Again
- UVa-10590-Boxes of Chocolates Again
- 【简单dp】Boxes of Chocolates Again
- Give me a big box of chocolates
- UVa 103 Stacking Boxes
- UVA 103 - Stacking Boxes
- uva 103 - Stacking Boxes
- uva Boxes 11003
- uva 103 Stacking Boxes
- [UVA 103] Stacking Boxes
- UVa 103.Stacking Boxes
- uva:103 - Stacking Boxes
- UVa 103 - Stacking Boxes
- UVA - 103 Stacking Boxes
- uva 103 - Stacking Boxes
- hdu 1664 Different Digits, spoj 3929 , 同余,bfs
- jsp超链接传递中文乱码问题
- VC++ Service编程(七)创建多线程服务
- VC++ Service编程(八)多线程服务
- 不使用第三个变量交换两个变量的值之"异或"的实际应用
- UVa 10489 - Boxes of Chocolates
- 位图初级(一)——位图的存储
- 《C++入门经典》读书笔记+习题解答 第9章 函数
- FlowVisor的学习笔记
- Redis常用命令解析——INFO, MONITOR, SLOWLOG
- Java基础之静态修饰符知识点总结
- C++: string的大小写转换
- Android中Context详解 ---- 你所不知道的Context
- android用户网络检测工具