当前位置:网站首页>[pointer] solve the last person left
[pointer] solve the last person left
2022-07-06 14:36:00 【|Light|】
requirement
Yes n A circle of individuals , Sequence number . Count from the first person , Where to report 3 Of the people out of the circle , Make up a function , The last thing left is the original number .( Use a pointer to achieve )
Code
/* * This function is used to calculate the last remaining bit * n: The number of people in the enclosure * Return its number */
int last_one(int n)
{
int k=-1;
int i,j,l=0;
int a[n];
for(i=0;i<n;i++)
{
a[i] = 0;
}
for(i=0;i<n-1;i++)
{
for(j=0;j<3;j++)
{
if(a[l]==1)
{
j--;
l++;
if(l==n)
{
l=0;
}
continue;
}
if(j==2)
{
a[l]=1;
}
l++;
if(l==n)
l=0;
}
}
for(i=0;i<n;i++)
{
if(a[i]==0)
{
k = i+1;
break;
}
}
return k;
}
main function
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",last_one(n));
return 0;
}
test
Test input
3
Output
2
边栏推荐
- XSS (cross site scripting attack) for security interview
- Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
- Functions: Finding Roots of equations
- Network technology related topics
- 函数:用牛顿迭代法求方程的根
- Bing Dwen Dwen official NFT blind box will be sold for about 626 yuan each; JD home programmer was sentenced for deleting the library and running away; Laravel 9 officially released | Sifu weekly
- Record an API interface SQL injection practice
- Web vulnerability - File Inclusion Vulnerability of file operation
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
- 内网渗透之内网信息收集(四)
猜你喜欢

1.支付系统

SystemVerilog discusses loop loop structure and built-in loop variable I

JDBC read this article is enough

Network technology related topics

Based on authorized access, cross host, and permission allocation under sqlserver

数据库多表链接的查询方式

Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class

Attack and defense world misc practice area (GIF lift table ext3)

Wu Enda's latest interview! Data centric reasons

Only 40% of the articles are original? Here comes the modification method
随机推荐
数字电路基础(四) 数据分配器、数据选择器和数值比较器
内网渗透之内网信息收集(四)
【指针】求二维数组中最大元素的值
Intel oneapi - opening a new era of heterogeneity
Database monitoring SQL execution
指針:最大值、最小值和平均值
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
Pointeurs: maximum, minimum et moyenne
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
Based on authorized access, cross host, and permission allocation under sqlserver
Network layer - simple ARP disconnection
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
Detailed explanation of network foundation
Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
[pointer] counts the number of times one string appears in another string
List and data frame of R language experiment III
Fire! One day transferred to go engineer, not fire handstand sing Conquest (in serial)
《英特尔 oneAPI—打开异构新纪元》