zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    BZOJ 1726 洛谷 2865 [USACO06NOV]路障Roadblocks【次短路】
    BZOJ 1699 [Usaco2007 Jan]Balanced Lineup排队
    洛谷 2777 [AHOI2016初中组]自行车比赛
    BZOJ 1832、1787 洛谷 4281 [AHOI2008]紧急集合
    BZOJ 4385 洛谷3594 POI2015 WIL-Wilcze doły
    【HDU 3037】Saving Beans(卢卡斯模板)
    【POJ 1061】青蛙的约会(EXGCD)
    【HIHOCODER 1469 】福字(DP)
    【BZOJ 1076】[SCOI2008]奖励关(期望)
    【HIHOCODER 1509 】 异或排序
  • 原文地址:https://www.cnblogs.com/ydclyq/p/11661718.html
Copyright © 2011-2022 走看看