水贪心~~就因为写错了swap(),wa了!坑爹! 今天彻底没状态啊!!被各种事情搞得头昏眼花!哭~~~
以后交换都用swap() !不然继续坑爹!
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
struct Node
{
int r1;
int r2;
}node[210];
bool cot[210];
int cmp(const void *a,const void *b)
{
if((*(Node *)a).r1 != (*(Node *)b).r1)
return (*(Node *)a).r1 - (*(Node *)b).r1;
else
return (*(Node *)a).r2 - (*(Node *)b).r2;
}
int main()
{
int cas,n,i,ans,j,tmp,k;
cin>>cas;
while(cas --)
{
ans = 0;
memset(cot,0,sizeof(cot));
cin>>n;
for(i = 0;i < n;i ++){
cin>>node[i].r1>>node[i].r2;
if(node[i].r1 > node[i].r2){swap(node[i].r1,node[i].r2);}
}
qsort(node,n,sizeof(node[0]),cmp);
j = 0;
while(j < n)
{
if(cot[j] == 0)
{
cot[j] = 1;
ans += 10;
tmp = node[j].r2;
if(tmp % 2 == 1) tmp++;
for(k = 0;k < n;k ++)
{
if(cot[k] == 0&&node[k].r1 > tmp)
{tmp = node[k].r2;cot[k] = 1;}
}
}
j ++;
}
cout<<ans<<endl;
}
return 0;
}