The 36th ACM/ICPC Asia Regional Fuzhou Site / 1010 War

11 篇文章 0 订阅

题目链接

我一开始的想法就是递推,维护一个cover值,表示能用第二阶段等待的时间来帮下一组数据cover掉多少时间。

但是我竟然没有考虑到可以不用等待下一组的第二段时间(即 t 时间)完成而马上进行第三组的 d 时间。这里wa了。

改后艰难AC....残了....

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

#define MAXN 100005
struct node{ int d, t; }a[MAXN];
int n;

int solve()
{
	int ret=0;
	int cover=0;
	for(int i=0; i<n; i++)
	{
//debug
//printf("go (%d, %d), cover=%d\n", a[i].d, a[i].t, cover);

		int all = a[i].d+a[i].t;
		int x = a[i].d+a[i].t - cover;
		if(x<0)	//ȫcover
		{
			cover = max(cover-a[i].d, a[i].t);
			x=0;
		}
		else if(cover>a[i].d)//
		{
			cover = max(cover-a[i].d, a[i].t);
		}
		else 
		{
			cover = a[i].t;
		}
		ret+=x;
	}
	return ret;
}

int cmp(node x, node y)
{
	if(x.t>y.t) return 1;
	else if(x.t==y.t && x.d<y.d) return 1;
	else return 0;
}
int main()
{
	int t;	scanf("%d", &t);
	for(int T=0; T<t; T++)
	{
		printf("Case %d: ", T+1);
		scanf("%d", &n);
		for(int i=0; i<n; i++)
		{
			scanf("%d%d", &a[i].d, &a[i].t);
		}
		sort(a, a+n, cmp);
		printf("%d\n", solve());
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值