当前位置:网站首页>[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
边栏推荐
- Windows platform mongodb database installation
- 《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
- 《统计学》第八版贾俊平第三章课后习题及答案总结
- 图书管理系统
- 指針:最大值、最小值和平均值
- 关于交换a和b的值的四种方法
- 数字电路基础(二)逻辑代数
- Attack and defense world misc practice area (GIF lift table ext3)
- JDBC read this article is enough
- Record once, modify password logic vulnerability actual combat
猜你喜欢
JDBC read this article is enough
Applet Web Capture -fiddler
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
Library management system
Markdown font color editing teaching
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
Realize applet payment function with applet cloud development (including source code)
随机推荐
线程的实现方式总结
《统计学》第八版贾俊平第二章课后习题及答案总结
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
Detailed explanation of network foundation routing
Numpy快速上手指南
Intranet information collection of Intranet penetration (4)
JDBC看这篇就够了
Sentinel overall workflow
“Hello IC World”
Intranet information collection of Intranet penetration (5)
. Net6: develop modern 3D industrial software based on WPF (2)
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
《统计学》第八版贾俊平第三章课后习题及答案总结
Web vulnerability - File Inclusion Vulnerability of file operation
Realize applet payment function with applet cloud development (including source code)
我的第一篇博客
关于交换a和b的值的四种方法
内网渗透之内网信息收集(三)
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated