HDU 1276

题意:和韩信点兵差不多,不过这个要求更高一些。

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main(){
 4     int N;cin>>N;
 5     while(N--)
 6     {
 7         queue<int>q;
 8         int n;cin>>n;
 9         for(int i=1;i<=n;++i)
10         {
11             q.push(i);
12         }
13         int cnt = 0;
14         while(q.size()>3)
15         {
16             cnt++;
17             int len = q.size();
18             if(cnt%2==1)
19             {
20                 for(int i = 1;i<=len;++i)
21                 {
22                     if(i%2)
23                     {
24                         int t = q.front();
25                         q.push(t);
26                     }
27                     q.pop();
28                 }
29             }else
30             {
31                 for(int i = 1;i<=len;++i)
32                 {
33                     if(i%3)
34                     {
35                         int t = q.front();
36                         q.push(t);
37                     }
38                     q.pop();
39                 }
40             }
41         }
42         cout<<q.front();
43         q.pop();
44         while(!q.empty())
45         {
46             cout<<" "<<q.front();
47             q.pop();
48         }
49         cout<<endl;
50     }
51     return 0;
52 }

 

posted @ 2019-02-22 17:03  鹤花之歌  阅读(126)  评论(0编辑  收藏  举报