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;
    } 
    
  • 相关阅读:
    Vue常用语法
    Vue--过滤器、指令、插件
    使用vue-cli创建项目
    electron Ctrl+滚轮事件 放大缩小
    axios 处理超时问题 记录
    electron 清除所有cookie记录
    electron用默认浏览器打开链接的3种实现方式
    electron 不支持Ctrl+滚动条放大缩小,自己动手做了一个react组件
    排序算法记录
    umi react 集成 spreadjs
  • 原文地址:https://www.cnblogs.com/Arielzz/p/14932612.html
Copyright © 2011-2022 走看看