UVA 10020 简单贪心区间覆盖,各种WA,记录一下

这个代码还是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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值