【CodeForces】Gargari and Bishops,codeforcesgargari

來源:互聯網
上載者:User

【CodeForces】Gargari and Bishops,codeforcesgargari

根據貪心可以知道,放置的教主必須不能相互攻擊到(也就是不在一條對角線上)才可以使得結果最大化。

根據觀察可以得到教主相互不攻擊的條件是他的座標和互為奇偶(x + y)

之後直接暴力,處理每個座標組角線的和就好

時間複雜度 0(n ^ 2)

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;typedef long long LL;const int maxn = 2005;LL sum_l[maxn * 10] = {0},sum_r[maxn * 10] = {0};LL mat[maxn][maxn];int main(){    int n,m;    LL  x;    scanf("%d",&n);    for(int i = 0; i < n; i++){        for(int j = 0; j < n; j++){            scanf("%I64d",&mat[i][j]);            sum_l[i + j] += mat[i][j];            sum_r[n - 1 + j - i] += mat[i][j];        }    }    //for(int i = 0; i < 2 * n - 1; i++)    //    printf("%I64d %I64d\n",sum_l[i],sum_r[i]);    LL max1 = - 1,max2 = -1;    int x1,x2,y1,y2;    for(int i = 0; i < n; i++)        for(int j = 0; j < n; j++){            LL ret = sum_l[i + j] + sum_r[n - 1 + j - i] - mat[i][j];            if(((i + j) & 1) && ret > max1){                max1 = ret;                x1 = i;                y1 = j;            }            else if((!((i + j) & 1)) && ret > max2){                max2 = ret;                x2 = i;                y2 = j;            }        }    LL ans = max1 + max2;    printf("%I64d\n",ans);    printf("%d %d %d %d\n",x1 + 1,y1 + 1,x2 + 1,y2 + 1);    return 0;}

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.