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

思路:由于只求最后一个人的编号,可以将一次操作后的人进行重编号,来进行状态转移,转化为子问题用dp来解决。dp方程比较容易写出,注意下细节就好了。

 #pragma comment(linker, "/STACK:102400000,102400000")

 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <ctime>
#include <cctype>
#include <set>
#include <bitset>
#include <functional>
#include <numeric>
#include <stdexcept>
#include <utility> using namespace std; #define mem0(a) memset(a, 0, sizeof(a))
#define mem_1(a) memset(a, -1, sizeof(a))
#define lson l, m, rt << 1
#define rson m + 1, r, rt << 1 | 1
#define define_m int m = (l + r) >> 1
#define rep_up0(a, b) for (int a = 0; a < (b); a++)
#define rep_up1(a, b) for (int a = 1; a <= (b); a++)
#define rep_down0(a, b) for (int a = b - 1; a >= 0; a--)
#define rep_down1(a, b) for (int a = b; a > 0; a--)
#define all(a) (a).begin(), (a).end()
#define lowbit(x) ((x) & (-(x)))
#define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
#define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
#define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
#define pchr(a) putchar(a)
#define pstr(a) printf("%s", a)
#define sstr(a) scanf("%s", a)
#define sint(a) scanf("%d", &a)
#define sint2(a, b) scanf("%d%d", &a, &b)
#define sint3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define pint(a) printf("%d\n", a)
#define test_print1(a) cout << "var1 = " << a << endl
#define test_print2(a, b) cout << "var1 = " << a << ", var2 = " << b << endl
#define test_print3(a, b, c) cout << "var1 = " << a << ", var2 = " << b << ", var3 = " << c << endl typedef long long LL;
typedef pair<int, int> pii;
typedef vector<int> vi; const int dx[] = {, , -, , , , -, -};
const int dy[] = {-, , , , , -, , - };
const int maxn = 2e2 + ;
const int md = ;
const int inf = 1e9 + ;
const LL inf_L = 1e18 + ;
const double pi = acos(-1.0);
const double eps = 1e-; template<class T>T gcd(T a, T b){return b==?a:gcd(b,a%b);}
template<class T>bool max_update(T &a,const T &b){if(b>a){a = b; return true;}return false;}
template<class T>bool min_update(T &a,const T &b){if(b<a){a = b; return true;}return false;}
template<class T>T condition(bool f, T a, T b){return f?a:b;}
template<class T>void copy_arr(T a[], T b[], int n){rep_up0(i,n)a[i]=b[i];}
int make_id(int x, int y, int n) { return x * n + y; } int p[maxn], f[maxn][maxn], ans[maxn];
int main() {
//freopen("in.txt", "r", stdin);
int T, n, m;
cin >> T;
while (T--) {
cin >> n >> m;
rep_up0(i, m) {
sint(p[i]);
}
mem0(f);
f[n][] = true;
for (int i = n - ; i; i --) {
for (int j = ; j < n - i + ; j ++) {
rep_up0(k, m) {
if ((p[k] + n - i) % (n - i + ) == j) continue;
int sta, tmp = p[k] % (n - i + );
if (j >= tmp) sta = j - tmp;
else sta = n - i + - tmp + j;
f[i][j] = f[i][j] || f[i + ][sta];
}
}
}
int cnt = ;
rep_up0(i, n) {
if (f[][i]) ans[cnt ++] = i + ;
}
cout << cnt << endl;
rep_up0(i, cnt) {
printf("%d%c", ans[i], i == cnt - ? '\n' : ' ');
}
}
return ;
}

