D. Beauty of the mountains(cf955)

分析:有一个n*m的数组a,对应n*m的数组b,想让b=0的下标的a的数组之和等于b=1的下标的a的数组之和,你可以进行k*k的范围所有数字全部加任意数。

求出子矩阵里0和1的差值;

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void sol(){
    int n,m,k;cin>>n>>m>>k;
    ll a[n+10][m+10],b[n+10][m+10],cz[n+10][m+10];
    ll sum=0;//0部分和1部分的差值
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    char x;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>x;
            if(x=='0')b[i][j]=-1;
            else b[i][j]=1;
            cz[i][j]=cz[i-1][j]+cz[i][j-1]-cz[i-1][j-1]+b[i][j];
            if(b[i][j]==1)sum+=a[i][j];
            else sum-=a[i][j];
        }
    }
    int g=0;
    for(int i=k;i<=n;i++){//算子矩阵的差值并找出所有子矩阵的gcd
        for(int j=k;j<=m;j++){
            int num=abs(cz[i][j]-cz[i-k][j]-cz[i][j-k]+cz[i-k][j-k]);
            if(g==0)g=num;
            else g=__gcd(g,num);
        }
    }
    if(sum==0||(g!=0&&abs(sum)%g==0))cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}
int main(){
    int t;cin>>t;
    while(t--){
        sol();
    }
    
}

  • 19
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Certainly, I can write a small essay of 1000 words about Yunnan province of China. Yunnan is one of the most beautiful provinces in China, located in the southwestern part of the country. It is surrounded by mountains and is known for its diverse topography and natural beauty. The province is home to 25 different ethnic minority groups, which gives it a rich cultural heritage that is unique to the region. Yunnan has a rich history, and there are many fascinating historical sites to visit throughout the province. One of the most famous historical sites is the ancient city of Dali, which dates back to the 14th century. The city is surrounded by the beautiful Cangshan Mountains and is known for its traditional architecture and unique culture. Another must-visit city in Yunnan is Lijiang, which is a UNESCO World Heritage Site. The old town of Lijiang is well-preserved and is a beautiful example of traditional Naxi architecture. The city is also famous for its Jade Dragon Snow Mountain, which is one of the most magnificent peaks in the world. In addition, Yunnan has some of the most beautiful natural landscapes in China, with towering mountains, deep gorges, and clear lakes. The Three Parallel Rivers of Yunnan Protected Areas is a UNESCO World Heritage Site that encompasses the area where the Jinsha, Lancang, and Nujiang rivers flow parallel to each other for over 300 kilometers. This region features spectacular natural scenery, including the deep canyons, majestic waterfalls, and rare species of animals and plants. Yunnan is also known for its vibrant and diverse cuisine. The province’s cuisine is influenced by the region’s ethnic minority groups, resulting in a unique blend of flavors and cooking styles. One of the most famous dishes in Yunnan is the ‘Crossing the Bridge Noodles,’ which is a rice noodle soup that is served with a variety of meats, vegetables, and seasonings. In conclusion, Yunnan province is a treasure trove of natural beauty, cultural heritage, and delicious cuisine. It has something to offer for everyone, from history buffs to nature lovers to foodies. Yunnan is undoubtedly one of the most fascinating and unforgettable destinations in China, and it is a place that everyone should visit at least once in their lifetime.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值