⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1487.txt

📁 自己AC的zju_acm上的若干个题目,都是自己辛辛苦苦AC的。
💻 TXT
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -