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

我用HASH过了,不懂为什么用排序就过不了呢!总是WA!!求大神指点

Posted by yzzhang1988 at 2010-05-10 23:31:43 on Problem 2028
#include <iostream>
#include <algorithm>


using namespace std;
int num[5000];

int main()
{
    int n,q;
    while(scanf("%d%d",&n,&q),n!=0||q!=0)
    {
        int tem=0;
       for(int i=0;i<n;i++)
       {
           int k;
           scanf("%d",&k);
           for(int j=0;j<k;j++)
           {
               cin>>num[tem];
               tem++;
           }
       }
       sort(num,num+tem);
       int a[2]={0};
       int sum=1;
       for(int i=0;i<tem-1;i++)
       {
           if(num[i]==num[i+1])
           {
               sum++;
           }
           else{

               if(num[i]!=0&&sum>=q&&sum>a[0])
               {

                   a[1]=num[i];
                   a[0]=sum;
               }
               sum=1;
           }
       }
       if(sum>=q&&sum>a[0])
       {

            a[1]=num[tem-1];
            a[0]=sum;
       }
       printf("%d\n",a[1]);



    }
    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