zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 28 D. Monitor

    题意:给出个n*m的矩阵,然我们求什么时候我们可以得到一个k*k的全坏矩阵,给出q个坐标和他们坏的时间

    思路:RQM预处理

     1 #include<bits/stdc++.h>
     2 typedef long long ll;
     3 using namespace std;
     4 const ll INF=1e18;
     5 
     6 ll d[503][503];
     7 ll dp[503][503];
     8 ll c[503][503];
     9 int n,m,k,q;
    10 
    11 int kk;
    12 void hh(int x){
    13     for(int i=0;i<m;i++)
    14         dp[i][0]=d[x][i];
    15     for(int j=1;(1<<j)<=m;j++)
    16         for(int i=0;i+(1<<j)-1<m;i++)
    17         dp[i][j]=max(dp[i][j-1],dp[i+(1<<(j-1))][j-1]);
    18     for(int i=0;i<=m-k;i++)
    19         c[x][i]=max(dp[i][kk],dp[i+k-(1<<kk)][kk]);
    20 }
    21 
    22 int RMQ(int l,int r){
    23     int kk=0;
    24     while((1<<(kk+1))<=r-l+1) kk++;
    25     return kk;;
    26 }
    27 
    28 int main(){
    29     cin>>n>>m>>k>>q;
    30     kk=RMQ(1,k);
    31     for(int i=0;i<n;i++)
    32         for(int j=0;j<m;j++) d[i][j]=INF;
    33     for(int i=1;i<=q;i++){
    34         int x,y;ll t;
    35         scanf("%d%d%lld",&x,&y,&t);
    36         d[x-1][y-1]=t;
    37     }
    38     for(int i=0;i<n;i++)
    39         hh(i);
    40     ll MMax=INF;
    41     for(int i=0;i<=n-k;i++){
    42         for(int j=0;j<=m-k;j++){
    43             ll Max=-1;
    44             for(int kk=i;kk<=i+k-1;kk++){
    45                  Max=max(Max,c[kk][j]);
    46                  if(Max==INF) break;
    47             }
    48             MMax=min(MMax,Max);
    49         }
    50     }
    51     if(MMax==INF) cout<<-1<<endl;
    52     else cout<<MMax<<endl;
    53 }
  • 相关阅读:
    IE下的异步JS测试
    使用P3P实现 跨域共享Cookie
    DataRow的泛型扩展方法
    我的Exec方法
    原创:截取HttpResponse输出流
    SWT/JFACE 第五天,常用组件
    导入数据库:DMP
    JAVA常见错误收集
    swtjface学习第二天
    项目管理过程之项目团队
  • 原文地址:https://www.cnblogs.com/hhxj/p/7494667.html
Copyright © 2011-2022 走看看