网站的首页怎么做,中山快速做网站价格,重庆网上房地产网签合同查询,凡科建站模板Problem Description 说到“敢死队”#xff0c;大家不要以为我来介绍电影了#xff0c;因为数据结构里真有这么道程序设计题目#xff0c;原题如下#xff1a; 有M个敢死队员要炸掉敌人的一个碉堡#xff0c;谁都不想去#xff0c;排长决定用轮回数数的办法来决定哪个战…Problem Description 说到“敢死队”大家不要以为我来介绍电影了因为数据结构里真有这么道程序设计题目原题如下 有M个敢死队员要炸掉敌人的一个碉堡谁都不想去排长决定用轮回数数的办法来决定哪个战士去执行任务。如果前一个战士没完成任务则要再派一个战士上去。现给每个战士编一个号大家围坐成一圈随便从某一个战士开始计数当数到5时对应的战士就去执行任务且此战士不再参加下一轮计数。如果此战士没完成任务再从下一个战士开始数数被数到第5时此战士接着去执行任务。以此类推直到任务完成为止。 这题本来就叫“敢死队”。“谁都不想去”就这一句我觉得这个问题也只能叫“不敢死队问题”。今天大家就要完成这道不敢死队问题。我们假设排长是1号按照上面介绍从一号开始数数到5的那名战士去执行任务那么排长是第几个去执行任务的 Input 输入包括多试数据每行一个整数M0M10000)敢死队人数若M0输入结束不做处理。 Output 输出一个整数n代表排长是第n个去执行任务。 Example Input 9 6 223 0 Example Output 2 6 132 #include stdio.h
#include stdlib.h
struct die
{int num;struct die *next;
}*p,*head,*tail,*q;
struct die *creat(int n)
{int i;p(struct die *)malloc(sizeof(struct die));p-num1;p-nextNULL;headp;tailp;for(i2;in;i){p(struct die *)malloc(sizeof(struct die));p-numi;tail-nextp;tailp;p-nextNULL;}tail-nexthead;return head;
}
int sel(struct die *head,int n)
{int num0;int count0;qhead;while(q-next!head){qq-next;}while(q-num!1){pq-next;num;if(num%50){q-nextp-next;// printf(%d,p-num);free(p);count;}elseqp;}return count;
}
int main()
{int n,m,g;while(~scanf(%d,n)n){headcreat(n);gsel(head,n);printf(%d\n,g);}
}
#include stdio.h
#include stdlib.h
struct node
{
int num;
struct node *next;
}*head,*tail,*p,*q;
void die(int n)
{
int i,count,s;
head(struct node *)malloc(sizeof(struct node));
head-nextNULL;
head-num1;
tailhead;
for(i2;in;i)
{
p(struct node *)malloc(sizeof(struct node));
p-nextNULL;
p-numi;
tail-nextp;
tailp;
//tail-nextNULL;
}
tail-nexthead;
qhead;
s1;count1;
while(q-num!q-next-num)
{
for(i1;i4;i)
{
qq-next;
}
if(q-next-num!1)
{
q-nextq-next-next;
qq-next;
count;
}
else
{
printf(%d\n,count);
s0;
break;
}
}
if(s1)
printf(%d\n,n);
}
int main()
{
int n;
while(~scanf(%d,n)n)
{
die(n);
}
return 0;
}