CCPC2019江西省赛-Problem G.Traffic

题目描述:

  /*纯手打题面*/
  Avin is observing the cars at a crossroads.He finds that there are n cars running in the east-west direction with the i-th car passing the intersection at time a[i].There are another m cars running in the north-south direction with the i-th car passing the intersection at time b[i].If two cars passing the intersections at the same time,a traffic crash occurs.In order to achieve world peace and harmony,all the cars running in the north-south direction wait the same time amount of integral time so that no two cars bump.You are asked the
minimum waiting time.
/*纯手打题面*/

Input

n m
a[i]
b[i]
(1<=n,m<=1000;1<=ai,bi<=1000)

Output

The minimum waiting time(integer).

题解心得:

啊啊啊啊啊啊啊啊啊啊啊啊,当时在比赛的时候翻了好久词典,终于把这个题目的意思大概搞懂了

然后和我们队的大佬讨论了好久

一开始爆搜O(N3)

然后想了好久奇奇怪怪的方法,分治什么的,然后就剪枝优化。

但是最后用标记法把时间复杂度压到了O(N2)。

大致思路:

枚举时间(一个循环)

在每个循环里标记a[i]所占的时间点(布尔数组c)

同时标记b[i]+t的时间点(布尔数组d)

接着c&&d;

就可以了。

这题真的水,不加剪枝也能AC。

代码:

以后附。

转载于:https://www.cnblogs.com/XYYXP/p/JXCPC_2019_Problem_G.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值