| ||||||||||
| 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 | |||||||||
贪心为什么会错???下是错误的代码,指点一下吧。。。#include<iostream>
#include<string.h>
struct room
{
int beg;
int end;
} s[201];
int hash[201];
int cmp( const void *a ,const void *b)
{
return (*(room *)a).end > (*(room *)b).end ? 1 : -1;
}
int main()
{
bool lab;
int nCase,N,ans;
int i,j,a,b;
scanf("%d",&nCase);
while(nCase -- )
{
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%d%d",&a,&b);
if(a%2 == 1) a++;
if(b%2 == 1) b++;
a/=2;b/=2;
s[i].beg=a<b?a:b;
s[i].end=a>b?a:b;
}
qsort(s,N,sizeof(s[0]),cmp);
memset(hash,0,sizeof(hash));
ans=0;
int begi;
while(true)
{
lab=false;
for(j=0;j<N;j++)
{
if(hash[j] == 0)
{
begi=j;
hash[j]=1;
lab=true;
ans++;
break;
}
}
if(lab == false) break;
for(j=begi+1;j<N;j++)
{
if(s[j].beg>s[begi].end)
{
hash[j]=1;
begi=j;
}
}
}
printf("%d\n",ans*10);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator