当前位置:网站首页>[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
边栏推荐
- 关于超星脚本出现乱码问题
- AQS details
- Hackmyvm target series (2) -warrior
- Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
- What language should I learn from zero foundation. Suggestions
- Always of SystemVerilog usage_ comb 、always_ iff
- Pointeurs: maximum, minimum et moyenne
- Intranet information collection of Intranet penetration (4)
- 函数:求两个正数的最大公约数和最小公倍
- JDBC read this article is enough
猜你喜欢

数字电路基础(三)编码器和译码器

《统计学》第八版贾俊平第七章知识点总结及课后习题答案

JDBC read this article is enough

关于超星脚本出现乱码问题

Internet Management (Information Collection)

Lintcode logo queries the two nearest saplings

Database monitoring SQL execution

内网渗透之内网信息收集(四)

Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class

Markdown font color editing teaching
随机推荐
Detailed explanation of network foundation
C language file operation
Function: calculates the number of uppercase letters in a string
“人生若只如初见”——RISC-V
The difference between layer 3 switch and router
Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
Network layer - simple ARP disconnection
函数:求1-1/2+1/3-1/4+1/5-1/6+1/7-…+1/n
Low income from doing we media? 90% of people make mistakes in these three points
MySQL learning notes (stage 1)
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
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
指针 --按字符串相反次序输出其中的所有字符
flask实现强制登陆
New version of postman flows [introductory teaching chapter 01 send request]
Internet Management (Information Collection)
《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
This article explains in detail how mockmvc is used in practical work
Record once, modify password logic vulnerability actual combat
Solutions to common problems in database development such as MySQL