约瑟夫环变式

设f[i][j]表示处理i个人,按照处理顺序,倒数第j个人是谁

则有f[i][j]=(f[i-1][j]+k)%i

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#define MAXN 500005
using namespace std;
int f[MAXN][];
int n,k;
void solve(){
scanf("%d%d",&n,&k);
int b[]={};
int t=-;
for(int i=;i>=;i--){
for(int j=;j<=k;j++){
(t+=)%=;
while(b[t]){
(t+=)%=;
}
}
f[][i]=t;
b[t]=;
}
for(int i=;i<=n;i++){
for(int j=;j<=;j++){
f[i][j]=(f[i-][j]+k)%i;
}
}
printf("%d %d %d\n",f[n][]+,f[n][]+,f[n][]+);
}
int main()
{
// freopen("data.in","r",stdin);
int T;
scanf("%d",&T);
while(T--){
solve();
}
return ;
}

UVALive4727:jump的更多相关文章

  1. LeetCode第[55]题(Java):Jump Game

    题目:跳跳游戏 难度:Medium 题目内容: Given an array of non-negative integers, you are initially positioned at the ...

  2. LeetCode OJ:Jump Game(跳跃游戏)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  3. LeetCode OJ:Jump Game II(跳跃游戏2)

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  4. Gym - 100851J: Jump(交互+构造+(大胆瞎搞)))

    题意:给定长度为N的01串,现在让你猜这个串,猜的次数要不超过N+500次. 每次你猜一个串,系统会返回N/2,或N,或0.当且当有N/2个位置猜对,N个位置猜对,其他. 思路:因为信息不多,没有关联 ...

  5. leetcode笔记:Jump Game

    一. 题目描写叙述 Given an array of non-negative integers, you are initially positioned at the first index o ...

  6. 原创 C++应用程序在Windows下的编译、链接:第三部分 静态链接(二)

    3.5.2动态链接库的创建 3.5.2.1动态链接库的创建流程 动态链接库的创建流程如下图所示: 在系统设计阶段,主要的设计内容包括:类结构的设计以及功能类之间的关系,动态链接库的接口.在动态链接库中 ...

  7. [LeetCode] Jump Game 跳跃游戏

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. [LeetCode] Jump Game II 跳跃游戏之二

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  9. MIT JOS学习笔记01:环境配置、Boot Loader(2016.10.22)

    未经许可谢绝以任何形式对本文内容进行转载! 一.环境配置 关于MIT课程中使用的JOS的配置教程网上已经有很多了,在这里就不做介绍,个人使用的是Ubuntu 16.04 + qemu.另注,本文章中贴 ...

随机推荐

  1. 201621123057 《Java程序设计》第2周学习总结

    一.本周学习总结 基本数据类型 char实质属于整型.boolean类型取值只有true和false两种. 引用数据类型 包装类:自动装箱 与 自动拆箱 数组:一维数组遍历数组用foreach循环:多 ...

  2. iOS Storyboard unwind segues使用小结

    使用storyboard开发的时候,经常会在一个scene上添加一个button,再拖拽这个button到某个想要关联的页面,最后选择push的方式跳转.这样scene_A和scene_B就有了一个& ...

  3. Tomcat 8项目无法启动,无报错

    作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Tomcat 8启动很慢,且日志上无任何错误,在日志中查看到如下信息: Log4j:[2015-10-29 ...

  4. 老板怎么办,我们网站遭到DDoS攻击又挂了?

    相信现在正在阅读此文的你,一定听说过发生在上个月的史上最大的DDoS攻击. 美国东部时间2月28日,GitHub在一瞬间遭到高达1.35Tbps的带宽攻击.这次DDoS攻击几乎可以堪称是互联网有史以来 ...

  5. nyoj 背包问题

    背包问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 现在有很多物品(它们是可以分割的),我们知道它们每个物品的单位重量的价值v和重量w(1<=v,w< ...

  6. NoSQL简介

    相信大家也多多少少了解过一些数据库,最常用的当属MySQL了,当然也这是关系型数据库的代表了 常见的关系型数据库有:MySQL.SQLServer.Oracle 而数据库也有另一个流派-----NoS ...

  7. C语言学习之弹跳小球

    重新回过头来看了一遍C语言,才发现我自己的无知,C语言其实好强大,我之前学的不过是一点C语法和做几个数学题.正好3月份的考试要考C语言,重新学一遍,先是在中国大学mooc上把翁恺老师的C语言刷了一遍, ...

  8. OAuth2.0学习(1-7)授权方式4-客户端模式(Client Credentials Grant)

    授权方式4-客户端模式(Client Credentials Grant) 客户端模式(Client Credentials Grant)指客户端以自己的名义,而不是以用户的名义,向"服务提 ...

  9. HTML mate标签

    META标签分两大部分:HTTP标题信息(http-equiv)和页面描述信息(name). http-equiv http-equiv类似于HTTP的头部协议,它回应给浏览器一些有用的信息,以帮助正 ...

  10. 转:NLP+句法结构(三)︱中文句法结构(CIPS2016、依存句法、文法)

    NLP+句法结构(三)︱中文句法结构(CIPS2016.依存句法.文法)转自:https://www.cnblogs.com/maohai/p/6453389.html 摘录自:CIPS2016 中文 ...