Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我用HASH过了,不懂为什么用排序就过不了呢!总是WA!!求大神指点#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator