codeforce830A. Office Keys】的更多相关文章

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…
CF830A Office Keys [题目链接]CF830A Office Keys [题目类型]贪心 &题意: 有n个人,k个钥匙,一个目的地,求让n个人都回到目的地的最短时间,每个人都要拿钥匙才能回目的地 &题解: 这题做的时候没有认真想样例,如果仔细想的话就能发现n个人选的n个钥匙一定是连续的(在排过序之后),你可以这样想: 如果n个人直接去目的地,那么就肯定是连续的区间了吧,如果这个区间里钥匙数够,就可以直接回去了,如果不够,肯定是在区间的两边寻找剩下的钥匙,所以一定是连续的区间…
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.…
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…
http://codeforces.com/contest/831/problem/D 题目大意是在一条坐标轴上,给出n个人,k把钥匙(k>=n)以及终点的坐标,所有人都可以同时运动,但不可以公用钥匙(相当于钥匙是消耗品,可以赋予人进入终点的能力),问最少花费多少时间可以让所有人都到达终点. 分析题意问题不大,无非就是每个方案中每个人的时间求最大值,每个方案再求最小值.但是如何在n^2的复杂度下枚举方案并计算耗时?这题的关键就是,可以证明,最优的方案一定是坐标值排序后连续的钥匙段(n把钥匙)顺序…
思路: 背包: 代码: #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define maxn 1005 #define maxk 2005 #define ll long long int n,k,p; ll dp[maxn][maxk],ai[maxn],bi…
显然是不可能交叉取钥匙的,于是把钥匙和人都按坐标排序就可以DP了 钥匙可以不被取,于是f[i][j]表示前i个钥匙被j个人拿的时间 f[i][j]=min(f[i-1][j],max(f[i-1][j-1],abs(b[i]-a[j])+abs(P-b[i])); #include<bits/stdc++.h> #define ll long long using namespace std; ,inf=2e9; int n,k,p; ],f[maxn*][maxn]; void read(i…
选择的钥匙一定是连续的,人和钥匙一定从左到右连续对应. 就枚举钥匙区间即可. #include<cstdio> #include<algorithm> using namespace std; int Abs(int x){ return x<0 ? (-x) : x; } int n,K,p,a[1010],ans=2147483647,b[2010]; int main(){ scanf("%d%d%d",&n,&K,&p);…