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.另注,本文章中贴 ...
随机推荐
- Django restful-framework初步学习
urls.py from django.conf.urls import include, url from django.contrib import admin from rest_framewo ...
- iOS开发-简单的循环结构分析
1.while循环 while (循环条件) { 循环体: } // 1.定义循环变量 ; // 2.循环条件 ) { // 3.循环体 printf("%d\n" ...
- 20145237《Java程序设计》实验报告一
实验一 Java开发环境的熟悉(Windows + Eclipse) 实验内容 1.使用JDK编译.运行简单的Java程序: 2.使用Eclipse 编辑.编译.运行.调试Java程序. 实验要求 1 ...
- bzoj千题计划243:bzoj2325: [ZJOI2011]道馆之战
http://www.lydsy.com/JudgeOnline/problem.php?id=2325 设线段树节点区间为[l,r] 每个节点维护sum[0/1][0/1] 从l的A/B区域到r的 ...
- Microsoft dynamic 批量更新
//批量处理 ExecuteMultipleRequest multipleRequest = new ExecuteMultipleRequest() { Settings = new Execut ...
- 虚拟机Vmware成功安装Ubuntu Server 16.04中文版
最近想在Linux下学习Python的爬虫开发技术,经过认真考虑优先选择在在Ubuntu环境下进行学习Python的开发,虽然Ubuntu Server 16.04 LTS版本已经集成了Python ...
- WPF自定义控件与样式-自定义按钮(Button)
一.前言 程序界面上的按钮多种多样,常用的就这几种:普通按钮.图标按钮.文字按钮.图片文字混合按钮.本文章记录了不同样式类型的按钮实现方法. 二.固定样式的按钮 固定样式的按钮一般在临时使用时或程序的 ...
- sts中maven
建立一个maven web的工程 网上有很多关于maven的下载,配置等,我这里就不多说了. 下面介绍主要介绍关于在sts中建立一个maven时最开始出现的错误问题. 创建maven工程 file-& ...
- ubuntu16.04下安装chrome
1.在终端中,输入以下命令: sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.l ...
- maven管理的jsp应用如何添加servlet、jsp相关依赖(org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp)
背景: 老大让做权限控制,研究了一下shiro,下了个demo下来,死活跑不起来,报 org.apache.jasper.JasperException: java.lang.ClassNotFoun ...