code force 424 A - Office Keys】的更多相关文章

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…
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…
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…
[Link]:http://codeforces.com/contest/831/problem/D [Description] 有n个人,它们都要去一个终点,终点位于p; 但是,在去终点之前,他们都要先拿到一把钥匙; 钥匙散落在k个位置(k>=n) 然后告诉你n个人的起始位置; 然后每个人,每秒钟移动一个单位长度; 问你最少需要多长时间,可以使得,每个人都拿到钥匙,且都走到终点; [Solution] 把初始位置a数组和钥匙位置b数组,都分别升序排; 假设有一个长度为n的窗口; 用这个窗口,一…
显然是不可能交叉取钥匙的,于是把钥匙和人都按坐标排序就可以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);…
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; ]; ]; ][]; //dp[i][j] 前i个人从前j个药匙中到达终点的最小时间 int main() { int n,k,p; while(~scanf("%d%d%d",&n,&k,&p)) { memset…