| ||||||||||
| 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 | |||||||||
求助,我还有哪里没有考虑到呢?为什么wrong answer...Prob.ID 3018#include<stdio.h>
int gift[1000],box[500][1000],count[500];
int partition(int a[],int low,int high)
{
int pivotkey;
pivotkey=a[low];
while(low<high)
{
while((low<high)&&((a[high]>=pivotkey))) high--;
a[low]=a[high];
while((low<high)&&((a[low]<=pivotkey))) low++;
a[high]=a[low];
}
a[low]=pivotkey;
return low;
}
void qsort(int a[],int low,int high)
{
int pivotloc;
if(low<high)
{
pivotloc=partition(a,low,high);
qsort(a,low,pivotloc-1);
qsort(a,pivotloc+1,high);
}
}
void quicksort(int a[],int k)
{
qsort(a,0,k-1);
}
int main()
{
int n,k,i,j,num,temp;
int flag=0;
while(scanf("%d%d",&n,&k)!=EOF)
{
for(i=0;i<k;i++)
{
scanf("%d",&gift[i]);
}
for(i=0;i<n;i++)
for(j=0;j<k;j++)
scanf("%d",&box[i][j]);
quicksort(gift,k);
for(i=0;i<n;i++)
{
quicksort(box[i],k);
}
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
if(box[i][0]<box[j][0])
{
for(num=0;num<k;num++)
{
temp=box[j][num];
box[j][num]=box[i][num];
box[i][num]=temp;
}
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(box[i][j]>gift[j])
count[i]=1;
else count[i]=0;break;
}
}
for(i=0,flag=0;i<n;i++)
{
if(count[i]==1)
for(num=i-1;num>0;num--)
{
if(count[num]==1)
for(j=0,flag=1;j<k;j++)
{
if(box[i][j]<=box[num][j])
{
flag=0;
break;
}
}
if(flag==1)
{
count[i]+=count[num];
break;
}
}
}
int max=count[0];
for(i=1;i<n;i++)
{
if(max<count[i])
{
max=count[i];
}
}
if(max!=0)
printf("%d\n",max);
else printf("Please look for another gift shop!\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator