HUST Online Judge WebBoard
Problem 3982 >> 答案错误
201803140220 @ 2019-04-07 20:41:32
[ Quote ] [ Edit ] [ Delete ] 1#
#include<stdio.h>

int main()
{
int n;
int i,k,t,p,a[1000];

scanf("%d",&n);

if(n<=2)
{
printf("1\n");
}

for(i=0;i<n;i++)
a[i]=i+1;

t=n;
while(t>2)
{
k=0;
for(i=0;i<n;i++)
if(a[i]!=0)
{
k++;
if(k==3)
{
k=0;
a[i]=0;
t--;
}
if(t==2)
p=1;
}

if(p==1)
break;

k=0;
for(i=n-1;i>=0;i--)
if(a[i]!=0)
{
k++;
if(k==3)
{
k=0;
a[i]=0;
t--;
}
if(t==2)
p=2;
}

if(p==2)
break;
}

if(p==2)
{
for(i=0;i<n;i++)
if(a[i]!=0)
{
printf("%d\n",a[i]);
break;
}
}
if(p==1)
{
for(i=n-1;i>=0;i--)
if(a[i]!=0)
{
printf("%d\n",a[i]);
break;
}
}

return 0;
}