Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

不知道这样构造行不行 请求高人指点 WA

Posted by yzg_1984 at 2005-01-14 15:23:40 on Problem 1672
#include <iostream>
#include <string>
int flag[100000],solution[100000];
using namespace std;
int n;
int cal(int m){
   int cnt=m;
   int i;
   for(i=1;i<=n;i++){
      if(flag[i]<i){
         solution[1]=i;
         break;
      }
   }
   for(int j=n;j>i;j--){
      if(flag[j]<j){
         solution[cnt--]=j;
         if(cnt==1)  return 1;
      }
   }
   return 0;
}
void print(int m){
   for(int i=1;i<=m;i++){
      if(i!=1)  cout<<' ';
      cout<<solution[i];
      flag[solution[i]]++;
   }
   cout<<endl;
   return ;
}
int main(){  
   int m;
   int ans=0;
   while(cin>>n&&n){
      int total=(1+n)*n/2;
      if(total%2)  {
         if(ans)  cout<<endl;
         else  ans=1;
         cout<<0<<endl;
         continue;
      }
      else{
         memset(flag+1,0,sizeof(int)*n);
         if(ans)  cout<<endl;
         else  ans=1;
         cout<<n<<endl;
         if(n%2)  m=n-1;
         else m=n; 
         int cnt=0; 
         while(cnt<total){
            if(cal(m)){
               print(m);
               cnt+=m;
            }
            else m-=2;
            if(m<2)  break;
         }
      }
   }
   return 1; 
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator