(codeforces 853A)Planning 贪心】的更多相关文章

Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of…
题意 给出飞机单位晚点时间代价和原定起飞时间,现在前k分钟不能起飞,求付出的最小代价和起飞顺序 思路 构造两个优先队列q1,q2,q1按时间顺序,q2按代价顺序,初始将所有飞机入q1,将时间在k前的飞机从q1加入q2,然后按时间顺序取出q1加入q2,同时从q2取出代价最大的加入答案 代码 #include<bits/stdc++.h> using namespace std; inline int read(){ ,f= ; char ch = getchar(); ;ch = getchar…
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一种是3多,那么结果就加上3的个数,再单独处理2. 对于1和2组队处理的讨论:首先分配2,有2种情况,一种是2正好分配完了,另外一种就2还剩下2个人(正好剩下1组).就一起处理这个2个人和1剩下的人. 把每次处理的结果都加起来即可. 代码 #include <iostream> #include &…
Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day. Metropolis airport is the main transport hub of…
Planning time limit per test 1 second memory limit per test 512 megabytes input standard input output standard output Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today,…
<题目链接> 题目大意: 表示有n架飞机本需要在[1,n]时间内起飞,一分钟只能飞一架.但是现在[1,k]时间内并不能起飞,只能在[k+1,k+n]内起飞.ci序号为i的飞机起飞延误一分钟的costi.每个飞机起飞时间不能比原定时间早,请安排一个起飞顺序,求最小的cost和. 解题分析: 贪心策略证明:转载于>>>设序号为i的飞机起飞时间为di,则cost=∑(di-i)*cj=∑di*cj-∑j*cj.显然后一项为常数,而{di-k}为[1,n]的一个排列, 所以只要使ci…
贪心:让代价大的尽量移到靠前的位置. 做法:先让前k个数加进堆里,枚举k+1~n+k,每次把新元素加进堆后找到最大代价放在当前位置即可. #include<bits/stdc++.h> #define ll long long using namespace std; ; struct poi{int c,pos;}; priority_queue<poi>q; bool operator<(poi a,poi b){return a.c<b.c;} int n,k;…
题目大意: 输入n,k,代表n列航班,初始始发实践为1,2,3分钟以此类推,然后输入n个整数分别代表延迟1分钟第i个航班损失多少钱,然后调整后的始发时间表是这样的,任何一辆航班的始发时间不能在他的初始始发实践之前而且满足k+1<=ti<=k+n,然后,让你输出最小的损失以及一次输出每辆航班的始发时间: 基本思路: 一开始我的思路是肯定是让每分钟损失最多的放在前面,然后由于还有限制条件所以,如果当前位置(时间)不能满足,那就向后找位置,但是这样是对于一个航班找时间,时间复杂度是n^2的,果断超时…
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有s的位置(不是字符),求所有s在sort后字典序最小的那个字符串. 思路:对字符排序后,从最后一个开始贪心,判断删除该字符后是否符和题意,当删除后不符合题意时,贪心到该相同字符对应的第一个位置为止. 比如对于test3来说 排序后为a a a b b b b c c c c 删除到(b,6)时发现不…
G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input output:standard output Johnny is at a carnival which has n raffles. Raffle i has a prize with value pi. Each participant can put tickets in whichever ra…