WA了无数次..最终搞懂题意..然后修改代码= =
思路很简单的...自己基础薄0 0
丑陋代码贴上= =
#include#include #define MALLOC (STU*)malloc(sizeof(STU)) int m1, m2, n; typedef struct person{ struct person *pre, *next; int lis; }STU; void _delete(struct person *node) { node->pre->next = node->next; node->next->pre = node->pre; free(node); } int main() { int i; STU *head = MALLOC, *temp, *_pre; scanf("%d%d%d", &n, &m1, &m2); head->lis = 1; _pre = head; for(i = 2; i <= n; i++)//temp为当前申请结点,_pre为前一个结点,结束之后_pre当尾结点用. { temp = MALLOC; temp->pre = _pre; temp->lis = i; _pre->next = temp; _pre = temp; } //链接首尾 temp = head->pre = _pre; _pre->next = head; while(n > 2)//只剩下一个结点结束 { for(i = 0; i < m1; i++) temp = temp->next; _pre = temp->next; //存放删除结点 _delete(temp); temp = _pre; if(temp == temp->next) break; for(i = 0; i < m2; i++) temp = temp->pre; if(_pre == temp) { _pre = temp->pre; _delete(temp); temp = _pre; n -= 1; continue; } _pre = temp->pre; _delete(temp); temp = _pre; n -= 2; } printf("%d\n", temp->lis); return 0; }