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的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...
随机推荐
- C#操作xml完整类文件
C#操作xml完整类文件 xml_oper.cs using ...System; using System.Data; using System.Web; using System.Xml; /** ...
- LOJ 6436 「PKUSC2018」神仙的游戏——思路+卷积
题目:https://loj.ac/problem/6436 看题解才会. 有长为 i 的 border ,就是有长为 n-i 的循环节. 考虑如果 x 位置上是 0 . y 位置上是 1 ,那么长度 ...
- 暑期训练 CF套题
CodeForces 327A 题意:有n个数,都是0或1,然后必须执行一次操作,翻转一个区间,里面的数0变1,1变0,求最多1的数量 思路:最开始我写的最大字段和,后面好像写搓了,然后我又改成暴力, ...
- SQLmap注入
一.安装 先安装Python2.7 下载SQLmap:http://sqlmap.org/ 下载文件解压到Python文件目录下 然后设置环境变量:D:\Python27\sqlmap 在cmd查看是 ...
- oracle函数自治事务解决不能增改删的语句操作
CREATE OR REPLACE FUNCTION SEQ3 (v_bname in VARCHAR2) return NUMBER is pragma autonomous_transaction ...
- 【GDAL】聊聊GDAL的数据模型
GDAL是个非常优秀的GIS数据操作库,最近在和实习生介绍GDAL的简单使用,顺手写下记录 本篇记录栅格数据,代码环境为C# 在GDAL中,栅格数据大致是以一个Dataset对应一个栅格数据文件(.T ...
- 练习1-20 编写程序detab,将输入中的制表符替换成适当数目的空格.
1.问题描述 编写程序detab,将输入中的制表符替换成适当数目的空格,使空格充满到下一个制表符终止位的地方. 假设制表符终止位的位置是固定的, 换句话说每隔n列就会出现一个制表符终止位. 2.描述 ...
- 如何设置Windows操作系统打印机与xlpd连接
Xlpd是Xmanager中负责远程打印的软件,除了打印远程文件,它还具备很多功能,本集将具体讲解Xlpd的主要功能. 主要功能如下: 1. 支持LPD协议(RFC1179) 在RFC1179中定义 ...
- <转>Excel生成guid、uuid
Excel生成guid.uuid 原文地址:https://www.cnblogs.com/jory/p/7718305.html 1.Excel生成guid,uuid 格式:600d65bc- ...
- Selenium:多表单(frame/iframe)切换(Switch模块)
frame标签有frameset.frame.iframe三种,frameset跟其他普通标签没有区别,不会影响到正常的定位,而frame与iframe需要切换进去才能定位到其中的元素 比如下面这个网 ...