hdu 5860 Death Sequence(递推+脑洞)
Now the problem is much easier: we have N men stand in a line and labeled from 1 to N, for each round, we choose the first man, the k+1-th one, the 2*k+1-th one and so on, until the end of the line.
For example, we have N = 7 prisoners, and we decided to kill every k=2 people in the line. At the beginning, the line looks like this:
1 2 3 4 5 6 7
after the first round, 1 3 5 7 will be executed, we have
2 4 6
and then, we will kill 2 6 in the second round. At last 4 will be executed. So, you need to output 1 3 5 7 2 6 4. Easy, right?
But the output maybe too large, we will give you Q queries, each one contains a number m, you need to tell me the m-th number in the death sequence.
#include <bits/stdc++.h> using namespace std;
const int maxn=3e6+;
int cnt[maxn];
int ans[maxn];//最后的答案
int n,k,q;
pair<int,int> dp[maxn];
int main()
{
//freopen("de.txt","r",stdin);
int t;
scanf("%d",&t);
while (t--){
scanf("%d%d%d",&n,&k,&q);
memset(cnt,,sizeof cnt);
for (int i=;i<n;++i){
dp[i].first=i%k?(dp[i-i/k-].first+):;
dp[i].second=cnt[dp[i].first]++;//求出来第i人的轮数,相应轮数cnt++
}
for (int i=;i<maxn;++i){
if (cnt[i]==)
break;
cnt[i]+=cnt[i-];//处理前缀和,即第i轮之前一共杀死多少人
}
for (int i=;i<n;++i){
ans[(dp[i].first?cnt[dp[i].first-]:)+dp[i].second]=i;
}
for (int i=;i<q;++i){
int x;
scanf("%d",&x);
printf("%d\n",ans[x-]+);
}
}
return ;
}
hdu 5860 Death Sequence(递推+脑洞)的更多相关文章
- HDU 5860 Death Sequence(递推)
HDU 5860 Death Sequence(递推) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 Description You ...
- HDU 5860 Death Sequence(死亡序列)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 5950 Recursive sequence 递推转矩阵
Recursive sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Other ...
- hdu 5950 Recursive sequence 递推式 矩阵快速幂
题目链接 题意 给定\(c_0,c_1,求c_n(c_0,c_1,n\lt 2^{31})\),递推公式为 \[c_i=c_{i-1}+2c_{i-2}+i^4\] 思路 参考 将递推式改写\[\be ...
- 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...
- HDU 5860 Death Sequence
用线段树可以算出序列.然后o(1)询问. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<c ...
- HDU 2085 核反应堆 --- 简单递推
HDU 2085 核反应堆 /* HDU 2085 核反应堆 --- 简单递推 */ #include <cstdio> ; long long a[N], b[N]; //a表示高能质点 ...
- hdu-5496 Beauty of Sequence(递推)
题目链接: Beauty of Sequence Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java ...
- hdu 2604 Queuing(dp递推)
昨晚搞的第二道矩阵快速幂,一开始我还想直接套个矩阵上去(原谅哥模板题做多了),后来看清楚题意后觉得有点像之前做的数位dp的水题,于是就用数位dp的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...
随机推荐
- Vue的使用总结(2)
1.Vue 中 class 和 style 的绑定 在 Vue 中,可以通过数据绑定来操作元素的 class 列表和内联样式,操作 class 和 style 是用 v-bind 来绑定的.在将 v- ...
- 【BZOJ2555】SubString(后缀自动机,LCT)
题意:给你一个字符串init,要求你支持两个操作 (1):在当前字符串的后面插入一个字符串 (2):询问字符串s在当前字符串中出现了几次?(作为连续子串) 你必须在线支持这些操作. 长度 <= ...
- IGServer for Java
Eclipse和JavaEE: DCServer是哪个? 查看服务器文件夹: Env_Var变量没有定义:JRE_HOME.JDK_HOME 这是Tomcat报错的提示,但是既然JAVA_HOME都有 ...
- [BZOJ3379] Turning in Homework
中文题目:提交作业 原文题目:Turning in Homework 传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=3379 哎,今天竟然没有 ...
- 7 November in 614
每日总结不能少!让自己的头脑好好清醒清醒,才不会犯那些所谓的低级错误! Contest A. ssoj3045 A 先生砍香蕉树 根据数据范围 \(m\le 1000,b\le 10000\),显然本 ...
- codeforces 559D Randomizer
题意简述: 在一个格点图中 给定一个凸$n$边形(每个定点均在格点上),随机选择其中一些点构成一个子多边形, 求子多边形的内部点个数的期望. ----------------------------- ...
- 【HTTP】http请求url参数包含+号,被解析为空格
项目技术:Angular 6 问题现象:接口传参的时候,使用 httpClient.post 方法提交数据,字段中包含+号被解析成空格,提交数据错误 解决过程: 1.http请求中包含+号,会被自动解 ...
- spring aop思想
- c#生成html静态文件时出现空白行,怎么去掉utf-8中的bom
public static void UTF8RemoveBOM(string filepath) { UTF8RemoveBOM(filepath, filepath); } public st ...
- nginx 日志统计接口每个小时访问量
指定时间段增量统计nginx日志不同接口的访问量: #!/bin/bash#此脚本用于统计nginx日志当前时间15分钟之内不同接口(URL)的访问量统计LOG=/usr/local/nginx/lo ...