标签:hdu1276
2 20 40
1 7 19 1 19 37
#include <stdio.h>
#include <string.h>
bool arr[5002];
int n, ans;
int getNext(int i){
while(arr[i] == 0 && i <= n) ++i;
return i;
}
void cal2(){
if(ans <= 3) return;
for(int pos = 0; pos <= n; ){
pos = getNext(pos + 1);
if(pos > n) return;
pos = getNext(pos + 1);
if(pos > n) return;
arr[pos] = 0;
--ans;
}
}
void cal3(){
if(ans <= 3) return;
for(int pos = 0; pos <= n; ){
pos = getNext(pos + 1);
if(pos > n) return;
pos = getNext(pos + 1);
if(pos > n) return;
pos = getNext(pos + 1);
if(pos > n) return;
arr[pos] = 0;
--ans;
}
}
int main(){
int t, flag;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
ans = n;
for(int i = 1; i <= n; ++i)
arr[i] = 1;
while(ans > 3){
cal2();
cal3();
}
flag = 0;
for(int i = 0; ;){
i = getNext(i + 1);
if(i > n) break;
if(flag == 0) flag = 1, printf("%d", i);
else printf(" %d", i);
}
printf("\n");
}
return 0;
}HDU1276 士兵队列训练问题,布布扣,bubuko.com
标签:hdu1276
原文地址:http://blog.csdn.net/u012846486/article/details/27836737