• Problem B. 即时战略 ———2019.10.12


    题目:

     

     

     

     

     

     

     

     

     

     代码~:感谢土蛋

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cmath>
     4 #include <cstdio>
     5 #include <algorithm>
     6 #include <queue>
     7 #include <vector>
     8 #include <map>
     9 #include <complex>
    10 
    11 #define lc k << 1
    12 #define rc k << 1 | 1
    13 
    14 #define inf 0x3f3f3f3f
    15  
    16 using namespace std;
    17 typedef long long ll;
    18 
    19 int a[805][805];
    20 int n, m, p;
    21 
    22 ll mn = 1e13, mx = 0;
    23 
    24 inline int dis(int x1, int y1, int x2, int y2){
    25     return min(abs(x2 - x1) + abs(y2 - y1), p);
    26 }
    27 
    28 void solve(int x){
    29     int y = 1;
    30     ll lres = 0, rres = 0;
    31     ll lsum = 0, rsum = 0;
    32     for(int i = x - p; i <= x + p; i ++){
    33         for(int j = y - p; j <= y; j ++){
    34             if(dis(i, j, x, y) != p) lsum += a[i + 200][j + 200]; lres += a[i + 200][j + 200] * (p - dis(i, j, x, y));
    35         }
    36     }
    37     for(int i = x - p; i <= x + p; i ++){
    38         for(int j = y + 1; j <= y + p; j ++){
    39             if(dis(i, j, x, y) != p) rsum += a[i + 200][j + 200]; rres += a[i + 200][j + 200] * (p - dis(i, j, x, y));
    40         }
    41     }
    42     //printf("%d %d %lld %lld %lld %lld
    ", x, y, lres, rres, lsum, rsum);
    43     mn = min(lres + rres, mn);
    44     mx = max(mx, lres + rres);
    45     while(y < m){
    46         lres -= lsum;
    47         for(int i = y - p + 1; i <= y; i ++){
    48             lsum -= a[x + (p - 1 - y + i) + 200][i + 200];
    49             if(p - 1 - y + i != 0) lsum -= a[x - (p - 1 - y + i) + 200][i + 200];
    50         }
    51         y ++;
    52         for(int i = y; i <= y + p - 1; i ++){
    53             rsum += a[x + (p - 1 - i + y) + 200][i + 200];
    54             if(p - 1 - i + y != 0) rsum += a[x - (p - 1 - i + y) + 200][i + 200];
    55         }
    56         rres += rsum;
    57         for(int i = x - p + 1; i <= x + p - 1; i ++){
    58             rsum -= a[i + 200][y + 200]; rres -= a[i + 200][y + 200] * (p - dis(i, y, x, y));
    59             lsum += a[i + 200][y + 200]; lres += a[i + 200][y + 200] * (p - dis(i, y, x, y));
    60         }
    61     //    printf("%d %d %lld %lld %lld %lld
    ", x, y, lres, rres, lsum, rsum);
    62         mn = min(lres + rres, mn);
    63         mx = max(mx, lres + rres);
    64     }
    65 }
    66 
    67 int main(){
    68     freopen("rts.in", "r", stdin);
    69     freopen("rts.out", "w", stdout);
    70      
    71     scanf("%d%d%d", &n, &m, &p);
    72     memset(a, 0, sizeof(a));
    73     for(int i = 1; i <= n; i ++){
    74         for(int j = 1; j <= m; j ++){
    75             scanf("%d", &a[i + 200][j + 200]);
    76             //a[i + 200][j + 200] = 1;
    77         }
    78     }
    79     for(int i = 1; i <= n; i ++){
    80         solve(i);
    81     }
    82     printf("%lld %lld
    ", mn, mx);
    83     return 0;
    84 }
    View Code
  • 相关阅读:
    js根据ip地址获取城市地理位置
    vue-cli项目中使用mock结合axios-mock-adapter生成模拟数据
    将图片转canvas
    判断浏览器是否联网
    头尾固定中间高度自适应布局 css
    经典闭包
    多余文字转化为省略号css
    $.grep()
    node 图片转base64
    CentOS 7下安装Mysql 5.7
  • 原文地址:https://www.cnblogs.com/ydclyq/p/11661718.html
Copyright © 2020-2023  润新知