测试点1WA,但是下载数据代入程序又是对的,且样例也可以过,Why?
查看原帖
测试点1WA,但是下载数据代入程序又是对的,且样例也可以过,Why?
1394370
Listedzero楼主2024/10/13 20:39

情况如标题所示, 提交记录:https://www.luogu.com.cn/record/181972054

#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e3+5;
bool t[MAXN];
int len[MAXN];//某个端点到下一个端点的距离 
int give,cow,shed,res;
int main(){
	cin>>give>>shed>>cow;
	int start;cin>>start;
	t[start]=1;
	for(int i=2;i<=cow;i++){
		int num;cin>>num;t[num]=1;
	}
	//1:特判,每个都可以单独覆盖,直接输出牛的个数 
	if(give>=cow) {cout<<cow;return 0;}
	//2:常规,贪心查找每两个牛棚中隔得最近的
	int cnt=0,num=0;bool q=0;
	for(int i=start;i<=shed;i++){
		if(t[i]==0) cnt++;
		if(t[i]==1) {
			len[num++]=cnt;
			cnt=0;
		}
	}
	cout<<endl;
	sort(len+1,len+1+num);
	int need=cow,list=0,wood=cow;
	while(need>=give-1){
		need--;
		wood+=len[list++];
//		cout<<"r";
	}
	cout<<wood;
//	cout<<endl;
//	for(int i=1;i<=shed;i++) cout<<t[i];
//	cout<<endl;
//	for(int i=1;i<=num;i++) cout<<len[i]<<" ";
	return 0;
}

附测试点1

in:

4 50 17 3 4 6 8 14 15 16 17 25 26 27 30 31 40 41 42 43

ans:21
2024/10/13 20:39
加载中...