标签:while tle int log tor 模拟题 str ane i++
原题代号:HDU 1276
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1276
题目原题:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8914 Accepted Submission(s):
3940
# include <stdio.h> # include <string.h> # include <stdlib.h> # include <iostream> # include <fstream> # include <vector> # include <queue> # include <stack> # include <map> # include <math.h> # include <algorithm> using namespace std; # define pi acos(-1.0) # define mem(a,b) memset(a,b,sizeof(a)) # define FOR(i,a,n) for(int i=a; i<=n; ++i) # define For(i,n,a) for(int i=n; i>=a; --i) # define FO(i,a,n) for(int i=a; i<n; ++i) # define Fo(i,n,a) for(int i=n; i>a ;--i) typedef long long LL; typedef unsigned long long ULL; int a[5005]; int main() { int t,n; cin>>t; while(t--) { cin>>n; for(int i=1; i<=n; i++)a[i]=1; if(n<=3) { if(n==1)cout<<1<<endl; else if(n==2)cout<<"1 2"<<endl; else if(n==3)cout<<"1 2 3"<<endl; } else { int sum=n; int flag=1; while(sum>3) { int s=0; if(flag%2)///报2的出列 { for(int i=1; i<=n; i++) { if(a[i]) { s++; if(s%2==0)a[i]=0,sum--; } } flag=!flag; } else///报3的出列 { for(int i=1; i<=n; i++) { if(a[i]) { s++; if(s%3==0)a[i]=0,sum--; } } flag=!flag; } } for(int i=1; i<=n; i++) if(a[i]==1)printf(i==1?"%d":" %d",i); cout<<endl; } } return 0; }
标签:while tle int log tor 模拟题 str ane i++
原文地址:http://www.cnblogs.com/teble/p/7197225.html