当前位置:网站首页>Zcmu--1720: death is like the wind, I want to pretend to force
Zcmu--1720: death is like the wind, I want to pretend to force
2022-07-27 23:49:00 【Little why】
Description
The wind of death , I want to pretend to force —— Hassa gave !!! Hello everyone , My name is Zhang quandan , Just from qd Travel back . then ... Poor people even got their clothes picked . Because I ordered a seafood . emperor penguin ,the king of QQ . In fact, many tourists who went with me were also ****. The shopkeeper is very cruel . Let us n A circle of individuals , Each person has a number 1,2,3...n. First time from 1 Start counting to (2^1) The second spicy person will be ****, Next, from being **** The next person starts counting again , Count to (2^2) The second spicy person will be ****. And so on , The first i Times will be counted to (2^i) The second person was ****. final 2 Individuals can survive . Then I came back like this .
Input
Multiple sets of test data
Enter a number n(2<=n<=10000)
Output
Output the numbers of the last two people ,a,b(a<b).
Sample Input
2
3
Sample Output
1 2
1 3
analysis : use vector It is very convenient , because erase You can directly delete the position of the eliminated person , All the remaining arrays are alive , Then every time you just pass the equation, you can directly find the subscript of the next person to be eliminated . As for the question (2^i) We have to use the fast power to calculate , The number of modulos taken while calculating is actually the number of people alive on the field .
#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 It's the number of people on the court
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;// It's a special verdict , This kind of elimination happens to be the last person
return (r+k-1)%l;
}
int main()
{
int n,i,p;
while(~scanf("%d",&n)){
v.erase(v.begin(),v.end()); // Initialization situation
for(i=1;i<=n;i++) v.push_back(i);// Enter the person number
i=1,k=0;
while(v.size()>2){
p=qm(2,i);
k=p; // Particular attention : Count off from the next person , That is, the first on the court k personal
v.erase(v.begin()+p);
i++;
}
printf("%d %d\n",v[0],v[1]);
}
return 0;
}边栏推荐
- Solve 5g pain points, Meizu 17 smart 5g fast and stable technology release
- My annual salary is 1million, and I don't have clothes more than 100 yuan all over my body: saving money is the top self-discipline
- [GWCTF 2019]BabyRSA1
- 日产1500万只!比亚迪口罩拿下美国加州10亿美元订单
- Character stream learning 14.3
- Lua basic grammar learning
- Redis hash underlying data structure
- Why do I need to wait for 2msl?
- 钉钉报警工具
- [RoarCTF2019]RSA
猜你喜欢

2022 summer vacation daily question (5)

C # delegate usage -- console project, which implements events through delegation

【JS 逆向百例】某公共资源交易网,公告 URL 参数逆向分析

西门子PLC能否实时无线采集多处从站模拟量数据?

TOGAF10标准读书会首场活动圆满举办,精彩时刻回顾!

Interviewer: let's talk about the specific process of network data transmission

Technical certification | Tupo software and Huawei cloud create a new situation of win-win cooperation
![[RoarCTF2019]babyRSA威尔逊定理](/img/c1/52e79b6e40390374d48783725311ba.gif)
[RoarCTF2019]babyRSA威尔逊定理

File&递归14.1

Bank Marketing预测一个客户购买理财产品的成功率
随机推荐
台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
Can Siemens PLC collect analog data of multiple slave stations in real time and wirelessly?
Yijia will release ODM orders in 2020 and make efforts in the middle and low-end market
[RoarCTF2019]babyRSA威尔逊定理
[ACTF新生赛2020]crypto-aes
smartRefresh嵌套多个RecycleView滑动冲突及布局显示不全
7.6万人停工!东芝宣布关闭日本所有工厂
Unity 实现简单画板画画功能(笔记)
How to use xshell Free Edition
Error:svn: E155010: ‘/Users/.../Desktop/wrokspace/xxx‘ is scheduled for addition, but is missing
Arm32 for remote debugging
JS提升:JS中的数组扁平化问题
Features of hardwired controller:
[C language] address book (dynamic version)
BUUCTF-Dangerous RSA
硬布线控制器的特点:
Zabbix4.0使用SNMP代理方式监控vcenter6.5
Is it really hard to understand? What level of cache is the recyclerview caching mechanism?
76000 people shut down! Toshiba announced the closure of all factories in Japan
29. Learn the stacked column chart of highcharts using percentage