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个人后停下来,当前位置的前一个人出队,然后继续进行,求最后剩下的那个人的可能编号. 思路:由于 ...
随机推荐
- nordic 51822 sdk. timer 的使用
它的源代码和头文件分别为app_timer.c/app_timer.h.这是Nordic为我们提供的虚拟定时器,这个定时器不同于硬件上的TIMER,而是基于RTC1实现的一种虚拟定时器,其将定时功能作 ...
- C#数字验证
using System; using System.Collections; using System.Configuration; using System.Data; using System. ...
- Windows系统安装MySQL详细教程和安装过程中问题汇总(命令安装),更新时间2021-12-8
安装包下载 下载地址:https://dev.mysql.com/downloads/mysql/ 点击下载之后,可以选择注册Oracle账号,也可以跳过直接下载. 下载完成后,选择一个磁盘内放置并解 ...
- 零基础学习java------25--------jdbc
jdbc开发步骤图 以下要用到的products表 一. JDBC简介 补充 JDBC本质:其实是官方(sun公司)定义的一套操作所有关系型数据库的规则,即接口,各个数据库厂商趋势线这个接口,提 ...
- spring mvc idea创建
创建项目 创建项目 --> Spring --> Spring MVC --> 下面选择Download,会显示Spring MVC-5版本 如果是首次使用IDEA,因为没有配置ma ...
- 【编程思想】【设计模式】【结构模式Structural】装饰模式decorator
Python版 https://github.com/faif/python-patterns/blob/master/structural/decorator.py #!/usr/bin/env p ...
- SpringBoot的定时任务
springBoot定时任务可分为多线程和单线程,而单线程又分为注解形式,接口形式 1.基于注解形式 基于注解@Scheduled默认为单线程,开启多个任务时,任务的执行时机会受上一个任务执行时间的影 ...
- Git初始化及仓库创建和操作
一.基本信息配置 1.全局配置用户名 git config --global user.name "YeHuan-byte" 2.全局配置邮箱 git config --globa ...
- 莫烦python教程学习笔记——validation_curve用于调参
# View more python learning tutorial on my Youtube and Youku channel!!! # Youtube video tutorial: ht ...
- 资源相关视图(Project)
<Project2016 企业项目管理实践>张会斌 董方好 编著 这里就扯到资源了,资源是啥意思?如果是教科书,怕又是有一个名词解释要背吧,吼吼--其实这个资源在这里的意思基本上猜就能猜到 ...