这个代码还是WA,实在是找不到哪里有毛病,难道有事题意没理解?无语
#include <map>
#include <set>
#include <list>
#include <cmath>
#include<cctype>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b)
{
return a % b == 0 ? b : gcd(b, a % b);
}
struct node
{
int start,end;
int id;
friend bool operator <(const node &a,const node &b)
{
if (a.start!=b.start) return a.start<b.start;
return a.end>b.end;
}
}src[100010],chan[100010];
int M,cas;
void input()
{
int a,b;cas=0;
scanf("%d",&M);
while (scanf("%d%d",&a,&b)==2)
{
if (a==0 && b==0) break;
if (a<=0 && b<=0) continue;
if (a>=M && b>=M) continue;
src[cas].start=a;
src[cas].end=b;
if (a<0) a=0;
if (b>M) b=M;
chan[cas].id=cas;
chan[cas].start=a;
chan[cas++].end=b;
}
}
void show()
{
for (int i=0;i<cas;i++)
printf("%d %d\n",chan[i].start,chan[i].end);
}
int res[100010];//Êä³öÊý×é
void slove()
{
if (M==0)
{printf("\n0\n");return ;}
int leap=0,newstart=0,flag=0;
sort(chan,chan+cas);
//show();
while (1)
{
if (leap==cas) break;
if (chan[leap].start>newstart) {printf("0\n");return ;}
newstart=chan[leap].end;
leap++;
if (newstart>=M){flag=1;break;}
}
if (flag)
{
printf("%d\n",leap);
for (int i=0;i<leap;i++)
printf("%d %d\n",src[chan[i].id].start,src[chan[i].id].end);
}
else printf("0\n");
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
input();
slove();
if (T) putchar('\n');
}
return 0;
}