1487.txt

来自「自己AC的zju_acm上的若干个题目,都是自己辛辛苦苦AC的。」· 文本 代码 · 共 90 行

TXT
90
字号
#include <iostream.h> 

struct Card 
{ 
   int num; 
   struct Card* next; 
   struct Card* last; 
}; 

struct Card* head = NULL; 
int now = 0; 

int move(int m) 
{ 
   if(now <= 0) 
      return 0; 
   int count = m % now; 
   if(count <= now / 2) 
   { 
      while(count != 0) 
      { 
         head = head->last; 
         count--; 
      } 
   } 
   else 
   { 
      count = now - count; 
      while(count != 0) 
      { 
         head = head->next; 
         count--; 
      } 
   } 
   return 1; 
} 
int add(int number) 
{ 
   struct Card* card = new struct Card; 
   card->num = number; 
   card->last = card->next = NULL; 
   if(now < 0) 
      return 0; 
   else if(now == 0) 
   { 
      now++; 
      head = card; 
      head->next = head; 
      head->last = head; 
      return 1; 
   } 
   card->next = head->next; 
   card->next->last = card; 
   card->last = head; 
   card->last->next = card; 
   now ++; 
   return 1; 
} 
void output() 
{ 
   struct Card* temp = head->next; 
   struct Card* deleted; 
   while(temp != head) 
   { 
      cout << temp->num << ' '; 
      deleted = temp; 
      temp = temp->next; 
      delete deleted; 
   } 
   cout << head->num << endl; 
   delete head; 
} 
int main() 
{ 
   int n,m; 
   while(cin >> n >> m) 
   { 
      int i; 
      head = NULL; 
      now = 0; 
      for(i = n; i >= 1; i--) 
      { 
         add(i); 
         move(m); 
      } 
      output(); 
   } 
   return 1; 
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?