zoukankan      html  css  js  c++  java
  • CF 1408D探照灯 找 匪

    1408D - Searchlights

    Let's define as xx our move to the right and as yy our move to the up. For all pairs (i,j)(i,j) of (robber, searchlight) at least one of this should be true: x+ai>cjy+bi>dj. So if xcjai then ydjbi+1.

    Let's make an array rr of length C=1e6 and write on each position of xx the minimum value of yy. For each (i,j)(i,j) we should make rx=max(rx,djbi+1) for all xcjai. So we have nm queries of max on prefix. We can do it using suffix maximums. After we will calculate all athe answer is minx(x+rx).

     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstring>
     4 #include<cmath>
     5 using namespace std;
     6 const int N = 2e3 + 10;
     7 int n, m;
     8 int a[N], b[N];
     9 int c[N], d[N];
    10 int ans = 10000000;
    11 int t[1000010];//t[x]当选择向右移动x时,至少需要向上移动t[x]个单位 
    12 
    13 int main(){
    14     scanf("%d%d",&n,&m);
    15     for(int i = 1 ; i <= n ; i++){
    16         scanf("%d%d",&a[i],&b[i]);
    17     }//匪徒
    18     for(int i = 1 ; i <= m ; i++){
    19         scanf("%d%d",&c[i],&d[i]);
    20     }//
    21     for(int i = 1 ; i <= n ; i++){
    22         for(int j = 1 ; j <= m ; j++){
    23             if(a[i] <= c[j] && b[i] <= d[j]){
    24                 t[c[j] - a[i]] = max(t[c[j] - a[i]], d[j] - b[i] + 1);
    25             }
    26         }
    27     }
    28     
    29     for(int i = 1000000 ; i >= 0 ; i--){
    30         t[i] = max(t[i], t[i + 1]); 
    31         ans = min(ans, t[i] + i);
    32     }
    33     printf("%d
    ",ans);
    34     
    35     return 0;
    36 }

  • 相关阅读:
    多线程(一)
    Interface
    Abstract
    面向对象
    字符串比对(10分)
    快递费用计算(7分)
    练习7-8 方阵循环右移 (20分)
    习题4-11 兔子繁衍问题 (15分)
    一道题理解穷举/贪心/爬山/遗传/退火/蚁群算法
    华为暑期测试实习生面经(2020.06)
  • 原文地址:https://www.cnblogs.com/ecustlegendn324/p/13831068.html
Copyright © 2011-2022 走看看