在下面这道题中,我是用了暴力,代码如下:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int t,k,q;
int cnt[1000005];
int a[100005],b[100005];
int main(){
scanf("%d",&t);
for(int T=1;T<=t;T++){
scanf("%d%d",&k,&q);
for(int i=1;i<=1000000;i++){
cnt[i]=0;
}
for(int tc=1;tc<=q;tc++){
scanf("%d%d",&a[tc],&b[tc]);
}
printf("Case %d:\n",T);
bool f=true;
for(int tc=1;tc<=q;tc++){
bool ok=true;
for(int i=a[tc];i<=b[tc]&&ok;i++){
if (cnt[i]+1>k){
ok=false;
}
}
if (ok){
if (f==true){
printf("%d",tc);
f=false;
}else{
printf(" %d",tc);
}
for(int i=a[tc];i<=b[tc];i++){
cnt[i]++;
}
}
}
printf("\n\n");
}
return 0;
}
但是WA了。哪位巨佬能告诉我哪里写错了?