[hdu5218]DP-约瑟夫环变形的更多相关文章

  1. 【约瑟夫环变形】UVa 1394 - And Then There Was One

    首先看到这题脑子里立刻跳出链表..后来继续看如家的分析说,链表法时间复杂度为O(n*k),肯定会TLE,自己才意识到果然自个儿又头脑简单了 T^T. 看如家的分析没怎么看懂,后来发现这篇自己理解起来更 ...

  2. HDU 5643 King's Game | 约瑟夫环变形

    经典约瑟夫环 }; ; i<=n; i++) { f[i] = (f[i-] + k) % i; } 变形:k是变化的 #include <iostream> #include &l ...

  3. Poj 3517 And Then There Was One(约瑟夫环变形)

    简单说一下约瑟夫环:约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3...n分别表示)围坐在一张圆桌周围.从编号为k的人开始报数,数到m的那个人出列:他的下一个人又从1开始报数,数到m的那个 ...

  4. poj 1012 &amp; hdu 1443 Joseph(约瑟夫环变形)

    题目链接: POJ  1012: id=1012">http://poj.org/problem?id=1012 HDU 1443: pid=1443">http:// ...

  5. F - System Overload(约瑟夫环变形)

    Description Recently you must have experienced that when too many people use the BBS simultaneously, ...

  6. G - And Then There Was One (约瑟夫环变形)

    Description Let’s play a stone removing game. Initially, n stones are arranged on a circle and numbe ...

  7. 14.约瑟夫环问题[JosephusProblem]

    [题目] n个数字(0,1,…,n-1)形成一个圆圈,从数字0开始,每次从这个圆圈中删除第m个数字(第一个为当前数字本身,第二个为当前数字的下一个数字).当一个数字删除后,从被删除数字的下一个继续删除 ...

  8. And Then There Was One(约瑟夫问题变形)

    题目链接:http://poj.org/problem?id=3517 And Then There Was One Time Limit: 5000MS   Memory Limit: 65536K ...

  9. HDU 5643 King's Game 【约瑟夫环】

    题意: 变形的约瑟夫环,最初为每个人编号1到n,第i次删去报号为i的人,然后从它的下一个人开始重新从1开始报号,问最终剩下第几号人? 分析: 首先看一下裸的约瑟夫环问题: 共n个人,从1开始报数,报到 ...

  10. C#实现约瑟夫环问题

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace orde ...

随机推荐

  1. 架构师修炼之微服务部署 - Docker简介

    Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器或Windows 机器上,也可以实现虚拟化,容器是 ...

  2. 小小小小小flag

    2020:300道题 小小小小小flag 150红题 100道橙题 50道黄题 努力变强!加油 我的主页: 主页https://www.luogu.com.cn/user/306734 谢谢大家,目前 ...

  3. 挑战全网最幽默的Vuex系列教程:第六讲 Vuex的管理员Module(实战篇)

    写在前面 这一讲是 Vuex 基础篇的最后一讲,也是最为复杂的一讲.如果按照官方来的话,对于新手可能有点难以接受,所以想了下,决定干脆多花点时间,用一个简单的例子来讲解,顺便也复习一下之前的知识点. ...

  4. 2019-2020-1 20199308《Linux内核原理与分析》第九周作业

    <Linux内核分析> 第八章 可执行程序工作原理进程的切换和系统的一般执行过程 8.1 知识点 进程调度的时机 ntel定义的中断类型主要有以下几种 硬中断(Interrupt) 软中断 ...

  5. Metasploit渗透测试环境搭建

    渗透测试实验环境搭建 下载虚拟机镜像 5个虚拟机镜像,其中Linux攻击机我选择用最新的kali Linux镜像,其余的均使用本书配套的镜像. 网络环境配置 VMware虚拟网络编辑器配置: 将VMn ...

  6. CentOS 7.4 安装网易云音乐

    1.下包–>网易云音乐 Ubuntu14.04(推荐14.04依赖包网上能找到) 提示:16.04有部分依赖包还找不到,有兴趣可以自行打包RPM安装. 2.解包 (1)使用 ar -vx解压ub ...

  7. Windows VHD Create, Attach, 获得Disk序号

    // create_vhd.cpp : Defines the entry point for the console application. // #include "stdafx.h& ...

  8. cocos2dx新建项目

    首先你得下载好cococs2dx,还有python2.x版本,还有vs2017 然后cmd在你Cocos2dx的路径下输入 python setup.py 然后你就回车回车回车 然后重新打开cmd 这 ...

  9. HDU 6341 Let Sudoku Rotate

    #include<bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i=a;i<=b;++i) #defi ...

  10. Excel中的clean函数

    纯属note. 之前经常用excel处理数据的时候,对长文本或网站上拉取的值都会用clean函数清除一些我们肉眼看不到的非打印字符. Excel官方介绍:clean 删除文本中的所有非打印字符. 此次 ...