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的方法去分析,推了好一会总算推出它的递推关系式了(还是菜 ...
随机推荐
- 为你的AliOS Things应用增加自定义cli命令
摘要: 怎么才能在RTOS系统中,通过 串口shell控制LED的开关. 在日常嵌入式开发中,我们经常会用串口命令来使设备进入某种特定的状态,或执行某个特定的操作.如系统自检,模拟运行,或者进入手动模 ...
- 【BZOJ1396】识别子串(后缀自动机,线段树)
题意: 一行,一个由小写字母组成的字符串S,长度不超过10^5 思路:论文题 设p为自动机上的合法结点,r为右端点,len=st[fa[p]]]+1 位置[r-st[p]+1,r-len+1]与r-i ...
- paper 149:Deep Learning 学习笔记(一)
1. 直接上手篇 台湾李宏毅教授写的,<1天搞懂深度学习> slideshare的链接: http://www.slideshare.net/tw_dsconf/ss-62245351? ...
- truncate与delete删除数据的区别
- vue项目git
https://github.com/renrenio/renren-fast-vue https://github.com/hzlshen/vue-project
- css 图片 和 文本 的处理
图片 1.css3已经可以实现 img标签 和 img内图片分开处理的功能了.类似标签的背景图. https://www.zhangxinxu.com/wordpress/2015/03/css3 ...
- [CSP-S模拟测试]:喝喝喝(模拟)
题目描述 奥利维尔和雪拉扎德在喝酒.两人连喝$18$瓶后,奥利维尔最终倒下了.奥利维尔服用了教会研究的醒酒药后,因为服用了太多产生了副作用,第二天睡不着了.他只好用数数的方式度过无聊的时光,不过他毕竟 ...
- leetcode-解题记录 1108. IP 地址无效化
题目: 给你一个有效的 IPv4 地址 address,返回这个 IP 地址的无效化版本. 所谓无效化 IP 地址,其实就是用 "[.]" 代替了每个 ".". ...
- Oracle基础数据类型与运算符
Oracle基础数据类型: 1. 字符型:字符串 char(最大2000), nchar(最大1000, 支持 Unicode)--->固定长 ...
- 为什么学python
一.什么是Python Python [1](英国发音:/ˈpaɪθən/ 美国发音:/ˈpaɪθɑːn/), 是一种面向对象的解释型计算机程序设计语言,由荷兰人Guido van Rossum发明. ...