zoukankan      html  css  js  c++  java
  • BZOJ3208 花神的秒题计划Ⅰ

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=3208

    Description

    背景:
     Memphis等一群蒟蒻出题中,花神凑过来秒题……
     
    描述:
     花花山峰峦起伏,峰顶常年被雪,Memphis打算帮花花山风景区的人员开发一个滑雪项目。
     
     我们可以把风景区看作一个n*n的地图,每个点有它的初始高度,滑雪只能从高处往低处滑【严格大于】。但是由于地势经常变动【比如雪崩、滑坡】,高度经常变化;同时,政府政策规定对于每个区域都要间歇地进行保护,防止环境破坏。现在,滑雪项目的要求是给出每个n*n个点的初始高度,并给出m个命令,C a b c表示坐标为a,b的点的高度改为c;S a b c d表示左上角为a,b右下角为c,d的矩形地区开始进行保护,即不能继续滑雪;B a b c d表示左上角为a b,右下角为c d的矩形地区取消保护,即可以开始滑雪;Q表示询问现在该风景区可以滑雪的最长路径为多少。对于每个Q要作一次回答。
     
     花神一看,这不是超简单!立刻秒出了标算~

    Input

    第一行n,第二行开始n*n的地图,意义如上;接下来一个m,然后是m个命令,如上

    Output

    对于每一个Q输出单独一行的回答

    暴力大法好!暴力出奇迹!暴力踩标程!暴力能AC!

    (好吧这道题正解就是暴力)(我是来刷水题放松身心的)

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <algorithm>
     4 #include <cstring>
     5 #define rep(i,l,r) for(int i=l; i<=r; i++)
     6 #define clr(x,y) memset(x,y,sizeof(x))
     7 using namespace std;
     8 const int maxn = 710;
     9 const int dir[4][2] = {{1,0},{0,1},{-1,0},{0,-1}};
    10 int n,m,x,y,z,w,f[maxn][maxn],h[maxn][maxn];
    11 char ch[10];
    12 bool p[maxn][maxn];
    13 inline int read(){
    14     int ans = 0, f = 1;
    15     char c = getchar();
    16     for(; !isdigit(c); c = getchar())
    17     if (c == '-') f = -1;
    18     for(; isdigit(c); c = getchar())
    19     ans = ans * 10 + c - '0';
    20     return ans * f;
    21 }
    22 inline bool valid(int x,int y){
    23     return x >= 1 && x <= n && y >= 1 && y <= n;
    24 }
    25 int dfs(int x,int y){
    26     if (p[x][y]) return 0;
    27     if (f[x][y]) return f[x][y];
    28     f[x][y] = 1;
    29     rep(i,0,3){
    30         int xx = x + dir[i][0];
    31         int yy = y + dir[i][1];
    32         if (valid(xx,yy) && h[xx][yy] < h[x][y])
    33         f[x][y] = max(f[x][y],dfs(xx,yy) + 1);
    34     }
    35     return f[x][y];
    36 }
    37 int main(){
    38     n = read(); clr(p,0);
    39     rep(i,1,n) rep(j,1,n) h[i][j] = read();
    40     m = read();
    41     rep(i,1,m){
    42         scanf("%s",ch);
    43         if (ch[0] == 'C'){
    44             x = read(); y = read(); z = read(); h[x][y] = z;
    45         }
    46         else if (ch[0] == 'S' || ch[0] == 'B'){
    47             x = read(); y = read(); z = read(); w = read();
    48             rep(j,x,z) rep(k,y,w) p[j][k] = (ch[0] == 'S');
    49         }
    50         else{
    51             clr(f,0); int mx = -1;
    52             rep(j,1,n) rep(k,1,n) mx = max(mx,dfs(j,k));
    53             printf("%d
    ",mx);
    54         }
    55     }
    56     return 0;
    57 }
    View Code
  • 相关阅读:
    MD5加密40位加密规律
    python中 if __name__ == '__main__': 浅解
    python3关于邮件的操作
    ecshop莫名其妙出现“Table '.starecs_stats' is marked as crashed and should be repaired”
    微擎安装问题
    蝉知CMS本地迁移到服务器具体步骤
    React Hooks useContext + useReducer实现简易Redux
    git merge时merge/squash merge/rebase merge的区别
    FormData 和 Content-Type: multipart/form-data
    对Promise.prototype.finally()的粗浅理解
  • 原文地址:https://www.cnblogs.com/jimzeng/p/bzoj3208.html
Copyright © 2011-2022 走看看