poj 3750 小孩报数问题
2015-02-04 17:04
375 查看
原题:http://poj.org/problem?id=3750
没啥好说的注意报数间隔为1的情况。
没啥好说的注意报数间隔为1的情况。
#include <stdio.h> #include <stdlib.h> #include <string.h> typedef char State[16]; typedef struct node { State name; struct node *pNext; }Node,*pNode; pNode AddNewNode(char *name) { pNode NewNode=(pNode)malloc(sizeof(Node)); strcpy(NewNode->name,name); NewNode->pNext=NULL; return NewNode; } void Init(pNode *pHead,char *name) { if(*pHead==NULL) *pHead=AddNewNode(name); else { pNode p=*pHead; while(p->pNext!=NULL) p=p->pNext; p->pNext=AddNewNode(name); } } void solve(pNode pHead,int w,int s) { int i,count=1; pNode p=pHead,start=pHead; while(p->pNext!=NULL) p=p->pNext; p->pNext=pHead; while(count++ < w) start=start->pNext; p=start; if(1 == s) { printf("%s\n",start->name); p=start->pNext; start->pNext=NULL; while(p->pNext!=NULL) { printf("%s\n",p->name); p=p->pNext; } return; } while(p->pNext!=p) { pNode p1=NULL; for(i=1;i < s - 1;i++) p=p->pNext; p1=p->pNext; p->pNext=p1->pNext; p=p1->pNext; printf("%s\n",p1->name); free(p1); } printf("%s\n",p->name); } int main() { #ifdef LOCAL freopen("input.txt","r",stdin); #endif int t=0,w=0,s=0; State buf; pNode Head=NULL; scanf("%d",&t); while(t--) { scanf("%s",buf); Init(&Head,buf); } scanf("%d,%d",&w,&s); solve(Head,w,s); return 0; }
相关文章推荐
- 【原】 POJ 3750 小孩报数问题 Joseph相关问题详解 解题报告
- POJ:题号3750----小孩报数问题
- poj 3750 小孩报数问题 解题报告
- POJ 3750 小孩报数问题 模拟约瑟夫环
- poj 3750 小孩报数问题(线段树-单点更新)
- POJ 3750 小孩报数问题(模拟/数据结构—循环链表)
- POJ 3750 小孩报数问题
- poj 3750 小孩报数问题(循环链表)
- poj 3750 小孩报数问题
- poj 3750 小孩报数问题
- 约瑟夫环 poj 3750 小孩报数问题 模拟
- POJ 3750 小孩报数问题 (线性表思想 约瑟夫问题 数组模拟运算的 没用循环链表,控制好下标的指向就很容易了)
- POJ 3750 小孩报数问题
- POJ 3750 小孩报数问题
- POJ 3750 小孩报数问题
- poj 3750 小孩报数问题
- poj 3750 小孩报数问题 约瑟夫问题
- (顺序表应用5.1.1)POJ 3750 小孩报数问题(基本的约瑟夫环问题:给出人数n,出发位置w,间隔数s)
- POJ 3750 小孩报数问题
- Poj 3750 小孩报数问题