当前位置:网站首页>ZCMU--1720: 死亡如风,我要装逼
ZCMU--1720: 死亡如风,我要装逼
2022-07-27 20:38:00 【小小小Why】
Description
死亡如风,我要装逼——哈撒给!!!大家好,我叫张全蛋,刚从qd旅游回来。然后。。。穷的连衣服都被人扒了。因为我当时点了一道海鲜。帝企鹅,the king of QQ 。其实当时还有许多和我一起去的游客也都被****。店主非常残忍。让我们n个人围成一个圈,每个人一个编号1,2,3...n.第一次从1开始数到(2^1)次辣个人就会被****,接下来从被****的下一个人重新开始计数,数到(2^2)次的辣个人就会被****.以此类推,第i次将会是数到第(2^i)次的人被****.最后的2个人可以幸免于难。然后我就这样回来了。
Input
多组测试数据
输入一个数n(2<=n<=10000)
Output
输出最后两个人的号码,a,b(a<b)。
Sample Input
2
3
Sample Output
1 2
1 3
解析:用vector十分方便,因为erase可以直接删淘汰人的位置,留下来的数组中都是活着的,然后每次只要通过等式就可以直接找到下一个要淘汰的人的下标。至于题目中的(2^i)得用快速幂来计算,计算的同时取模的数其实就是场上活着的人数。
#include <stdio.h>
#include <vector>
using namespace std;
vector<int> v;
int k;
int qm(int b,int p){
int r=1,l=v.size(); //l是场上人数
while(p){
if(p%2==1) r=r*b%l;
b=b*b%l;
p/=2;
}
if(r+k-1<0) return v.size()-1;//特判一下,这种淘汰的刚好是最后一个人
return (r+k-1)%l;
}
int main()
{
int n,i,p;
while(~scanf("%d",&n)){
v.erase(v.begin(),v.end()); //初始化情况
for(i=1;i<=n;i++) v.push_back(i);//输入人物编号
i=1,k=0;
while(v.size()>2){
p=qm(2,i);
k=p; //特别注意:从下一个人开始报数,也就是场上第k个人
v.erase(v.begin()+p);
i++;
}
printf("%d %d\n",v[0],v[1]);
}
return 0;
}边栏推荐
- 【数字识别】基于知识库实现手写体数字识别附matlab代码
- [CVA valuation training camp] how to quickly read the annual reports of listed companies - Lesson 4
- Library management system based on SSM framework
- 【ELM分类】基于核极限学习机和极限学习机实现UCI数据集分类附matlab代码
- Safety Fundamentals 1
- Cron expression
- Lanproxy映射本地开发环境
- [GNN report] Tang Jian, Montreal, Canada: Geometric deep learning for drug discovery
- [number recognition] handwritten number recognition based on knowledge base with matlab code
- Pyqt5 rapid development and practice 4.10 window drawing controls
猜你喜欢

What is the b+tree index of MySQL? How does the cluster index grow?

AWS DynamoDB运用技巧

Exercise --- BFS

On data management of data warehouse

MySQL basic installation and startup

Cron expression
![[image defogging] image defogging based on dark channel and non-mean filtering with matlab code](/img/44/6120682f9571f6ad35f8b9249b7fea.png)
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code
![[soft test software evaluator] 2014 comprehensive knowledge over the years](/img/85/46c8fc696ae5249a9aca22b50493f0.jpg)
[soft test software evaluator] 2014 comprehensive knowledge over the years
![[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code](/img/6a/92ace81b798810299a2fec0ce6ae70.png)
[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code

Pyqt5 rapid development and practice 4.10 window drawing controls
随机推荐
毕设-基于SSM高校后勤管理系统
寻找和利用 XXE – XML 外部实体注入
[stonedb fault diagnosis] database instance crash
Trends in software development in 2022
Arm32 for remote debugging
Containerd CTR run the ansible container and execute the complete command of ansible playbook task
Lanproxy映射本地开发环境
Basic lighting of unity
Cloud native enthusiast weekly: a complete collection of client go examples
【数字识别】基于Hopfield神经网络识别0-9数字附Matlab代码
Nature综述:微生物群落形成过程中的优先效应
[GNN report] Tang Jian, Montreal, Canada: Geometric deep learning for drug discovery
360 was selected into the panorama of China's security industry, and isc2022 talked about the direction of security services in 63 fields
How do I shut down oracle?
Analysis of cloud native application security organization structure
8000 word explanation of OBSA principle and application practice
NDK 系列(6):说一下注册 JNI 函数的方式和时机
Desai wisdom number - other charts (parallel coordinate chart): family's willingness to allocate assets in the future
八大排序之冒泡、快排、堆排、基数排序
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code