zoukankan      html  css  js  c++  java
  • AGC016C +/- Rectangle(构造)

    题目大意:给定H,W,h,w四个数,求是否满足矩阵的全部数之和和正数,h行w列之和为负数

    如果h和w恰好是H,W的约数,则肯定不存在

    否则肯定存在

    只需要把h,w内每个元素填的足够大,然后小矩形的最后一个元素为负,且保持整个小矩形为负即可(可用不等式证明)

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    using namespace std;
    long long Mat[505][505];
    long long n, m, r, c;
    int main()
    {
        cin>>r>>c>>n>>m;
        for(int i = 1; i <= r; i++)
            for(int j = 1; j <= c; j++)
                Mat[i][j] = 1000;
        for(int i = n; i <= r; i += n)
            for(int j = m; j <= c; j += m)
                Mat[i][j] = -n*m*1000 + 999;
        long long sum = 0;
        for(int i = 1; i <= r; i++)
            for(int j = 1; j <= c; j++)
                sum += Mat[i][j];
        if(sum < 0) { cout<<"No"<<endl; }
        else {
            cout<<"Yes"<<endl;
            for(int i = 1; i <= r; i++){
                for(int j = 1; j <= c; j++)
                    cout<<Mat[i][j]<<" ";
                cout<<endl;
            }
        }
    
    }
  • 相关阅读:
    pandas.DataFrame.to_excel
    python list [:1]
    python 读取文件
    pandas 中的常用数学计算
    神经网络相关术语
    keras初探
    机器学习相关
    Numpy random arange zeros
    numpy 常用函数
    【Redis学习之四】Redis数据类型 string
  • 原文地址:https://www.cnblogs.com/Saurus/p/7050372.html
Copyright © 2011-2022 走看看