Codeforces 523D Statistics of Recompressing Videos 排序+优先队列
来源:互联网 发布:axure 浏览器插件 mac 编辑:程序博客网 时间:2024/05/16 13:05
题目链接:点击打开链接
题意:
给定n个人,k个窗口
下面n行给出每个人到银行的时间和每个人办理手续需要的时间。
输出每个人离开的时间
先到先服务
import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.PrintWriter;import java.math.BigInteger;import java.text.DecimalFormat;import java.util.ArrayDeque;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.Comparator;import java.util.Deque;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.Map;import java.util.PriorityQueue;import java.util.Scanner;import java.util.Stack;import java.util.StringTokenizer;import java.util.TreeMap;import java.util.TreeSet;import java.util.Queue;import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;public class Solution {class Node implements Comparable<Node>{long a, b; int id;Node(long a, long b, int id){this.a = a; this.b = b; this.id = id;}public int compareTo(Node o) {return Long.compare(a, o.a);}void pt(){System.out.println(a+" "+b+" "+id);}}long n, k;PriorityQueue<Node> q = new PriorityQueue();ArrayList<Node> b = new ArrayList();Long[] ans = new Long[N];void work() throws Exception {n = Int(); k = Int();for(int i = 1; i <= k; i++)q.add(new Node(0L, 0L, 0));for(int i = 1; i <= n; i++)b.add( new Node(Int(), Int(), i) );Collections.sort(b);for(int i = 0; i < n; i++) { long x = b.get(i).a, y = b.get(i).b; int id = b.get(i).id;Node top = q.poll();x = max(x, top.a);x += y;ans[id] = x;q.add(new Node(x, 0, id));}for(int i = 1; i <= n; i++)out.println(ans[i]);}Solution(){in = new BufferedReader(new InputStreamReader(System.in));out = new PrintWriter(System.out);}public static void main(String[] args) throws Exception {Solution wo = new Solution();// in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt"))));// out = new PrintWriter(new File("output.txt"));wo.work();out.close();}static int N = 500005;static int M = N * 2;DecimalFormat df = new DecimalFormat("0.0000");static int inf = (int) 1e9;static long inf64 = (long) 1e18;static double eps = 1e-8;static double Pi = Math.PI;static int mod = (int) 1e9 + 7;private String Next() throws Exception {while (str == null || !str.hasMoreElements())str = new StringTokenizer(in.readLine());return str.nextToken();}private int Int() throws Exception {return Integer.parseInt(Next());}private long Long() throws Exception {return Long.parseLong(Next());}private double Double() throws Exception {return Double.parseDouble(Next());}StringTokenizer str;static Scanner cin = new Scanner(System.in);static BufferedReader in;static PrintWriter out;class Edge{int from, to, dis, nex;Edge(){} Edge(int from, int to, int dis, int nex){this.from = from; this.to = to; this.dis = dis; this.nex =nex; }} Edge[] edge = new Edge[M<<1]; int[] head = new int[N]; int edgenum; void init_edge(){ for(int i = 0; i < N; i++)head[i] = -1; edgenum = 0;} void add(int u, int v, int dis){ edge[edgenum] = new Edge(u, v, dis, head[u]); head[u] = edgenum++; } /* */int upper_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;int pos = r;r--;while (l <= r) {int mid = (l + r) >> 1;if (A[mid] <= val) {l = mid + 1;} else {pos = mid;r = mid - 1;}}return pos;}int lower_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A;int pos = r;r--;while (l <= r) {int mid = (l + r) >> 1;if (A[mid] < val) {l = mid + 1;} else {pos = mid;r = mid - 1;}}return pos;}int Pow(int x, int y) {int ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}double Pow(double x, int y) {double ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}int Pow_Mod(int x, int y, int mod) {int ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;ans %= mod;y >>= 1;x = x * x;x %= mod;}return ans;}long Pow(long x, long y) {long ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;y >>= 1;x = x * x;}return ans;}long Pow_Mod(long x, long y, long mod) {long ans = 1;while (y > 0) {if ((y & 1) > 0)ans *= x;ans %= mod;y >>= 1;x = x * x;x %= mod;}return ans;}int gcd(int x, int y) {if (x > y) {int tmp = x;x = y;y = tmp;}while (x > 0) {y %= x;int tmp = x;x = y;y = tmp;}return y;}int max(int x, int y) {return x > y ? x : y;}int min(int x, int y) {return x < y ? x : y;}double max(double x, double y) {return x > y ? x : y;}double min(double x, double y) {return x < y ? x : y;}long max(long x, long y) {return x > y ? x : y;}long min(long x, long y) {return x < y ? x : y;}int abs(int x) {return x > 0 ? x : -x;}double abs(double x) {return x > 0 ? x : -x;}long abs(long x) {return x > 0 ? x : -x;}boolean zero(double x) {return abs(x) < eps;}double sin(double x) {return Math.sin(x);}double cos(double x) {return Math.cos(x);}double tan(double x) {return Math.tan(x);}double sqrt(double x) {return Math.sqrt(x);}}
0 0
- Codeforces 523D Statistics of Recompressing Videos 排序+优先队列
- cf#VK Cup 2015 - Qualification Round 2-D - Statistics of Recompressing Videos-优先队列模拟
- Codeforces 523C&D C.Name Quest【贪心】、D.Statistics of Recompressing Videos【模拟】
- 523D - Statistics of Recompressing Videos【模拟,greedy】
- VK Cup 2015 - Qualification Round 2 D - Statistics of Recompressing Videos
- Codeforces 3D 优先队列
- Codeforces 721D (优先队列,模拟)
- codeforces 721D D. Maxim and Array (STL||优先队列)
- Codeforces Round #303 (Div. 2)-D. Queue(优先队列)
- Codeforces 553D Nudist Beach 优先队列 贪心
- Codeforces Round #350 (Div. 2)(D)优先队列
- Codeforces Round #374 (Div. 2) D 贪心+优先队列
- codeforces 725D Contest Balloons(贪心+优先队列)
- codeforces 754D Fedor and coupons(优先队列)
- codeforces 754D Fedor and coupons (优先队列)
- Codeforces 754 D Fedor and coupons【优先队列】
- Codeforces 722D Generating Sets【优先队列+贪心】
- codeforces D. Fedor and coupons 贪心+优先队列
- Jbutton时间按钮
- 【SICP归纳】5 泛型运算符
- 删除尺码和颜色后面价格
- PHP 设计模式
- 对的Volatile深入理解
- Codeforces 523D Statistics of Recompressing Videos 排序+优先队列
- 【数位DP】 HDU 4734 F(x)
- 杭电 HDU 1064 Financial Management
- java 获取properties配置文件属性值
- [数据结构复习]红黑树
- ASP.NET使用GridView时,出现错误“必须声明标量变量‘@ID’”的解决方法
- UVA - 11997 K Smallest Sums 归并排序+优先队列
- 深入理解内存:原理简介
- java几大排序