求助费用流答案输出 代码有注释
查看原帖
求助费用流答案输出 代码有注释
308384
Morpheuse楼主2022/3/26 23:13

Wa #81

样例没过...

scanf("%d%d%d%d", &n,&k,&ms,&me);
	//所有时间都在睡觉.
	//吃饭的时间区间为 [me , k - ms].
	//流经上面的边 也就是吃饭的区间为 [me , k - ms].
	//总流量为 Flw.
	//流经下面的边的区间就是 [Flw - k + ms , Flw - me].
	Flw = k - ms;
//	cout<<"总流量"<<Flw<<' '<<Flw - me<<endl;
	s = 0 , t = n + 1;
	add(s , 1 , Flw , 0);
	int ans = 0;
	for(int i = 1 ; i <= n ; ++ i) scanf("%d", &S[i]) , ans += S[i];
	for(int i = 1 ; i <= n ; ++ i) scanf("%d", &E[i]);
	for(int i = 1 ; i <= n ; ++ i) add(i , i + 1 , Flw - me , 0);
	for(int i = 1 ; i <= n ; ++ i) add(i , min(i + k , t) , 1 , S[i] - E[i]);
	dinic();
	printf("%d\n", ans - cot);
//	int tot = 0;
	for(int x = 1 ; x <= n ; ++ x)
	{
		int flag = 0;
		for(int i = hea[x] ; i ; i = e[i].nex)
		{
//			int to = e[i].to;
//			cout<<x<<"->"<<to<<":"<<e[i].flw<<endl;
			if(e[i].dat == S[x] - E[x])
			{ 
				if(e[i].flw)
				{//选择了睡觉.
//					cout<<"当前"<<x<<"上边还有流量说明选择睡觉"<<endl;
					flag = 1;
				}
				else
				{
//					cout<<"当前"<<x<<"上边没有流量说明选择吃饭"<<endl;
					flag = 0;
				}
					
				break;
			}
		}
		if(flag)
		{
//			tot += S[x];
			printf("S");
		}
		else
		{
//			tot += E[x];
			printf("E");
		}
	}
//	printf("%d\n", tot);
2022/3/26 23:13
加载中...