Game(hdu5218)
Game
BrotherK is very rich. He has a big company.
One day, BrotherK wants to give an award to one of the employees in the company. It's so hard to make a choise that BrotherK decides to play a game to determine the lucky dog.
At the beginning of the game, all NN employees form a circle. Then, they receive t-shirts with numbers 1 through NN in clockwise order along the circle.
The game consists of many turns. In the ith turn, BrotherK starts by standing in front of a employee and announces a number X_iXi. He will move to the (X_i+1Xi+1)th-next-employee in clockwise order, and the X_iXith-next-employees will be removed from the circle, then the (i+1)th turn starts.
Attention that the 1th-next-employee of a employee is itself, and BrotherK stands in front of the employee with number 1 at first. In the ith turn, The value of X_iXi is chosen randomly from a given integer set SS. When there is only one employee left in the game, the game ends and the employee wins the award.
You are given the int NN and the set of integers, BrotherK wants to know which employees are possible to win.
The first line contains a single integer TT, indicating the number of test cases.
Each test case begins with two integer N, MN,M, indicating the number of employees in BrotherK's company, and the size of BrotherK's integer set SS. Next line contains MM numbers, from a_1a1 to a_MaM, indicating the integer in SS.
TT is about 50
1~\le~N, M~\le~2001 ≤ N,M ≤ 200
1~\le~a_i~\le~10^91 ≤ ai ≤ 109
For each test, print two lines.
The first line contains a integer KK, indicating how many people are possible to win.
The second line contains KK number, indicating the number in T-shirt who can win, in ascending order.
2
3 1
1
3 2
1 2
1
3
3
1 2 3
思路:dp+约瑟夫环;
约瑟夫环的问题可以用递推来解决,ans[n] = (ans[n-1]+m)%n;那么这次每次可以有多个间隔,那么dp[i][j]表示当执行第n-i+1次时下标为j是否存在;具体过程看代码
1 #include<iostream>
2 #include<cstdio>
3 #include<cstring>
4 #include<string>
5 #include<cmath>
6 #include<cstdlib>
7 #include<queue>
8 #include<stack>
9 #include<map>
10 #include<vector>
11 #include<algorithm>
12 using namespace std;
13 typedef long long LL;
14 bool flag[10000];
15 int dp[205][205];
16 int ask[1000];
17 int main(void)
18 {
19 int T;
20 scanf("%d",&T);
21 while(T--)
22 {
23 int n,m;
24 memset(flag,0,sizeof(flag));
25 scanf("%d %d",&n,&m);
26 int i,j;
27 memset(dp,-1,sizeof(dp));
28 for(i = 2; i < 205; i++)
29 {
30 for(j = 0; j < 205; j++)
31 {
32 dp[i][j] = -1;
33 }
34 }
35 for(i = 0; i < m; i++)
36 {
37 scanf("%d",&ask[i]);
38 }
39 dp[1][0] = 1;
40 for(i = 2; i <= n; i++)
41 for(j = 0; j <= i; j++)
42 if(dp[i-1][j]!=-1)
43 for(int s = 0; s < m; s++)
44 dp[i][(j+ask[s])%i] = 1;
45 int sum = 0;
46 int ac[1000];
47 for(i = 0; i < n; i++)
48 {
49 if(dp[n][i]==1)
50 {
51 ac[sum++] = i+1;
52 }
53 }
54 printf("%d\n",sum);
55 printf("%d",ac[0]);
56 for(i = 1; i < sum; i++)
57 printf(" %d",ac[i]);
58 printf("\n");
59 }
60 return 0;
61 }
Game(hdu5218)的更多相关文章
- [hdu5218]DP-约瑟夫环变形
题意:n个人围成一圈,另外一个人最开始站在第一个人前面,每次从集合s里面随机选一个数x,这个人顺时针经过x个人后停下来,当前位置的前一个人出队,然后继续进行,求最后剩下的那个人的可能编号. 思路:由于 ...
随机推荐
- k8s集群中部署Rook-Ceph高可用集群
先决条件 为确保您有一个准备就绪的 Kubernetes 集群Rook,您可以按照这些说明进行操作. 为了配置 Ceph 存储集群,至少需要以下本地存储选项之一: 原始设备(无分区或格式化文件系统) ...
- Netty4.x 源码实战系列(一): 深入理解ServerBootstrap 与 Bootstrap (1)
从Java1.4开始, Java引入了non-blocking IO,简称NIO.NIO与传统socket最大的不同就是引入了Channel和多路复用selector的概念.传统的socket是基于s ...
- spring下春注解的声明式事务控制
package com.hope.test;import com.hope.domain.Account;import com.hope.service.IAccountService;import ...
- Selenium和PhantomJS
Selenium Selenium是一个Web的自动化测试工具,最初是为网站自动化测试而开发的,类型像我们玩游戏用的按键精灵,可以按指定的命令自动操作,不同是Selenium 可以直接运行在浏览器上, ...
- 二叉搜索树、平衡二叉树、红黑树、B树、B+树
完全二叉树: 空树不是完全二叉树,叶子结点只能出现在最下层和次下层,且最下层的叶子结点集中在树的左部.如果遇到一个结点,左孩子不为空,右孩子为空:或者左右孩子都为空:则该节点之后的队列中的结点都为叶子 ...
- 【Linux】【CentOS7】免密登录突然失效
[报错解决]免密登录突然失效 哔哩哔哩 萌狼蓝天 博客:萌狼工作室-博客园 [问题描述] 原本配置好了的免密登录,今天启动hadoop发现免密登录失效了 [解决方案] 1.切换到管理员模式,进入配置文 ...
- 03 - Vue3 UI Framework - 首页
顶部边栏做完了,接下来开始做官网的首页 返回阅读列表点击 这里 创建视图文件夹 让我们先新建一个 src/views 文件夹,用来存放官网的主要视图 然后在该文件夹下新建两个 vue 文件,作为我们的 ...
- Jenkins pipeline声明式语法
目录 一.最简结构 二.简单例子 一.最简结构 pipeline { agent any stages { stage('pull') { st ...
- Log4j漏洞源码分析
Log4j漏洞源码分析 这几天Log4j的问题消息满天飞,今天我们就一起来看看从源码角度看看这个漏洞是如何产生的. 大家都知道这次问题主要是由于Log4j中提供的jndi的功能. 具体涉及到的入口类是 ...
- java JDK8 时间处理
目录 时间格式化 LocalDate:年月日 LocalTime:时分秒毫秒 LocalDateTime:年月日时分秒 Instant:纳秒时间戳 Duration:两时间间隔 Duration:处理 ...