HDU 4907 - Task schedule(BestCoder Round #3 简单DP)

题目链接 HDU4907

【分析】 比赛的时候忘记考虑查询点大于给出点的情况了,然后竟然也过了小数据,结果后来大数据WA了,再过来看马上发现错误了(相当郁闷啊);

其实这题就是DP的记录一下每个点右边最近的没有任务的点,后来的询问应该题目说了询问之间没有关联,所以不需要更新了(记得最近做了好题这种类型的,上次百度之星的初赛(HDU4831)也有比这个难一点的需要更新的,郁闷啊),惨痛的教训)

 

【AC CODE】187ms

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAXN 100010
bool vis[2 * MAXN];
int dp[2 * MAXN];

int main()
{
#ifdef SHY
	freopen("e:\\1.txt", "r", stdin);
#endif
	int t;
	scanf("%d%*c", &t);
	while(t--)
	{
		int n, m, a, maxn = 0, p;
		scanf("%d %d%*c", &n, &m);
		memset(vis, 0, sizeof(vis));
		for(int i = 0; i < n; i++)
		{
			scanf("%d%*c", &a);
			vis[a] = true;
			if(maxn < a) maxn = a;
		}
		p = maxn + 1;
		for(int i = maxn; i >= 1; i--)
		{
			if(!vis[i])
				p = i;
			dp[i] = p;
		}
		for(int i = 0; i < m; i++)
		{
			scanf("%d%*c", &a);
			if(vis[a])
				printf("%d\n", dp[a]);
			else printf("%d\n", a);
		}
	}
	return 0;
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值