Game

 Accepts: 138
 Submissions: 358
 Time Limit: 2000/1000 MS (Java/Others)
 Memory Limit: 131072/131072 K (Java/Others)
Problem Description

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_iX​i​​. He will move to the (X_i+1X​i​​+1)th-next-employee in clockwise order, and the X_iX​i​​th-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_iX​i​​ 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.

Input

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_1a​1​​ to a_Ma​M​​, 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 ≤ a​i​​ ≤ 10​9​​

Output

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.

Sample Input
2
3 1
1
3 2
1 2
Sample Output
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)的更多相关文章

  1. [hdu5218]DP-约瑟夫环变形

    题意:n个人围成一圈,另外一个人最开始站在第一个人前面,每次从集合s里面随机选一个数x,这个人顺时针经过x个人后停下来,当前位置的前一个人出队,然后继续进行,求最后剩下的那个人的可能编号. 思路:由于 ...

随机推荐

  1. 13.Merge k Sorted Lists

    思路:利用map<int,vector<ListNode*> > 做值和指针的映射,最后将指针按值依次链接起来, 时间复杂度O(N),空间O(N) Merge k sorted ...

  2. springcloud - alibaba - 2 - 集成Feign - 更新完成

    1.依赖 依赖管理 <parent> <artifactId>spring-boot-parent</artifactId> <groupId>org. ...

  3. LeetCode数组中重复的数字

    LeetCode 数组中重复的数字 题目描述 在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内.数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次. ...

  4. 对于vue项目更新迭代导致上传至服务器后出现Loading chunk {n} failed和Unexpected token <的解决方式

    相信大家对于vue项目的维护与更新中会遇见很多问题,其中有两种情况最为常见. 一种是Loading chunk {n} failed,这种情况出现的原因是vue页面更新上传至服务器后,由于vue默认打 ...

  5. 8. LINUX shell 环境变量

    wc –l file 计算文件行数, wc -w file  计算文件中的单词数, wc -c file   计算文件中的字符数 查看文件内容: cat .more

  6. 网口程序udp

    # -*- coding: utf-8 -*- """ Created on Thu Nov 12 15:02:53 2020 @author: Administrato ...

  7. 单链表的模板类(C++)

    /*header.h*/#pragma once #include<iostream> using namespace std; template<class T> struc ...

  8. android 下动态获取控件的id

    有时候我们需要动态的取得一个一个控件的id,然后进行操作,经过在网上查找,找到了一下方法getResources().getIdentifier("textView01", &qu ...

  9. 解决ViewPager与ScrollView 冲突

    ViewPager来实现左右滑动切换tab,如果tab的某一项中嵌入了水平可滑动的View就会让你有些不爽,比如想滑动tab项中的可水平滑动的控件,却导致tab切换. 因为Android事件机制是从父 ...

  10. linux如何安装缺失依赖

    这里要提到一个网站https://pkgs.org/,他是linux系统的一个相关网站,里面都是相关内容 Warning: RPMDB altered outside of yum. ** Found ...