标签:
1 9 1 5
5 1 7 4 3 6 9 2 8 8 win.
#include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> using namespace std; typedef struct link{ int num; struct link *next; }IA; IA *Create(); void *Delete(IA *head); int n,m,s; int main() { IA *head = NULL,*tail = NULL; int T; scanf("%d",&T); while(T--){ scanf("%d%d%d",&n,&s,&m); tail = Create(); Delete(tail); } return 0; } IA *Create() { IA *tail ,*head = NULL,*p; tail = head; int i = 1; while(i<=n){ p = (IA*)malloc(sizeof(IA)); p->num = i; if(head ==NULL){ head = p; tail = p; tail->next = NULL; } else { tail->next =p; p->next =NULL; tail = p; } i++; } tail->next = head; return tail; } void *Delete(IA *tail) { IA * ptr1,*ptr2; int cnt = 0,hui = 0,i = 1; if(tail->next ==NULL) return 0; ptr1 = tail; ptr2 = tail->next; while(i!=s) { ptr1 = ptr2; ptr2 = ptr2->next;; i++; } while(hui!=n - 1){ cnt++; if(cnt == m){ printf("%d ",ptr2->num); ptr1 ->next =ptr2->next; free(ptr2); cnt = 0; hui++; } else ptr1 = ptr2; ptr2 = ptr1->next; } printf("%d\n%d win",ptr1->num,ptr1->num); }
磕磕盼盼能自己写出来了orz
标签:
原文地址:http://www.cnblogs.com/zero-begin/p/4332238.html