2016年武汉科技大学邀请赛网络赛 F题
来源:互联网 发布:天津网络推广公司 编辑:程序博客网 时间:2024/06/10 22:28
A Stones Game
Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: 13 Accepted: 2
[Submit][Status][Web Board]
Description
Alice and Bob are playing a stones picking game. The rules of the game is like this: some indentical stones, total n, every time the player can only pick the stones of the number a, which is one of A1 - Am sequence. The one who takes the last stone will win the game! Alice plays first. Alice wants to know whether there is a winning strategy, if yes output the number for the first step, otherwise output "No".
Input
Each test case has two lines.
The first line contain two integer n and m (1<=n<=1e9,1<=m<=10).
The second line contains m integers A1, A2, ..., Am, each integer is in the range of [1, 10].
Output
Output a single integer — If there exists a answer output it (if there are multiple solutions output the minimum); Otherwise output "No".
Sample Input
17 31 2 4
Sample Output
2
HINT
We should find that there could be a state that none of them will win. For exmaple, if there are 7 stones, each one could only take two stones for a time. They could not take the last stone forever. Then, none of them will be the winner.
题目意思:n堆石子,每一次每个人可以选择m个数中的一个数,拿走对应数量石子的胜。问第一步走什么保证有必胜策略。
题解:可以注意到这些数字非常小。所以每一步的状态之多和前10步的状态有关。那么至多经过(3^10)步就会面临之前相同的情况,这样救有了循环。利用循环节加速中间过程即可。
注意有一种情况双方都没有必胜策略。
- 2016年武汉科技大学邀请赛网络赛 F题
- 2016年武汉科技大学邀请赛网络赛 A题
- 2016年武汉科技大学邀请赛网络赛 B题
- 2016年武汉科技大学邀请赛网络赛 J题
- 2016年武汉科技大学邀请赛网络赛 D题
- 2016年武汉科技大学邀请赛网络赛 C题
- 2016年武汉科技大学邀请赛网络赛 E题
- 2016年武汉科技大学邀请赛网络赛 G题
- 2016年武汉科技大学邀请赛网络赛 H题
- 2016年武汉科技大学邀请赛网络赛 I题
- 2016武汉科技大学邀请赛现场赛 F题
- 2016武汉科技大学邀请赛现场赛 A题
- 2016武汉科技大学邀请赛现场赛 B题
- 2016武汉科技大学邀请赛现场赛 C题
- 2016武汉科技大学邀请赛现场赛 D题
- 2016武汉科技大学邀请赛现场赛 E题
- 2016武汉科技大学邀请赛现场赛 G题
- 2016武汉科技大学邀请赛现场赛 L
- poj 1195 Mobile phones(二维树状数组)
- shell原理和问答机制引入
- cf#221-div1-D - Tree and Queries-dfs序+莫队算法
- 简易版 文件上传UpdateFile(Struts2版)
- HBase Rowkey的散列与预分区设计
- 2016年武汉科技大学邀请赛网络赛 F题
- QTableWidget使用总结
- db2 常用sql
- <html>img、map、area
- JAVA程序员一定知道的优秀第三方库(2016版)
- UITableView-04Cell的循环利用
- sql的子连接查询
- java网络编程(URL类)
- Json格式