当前位置:网站首页>[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
边栏推荐
- 指針:最大值、最小值和平均值
- Pointers: maximum, minimum, and average
- MySQL interview questions (4)
- Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
- MySQL learning notes (stage 1)
- flask实现强制登陆
- [pointer] use the insertion sorting method to arrange n numbers from small to large
- JVM memory model concept
- High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
- Always of SystemVerilog usage_ comb 、always_ iff
猜你喜欢
Hackmyvm target series (1) -webmaster
四元数---基本概念(转载)
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
《统计学》第八版贾俊平第二章课后习题及答案总结
Uibutton status exploration and customization
5分钟掌握机器学习鸢尾花逻辑回归分类
内网渗透之内网信息收集(三)
On the idea of vulnerability discovery
ES全文索引
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
随机推荐
四元数---基本概念(转载)
Data mining - a discussion on sample imbalance in classification problems
Sentinel overall workflow
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
[pointer] use the insertion sorting method to arrange n numbers from small to large
Intranet information collection of Intranet penetration (3)
数字电路基础(二)逻辑代数
Network technology related topics
Pointers: maximum, minimum, and average
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
指针:最大值、最小值和平均值
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
Intranet information collection of Intranet penetration (4)
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
Attack and defense world misc practice area (GIF lift table ext3)
Function: find the root of the equation by Newton iterative method
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
{1,2,3,2,5}查重问题
线程的实现方式总结
Numpy Quick Start Guide