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;
            }
        }
    
    }
  • 相关阅读:
    VC++读写文件
    VC++编译说明
    VC++时间函数总结
    VC++多工程项目
    VC++全局变量初始化
    Linux 系统免密码登陆远程服务器
    debian 系统安装配置apache
    数据库授权
    Mysql 主从服务器数据同步
    centos Install Docker
  • 原文地址:https://www.cnblogs.com/Saurus/p/7050372.html
Copyright © 2011-2022 走看看