为什么第一个数据不对
查看原帖
为什么第一个数据不对
707380
CSDN_dalao楼主2023/10/4 16:07
#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int s(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void p(int x){
 	if(!x)putchar('0');
    char F[200];
    int tmp=(x>0?x:-x);
    if(x<0)putchar('-');
    int cnt=0;
    while(tmp>0){
        F[cnt++]=tmp%10+'0';
        tmp/=10;
    }
    while(cnt>0)putchar(F[--cnt]);
    putchar('\n');
}
int n,k,m,tmp[1000005],tot[1000005],o,op;
struct node{
	int l,r;
}a[1000005],b[1000005];
bool cmp(node a,node b){
	return a.l<b.l;
}
signed main(){
	n=s(),m=s(),k=s();
	for(int i=1;i<=m;i++){
		a[i].l=s(),a[i].r=s(); 
	}
	for(int i=1;i<=k;i++){
		b[i].l=s(),b[i].r=s(); 
	}
	sort(a+1,a+1+m,cmp);
	sort(b+1,b+1+k,cmp);
	int t=0;
	bool used[1000005]={0};
	while(t<=m){
		int i=1,cnt=0;
		while(used[i]==1)i++;
		used[i]=1;
		t++,cnt++;
		for(int j=i+1;j<=m;j++){
			if(a[j].l>a[i].r&&!used[j]){
				used[j]=1;
				i=j;
				t++,cnt++;
			}
		}
		tmp[++o]=cnt;
	}
	for(int i=1;i<=m;i++)used[i]=0;
	t=0;
	while(t<=k){
		int i=1,cnt=0;
		while(used[i]==1)i++;
		used[i]=1;
		t++,cnt++;
		for(int j=i+1;j<=k;j++){
			if(b[j].l>b[i].r&&!used[j]){
				used[j]=1;
				i=j;
				t++,cnt++;
			}
		}
		tot[++op]=cnt;
	}
	int mx=0;
	for(int i=0;i<=n;i++){
		int cnt=0;
		for(int j=1;j<=i;j++)cnt+=tmp[j];
		for(int j=1;j<=n-i;j++)cnt+=tot[j];
		mx=max(mx,cnt);
	}
	p(mx);
	return 0;
}

数据: 2 5 10 36 275 131 223 222 308 40 60 50 70 61 80 71 90 81 100 167 240 101 120 166 220 46 194 130 150 186 243 153 170 按理来说应输出7,可输出的是6

2023/10/4 16:07
加载中...