UVALive4727:jump
约瑟夫环变式
设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的更多相关文章
- LeetCode第[55]题(Java):Jump Game
题目:跳跳游戏 难度:Medium 题目内容: Given an array of non-negative integers, you are initially positioned at the ...
- LeetCode OJ:Jump Game(跳跃游戏)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- LeetCode OJ:Jump Game II(跳跃游戏2)
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Gym - 100851J: Jump(交互+构造+(大胆瞎搞)))
题意:给定长度为N的01串,现在让你猜这个串,猜的次数要不超过N+500次. 每次你猜一个串,系统会返回N/2,或N,或0.当且当有N/2个位置猜对,N个位置猜对,其他. 思路:因为信息不多,没有关联 ...
- leetcode笔记:Jump Game
一. 题目描写叙述 Given an array of non-negative integers, you are initially positioned at the first index o ...
- 原创 C++应用程序在Windows下的编译、链接:第三部分 静态链接(二)
3.5.2动态链接库的创建 3.5.2.1动态链接库的创建流程 动态链接库的创建流程如下图所示: 在系统设计阶段,主要的设计内容包括:类结构的设计以及功能类之间的关系,动态链接库的接口.在动态链接库中 ...
- [LeetCode] Jump Game 跳跃游戏
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- [LeetCode] Jump Game II 跳跃游戏之二
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- MIT JOS学习笔记01:环境配置、Boot Loader(2016.10.22)
未经许可谢绝以任何形式对本文内容进行转载! 一.环境配置 关于MIT课程中使用的JOS的配置教程网上已经有很多了,在这里就不做介绍,个人使用的是Ubuntu 16.04 + qemu.另注,本文章中贴 ...
随机推荐
- JAVA使用和操作properties文件
java中的properties文件是一种配置文件,主要用于表达配置信息,文件类型为*.properties,格式为文本文件,文件的内容是格式是"键=值"的格式,在properti ...
- 创建带缩进的XML
from xml.etree import ElementTree as ET from xml.dom import minidom root = ET.Element('}) son=ET.Sub ...
- [Cerc2013]Magical GCD
https://vjudge.net/problem/UVA-1642 题意:在一个序列中,找出一段连续的序列,使得长度*gcd最大 固定右端点,当左端点从左向右移动时,gcd不变或变大 gcd相同时 ...
- D的下L
D的小L 时间限制:4000 ms | 内存限制:65535 KB 难度:2 描述 一天TC的匡匡找ACM的小L玩三国杀,但是这会小L忙着哩,不想和匡匡玩但又怕匡匡生气,这时小L给 ...
- 构建微服务开发环境7————使用Github管理项目代码的版本
[内容指引] 1.注册GitHub帐号: 2.下载Github Desktop客户端: 3.macOS安装Github Desktop客户端: 4.windows安装Github Desktop客户端 ...
- python基础学习篇章一
一. 对Python的认识 1. Python的标准实现方式是将源代码的语句编译为字节码的形式,之后再将字节码解释出来.由于字节码是一种与平台无关的形式,字节码具有可移植性.但是Python没有将代码 ...
- Java8-如何构建一个Stream
Stream的创建方式有很多种,除了最常见的集合创建,还有其他几种方式. List转Stream List继承自Collection接口,而Collection提供了stream()方法. List& ...
- 分布式系统之消息中间件rabbitmq
分布式系统之消息中间件rabbitmq 博客分类: 感谢: 一般php 用rabbitmq java 用activemq http://spartan1.iteye.com/blog/11802 ...
- nodeJS基于smtp发邮件
邮件的协议smtp是tcp/ip族中的一个协议,所以我们这次考虑使用net模块来发送邮件. const net = require('net') const assert = require('ass ...
- angular2 学习笔记 ( animation 动画 )
refer : https://angular.io/guide/animations https://github.com/angular/angular/blob/master/packages/ ...