• C. Palindromic Paths


    题目链接:https://codeforces.com/contest/1366/problem/C

    题目大意:

    想法:

     所以我们只需要读入的时候预处理一下坐标和,然后直接去枚举 坐标和统计答案就可以了 

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    
    #define ll long long
    #define ull unsigned long long
    #define ls nod<<1
    #define rs (nod<<1)+1
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define INF 0x3f3f3f3f
    #define max(a, b) (a>b?a:b)
    #define min(a, b) (a<b?a:b)
    
    
    const double eps = 1e-8;
    const int maxn = 1e6 + 10;
    const ll MOD = 998244353;
    const int mlog=20;
    
    int sgn(double a) { return a < -eps ? -1 : a < eps ? 0 : 1; }
    
    using namespace std;
    
    int t,n,m,a[40][40],c[65][2];
    int main(){
        cin >> t;
        while(t--){
            int ans=0;
            cin >> n >> m;
            memset(a,0,sizeof(a));
            memset(c,0,sizeof(c));
            for(int i=1;i<=n;++i) 
                for(int j=1;j<=m;++j) 
                    cin >> a[i][j],c[i+j][0]+=(a[i][j]==0),c[i+j][1]+=(a[i][j]==1);
            if((n+m)%2==1){
                for(int i=2;i<=(n+m+2)/2;++i){
                    ans+=c[i][0]+c[i][1]+c[n+m+2-i][0]+c[n+m+2-i][1]-max(c[i][0]+c[n+m+2-i][0],c[i][1]+c[n+m+2-i][1]);
                }
            }
            else{
                for(int i=2;i<(n+m+2)/2;++i){
                    ans+=c[i][0]+c[i][1]+c[n+m+2-i][0]+c[n+m+2-i][1]-max(c[i][0]+c[n+m+2-i][0],c[i][1]+c[n+m+2-i][1]);
                }
            }
            cout<<ans<<endl;
        }
        return 0;
    }
  • 相关阅读:
    37.Spring-事务控制.md
    35.Spring-jdbc支持.md
    29.Hibernate-二级缓存和session管理.md
    28.Hibernate-HQL查询.md
    27.Hibernate-缓存和懒加载.md
    26.Hibernate-主键和映射.md
    25.Hibernate-配置文件.md
    24.Hibernate-各种类型的查询.md
    MarkDown学习记录
    gitbook使用
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/13541266.html
Copyright © 2020-2023  润新知