CF830A Office Keys(贪心)】的更多相关文章

CF830A Office Keys [题目链接]CF830A Office Keys [题目类型]贪心 &题意: 有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要拿钥匙才能回目的地 &题解: 这题做的时候没有认真想样例,如果仔细想的话就能发现n个人选的n个钥匙一定是连续的(在排过序之后),你可以这样想: 如果n个人直接去目的地,那么就肯定是连续的区间了吧,如果这个区间里钥匙数够,就可以直接回去了,如果不够,肯定是在区间的两边寻找剩下的钥匙,所以一定是连续的区间…
原题链接:http://codeforces.com/contest/830/problem/A 题意:在一条数轴上分别有n个人和k把钥匙(n<=k),以及一个目的地,每个人要各自拿到一个钥匙后到达目的地.每个人的移动速度都是1, 问所有人都到达目的地的最短时间. 思路:转化一下题意,就是求耗时最长的人所用的最短时间. 我们可以二分答案x,然后对排序后的人以及钥匙进行枚举,进行从左至右搭配. 这里check函数中返回false的条件是从左至右所有人都能在x的时间内到达目的地,而计算这些人到达目的…
D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as wel…
D. Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as wel…
Office Keys time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well.…
A. Office Keys time limit per test: 2 seconds memory limit per test: 256 megabytes input standard: input output standard: output There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as…
思路: 问题的关键在于对钥匙按照位置排序之后,最终选择的n个钥匙一定是其中的一个连续的区间. 实现: #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; typedef long long ll; const ll INF = 0x3f3f3f3f3f3f3f3f; ll man[], key[]; ll cal(ll…
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo…
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都要先拿到一把钥匙; 钥匙散落在k个位置(k>=n) 然后告诉你n个人的起始位置; 然后每个人,每秒钟移动一个单位长度; 问你最少需要多长时间,可以使得,每个人都拿到钥匙,且都走到终点; [Solution] 把初始位置a数组和钥匙位置b数组,都分别升序排; 假设有一个长度为n的窗口; 用这个窗口,一…
http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公用钥匙(相当于钥匙是消耗品,可以赋予人进入终点的能力),问最少花费多少时间可以让所有人都到达终点. 分析题意问题不大,无非就是每个方案中每个人的时间求最大值,每个方案再求最小值.但是如何在n^2的复杂度下枚举方案并计算耗时?这题的关键就是,可以证明,最优的方案一定是坐标值排序后连续的钥匙段(n把钥匙)顺序…