zoukankan      html  css  js  c++  java
  • [IOI2013]robots 机器人

    portal

    不愧是IOI滴题,瞅了半天没思路/kk

    贪心

    (A)(B) 机器人按照限制从小到大排序,物品按照质量从小到大排序,二分枚举最短时间,先用 (A) 机器人运,剩下的再交给 (B) 机器人,最后判断能不能运完,可以用优先队列来维护运的物品

    /*
    work by:Ariel_
    队列要清空,无解输出-1 
    */
    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <queue>
    #include <algorithm>
    using namespace std;
    const int N = 500005,M = 100005;
    int read(){
        int x = 0,f = 1; char c = getchar();
        while(c < '0'||c > '9') {if(c == '-') f = -1; c = getchar();}
        while(c >= '0' && c <= '9') {x = x*10 + c - '0'; c = getchar();}
        return x*f;
    }
    struct node{
       int x, y;
       bool operator < (const node st) const {return x < st.x;}
    }p[N];
    int ta[M], tb[M], A, B, x[M], y[M], n;
    priority_queue <int> Q;
    bool check(int mid) {
       for (int i = 1; i <= A; i++) ta[i] = mid;
       for (int i = 1; i <= B; i++) tb[i] = mid;
       while(!Q.empty()) Q.pop();
       int now = 1;
       for (int i = 1; i <= A; i++) {
       	  while (p[now].x < x[i] && now <= n) Q.push(p[now].y), now++;//这个玩具可以被这个机器送(但不一定被这个机器送) 
    	  while (!Q.empty() && ta[i]--) Q.pop();//用这个机器运送这个玩具(要保证这个机器运送的时间在枚举范围之内) 
       }
       while (now <= n) Q.push(p[now].y), ++now;
       for (int i = B; i >= 1; i--) {
       	  while (!Q.empty() && tb[i]-- && Q.top() <  y[i]) Q.pop();
       }
       return Q.empty();
    }
    int main(){
       A = read(), B = read(), n = read();
       for (int i = 1; i <= A; i++) x[i] = read();
       for (int i = 1; i <= B; i++) y[i] = read();
       sort(x + 1, x + A + 1), sort(y + 1, y + B + 1);
       for (int i = 1; i <= n; i++) p[i].x = read(), p[i].y = read(); sort(p + 1, p + n + 1);
       int L = 1, R = n, ans = -1, mid;
       while(L <= R) {
       	  mid = (L + R) >> 1;
       	  if (check(mid)) ans = mid, R = mid - 1;
    	  else L = mid + 1;
       } 
       printf("%d", ans);
       puts("");
       return 0;
    } 
    
  • 相关阅读:
    NVMe固态硬盘工具箱使用说明
    (原创)Python文件与文件系统系列(1)—— file 对象
    Linux系统排查4——网络篇
    Python内置类型——list
    (原)数据结构——线索二叉树
    Python匿名函数——lambda表达式
    Python生成器
    Python内置类型——dict
    Python内置类型——set
    解决Django-1.8.2应用部署到Apache后无法显示admin应用的CSS
  • 原文地址:https://www.cnblogs.com/Arielzz/p/14932612.html
Copyright © 2011-2022 走看看