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

呼呼~~~~第一次用类写程序,好像蛮爽的

Posted by yzhw at 2009-01-13 15:26:39 on Problem 1029
# include <iostream>
using namespace std;
bool use[1001];
class pretest
{
      private:
          int l[501];
          int r[501];
      public:
          int num;
          void add(int left[],int right[],int len);
          bool find(bool sel,int flag);
};
class test
{
      private:
          pretest data[101];
          int point;
          bool isin(bool sel,int flag);
          bool isnotin(bool sel,int flag);
      public:
          test();
          void add(int left[],int right[],int len);
          int judge(int n);
};
//*******************************************************************************
void pretest::add(int left[],int right[],int len)
{
     for(int i=1;i<=len;i++)
     {
      l[i]=left[i];
      r[i]=right[i];
     }
     num=len;
}
bool pretest::find(bool sel,int flag)
{
     if(!sel)
     {
      for(int i=1;i<=num;i++)
        if(l[i]==flag) return 1;
      return 0;
     }
     else
     {
       for(int i=1;i<=num;i++)
         if(r[i]==flag) return 1;
       return 0;
     }
}
      
//******************************************************************************
test::test()
{
     point=0;
}
void test::add(int left[],int right[],int len)
{
     data[++point].add(left,right,len);
}
bool test::isin(bool sel,int flag)
{
     for(int i=1;i<=point;i++)
     {
             if(!data[i].find(sel,flag)) return 0;
     }
     return 1;
}
bool test::isnotin(bool sel,int flag)
{
     for(int i=1;i<=point;i++)
     {
             if(data[i].find(sel,flag)) return 0;
     }
     return 1;
}
int test::judge(int n)
{
    for(int i=1;i<=n;i++)
    {
     if(use[i])
     {
      if((isin(0,i)&&isnotin(1,i))||(isin(1,i)&&isnotin(0,i))) continue;
      else use[i]=0;
     }
    }
    int last=0;
    for(int i=1;i<=n;i++)
    {
     if(use[i])
     {
      if(!last) last=i;
      else return 0;
     }
    }
    return last;
}
int main()
{
    int data_num,test_num;
    test mydata;
    cin>>data_num>>test_num;
    for(int i=1;i<=data_num;i++) use[i]=1;
    for(int i=1;i<=test_num;i++)
    {
       int num;
       int t1[501],t2[501];
       char equal;
       cin>>num;
       for(int j=1;j<=num;j++) cin>>t1[j];
       for(int j=1;j<=num;j++) cin>>t2[j];
       cin>>equal;
       if(equal=='=')
       {
        for(int j=1;j<=num;j++)
        {
         use[t1[j]]=0;
         use[t2[j]]=0;
        }
       }
       else if(equal=='<') mydata.add(t1,t2,num);
       else mydata.add(t2,t1,num);
      
    }
     cout<<mydata.judge(data_num)<<endl;
    system("pause");
    return 0;
}
                 

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