POJ1745解题报告
来源:互联网 发布:python 多线程 sleep 编辑:程序博客网 时间:2024/06/05 11:50
Divisibility
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 6873 Accepted: 2294
Description
Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us, for example, take the sequence: 17, 5, -21, 15. There are eight possible expressions: 17 + 5 + -21 + 15 = 16
17 + 5 + -21 - 15 = -14
17 + 5 - -21 + 15 = 58
17 + 5 - -21 - 15 = 28
17 - 5 + -21 + 15 = 6
17 - 5 + -21 - 15 = -24
17 - 5 - -21 + 15 = 48
17 - 5 - -21 - 15 = 18
We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5.
You are to write a program that will determine divisibility of sequence of integers.
17 + 5 + -21 - 15 = -14
17 + 5 - -21 + 15 = 58
17 + 5 - -21 - 15 = 28
17 - 5 + -21 + 15 = 6
17 - 5 + -21 - 15 = -24
17 - 5 - -21 + 15 = 48
17 - 5 - -21 - 15 = 18
We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5.
You are to write a program that will determine divisibility of sequence of integers.
Input
The first line of the input file contains two integers, N and K (1 <= N <= 10000, 2 <= K <= 100) separated by a space.
The second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value.
The second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value.
Output
Write to the output file the word "Divisible" if given sequence of integers is divisible by K or "Not divisible" if it's not.
Sample Input
4 717 5 -21 15
Sample Output
Divisible
题意:给定n个数和一个K,问这n个数通过加减得到的结果能不能被K整除
思路:自己想了一会,发现只需要记住当前i步所有变换%k能得到的余数,在用第i+1个数在第i步得到所有余数的基础上再得到i+1步所有
的余数(i=0...i=n-1),最后判断是否能得到余数0即可。。
- POJ1745解题报告
- poj1745
- POJ1745
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- 解题报告
- poj1745 Divisibility
- poj1745 Divisibility
- poj1745 - Divisibility
- poj1745 Divisibility
- poj1745 dp
- poj1745 Divisibility
- [DP]poj1745
- 【poj1745】Divisibility
- Android事件处理分析
- hbase安装与配置
- ASP.Net中类似Servlet的东西
- hive安装与配置
- android 铃声设置流程讲解
- POJ1745解题报告
- CCNA实验十九 静态与默认路由
- 流程中的Task节点(上)
- J2ME电话薄源代码重新整理
- 配置Apache,支持WAP OTA [转]
- 【转】关于Java多线程的思考
- 10.21.2010吉他课笔记
- System.Data.SqlClient.SqlError: 备份集中的数据库备份与现有的 'XXX' 数据库不同。
- FILE__,__LINE__,FUNCTION__实现代码跟踪(转载)