当前位置:网站首页>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;
}边栏推荐
- After returning to mixlab for three days, "creative team" cured my spiritual internal friction
- iMeta | 国际标准刊号ISSN印刷版正式确认,双ISSN申请完成
- 迪赛智慧数——其他图表(平行坐标图):家庭未来资产配置意愿
- NDK 系列(6):说一下注册 JNI 函数的方式和时机
- The principle and demonstration of service path lifting without quotation marks
- Simple and practical data visualization cases
- NDK series (6): let's talk about the way and time to register JNI functions
- [image defogging] image defogging based on dark channel and non-mean filtering with matlab code
- With double-digit growth in revenue and profit, China Resources Yibao has quietly created these new products worth more than 100 million
- Tita 的OKR系统与其他同类型产品,或者是共享文档等相比,有什么优势?
猜你喜欢

The significance of enterprise digital transformation, digital transformation is not a choice
![[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code](/img/bd/fe105f0af3a24ad6f220fa35bb5e8d.png)
[elm classification] classification of UCI data sets based on nuclear limit learning machine and limit learning machine, with matlab code

Analysis of cloud native application security organization structure

面试官:说一下网络数据传输的具体流程

Safety foundation 2

Trends in software development in 2022

Pyqt5 rapid development and practice 4.10 window drawing controls

【信号处理】基于高阶统计量特征的通信系统中微弱信号检测附matlab代码

用户画像在科技期刊微信公众号精准推送中的应用

20 character short domain name bypass replication
随机推荐
Basic SQL DML
Huawei Hongmeng 3 was officially released, and this security feature has solved a major pain point
网络开发套接字以及UDP、TCP协议
Security-001
Tips and extensions of graph theory
Basic SQL DDL
Object creation process and object layout
What is the b+tree index of MySQL? How does the cluster index grow?
[signal processing] weak signal detection in communication system based on the characteristics of high-order statistics with matlab code
Harmonyos third operation
他山之石 | 蚂蚁超大规模知识图谱构建及应用
51 MCU internal peripherals: real time clock (SPI)
8000 word explanation of OBSA principle and application practice
Dry goods semantic web, Web3.0, Web3, metauniverse, these concepts are still confused? (medium)
怎么使用C# Winform实现复制文件显示进度
Figure basic knowledge code
The wechat installation package has expanded 575 times in 11 years, and the up owner: "98% of the documents are garbage"; Apple App store was exposed to a large number of pornographic apps; Four techn
Blender plug-in of 2022
[number recognition] handwritten number recognition based on knowledge base with matlab code
记录一下使用R语言中关于formatC的错误