• 题意:构造一个\(n\)x\(n\)只含\(0\)和\(k\)个\(1\)的矩阵,统计每一行每一列\(1\)的sum,然后构造一个权值最大行和最小行的差的平方加权值最大列和最小列的差的平方的最小和(\(f(A)=(max(R)-min(R))^2+(max(C)-min(C))^2\)的最小值).

  • 题解:假如\(k\ mod\ n=0\)的话,那么最小值一定是0,否则一定是2,直接上图吧.

    ​ 1.k%n=0:

    2.k%n!=0:

    这样的话,规律应该显而易见了吧,我们沿着对角线构造,然后取余,填填补补即可,具体的看代码吧.

  • 代码:

    1. int t;
    2. int n,k;
    3. int a[400][400];
    4. int main() {
    5. ios::sync_with_stdio(false);cin.tie(0);
    6. cin>>t;
    7. while(t--){
    8. cin>>n>>k;
    9. me(a,0,sizeof(a));
    10. if(k%n==0){
    11. cout<<0<<endl;
    12. }
    13. else cout<<2<<endl;
    14. for(int i=0;i<k%n;++i){
    15. for(int j=i;j<=i+k/n;++j){
    16. a[i][j%n]=1;
    17. }
    18. }
    19. for(int i=k%n;i<n;++i){
    20. for(int j=i;j<i+k/n;++j){
    21. a[i][j%n]=1;
    22. }
    23. }
    24. for(int i=0;i<n;++i){
    25. for(int j=0;j<n;++j){
    26. cout<<a[i][j];
    27. }
    28. cout<<endl;
    29. }
    30. }
    31. return 0;
    32. }

Codeforces Round #654 (Div. 2) D. Grid-00100 (构造)的更多相关文章

  1. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  2. Codeforces Round #654 (Div. 2) A~E 题解

    LINK:CF R 654 div2 前言:F题是一个线段树分类讨论的题目 比赛的时候没看 赛后感觉没什么意思 所以咕掉了. 记事:第一次笼统的写一场比赛的题目 可能是我这场比赛打的太差了 题目不难 ...

  3. Codeforces Round #654 (Div. 2)

    比赛链接:https://codeforces.com/contest/1371 A. Magical Sticks 题意 有 $n$ 根小棍,长度从 $1$ 到 $n$,每次可以将两根小棍连接起来, ...

  4. Codeforces Round #654 (Div. 2) B. Magical Calendar (结论)

    题意:你需要在长度从\(1\)~\(k\),宽度无限的网格图中造图形(每个点四周必须连通),问最多能造出多少种不同的图形. 题解:感觉没什么好说的,就是画图找规律,如果\(r\ge n\)的话(即没有 ...

  5. Codeforces Round #654 (Div. 2) C. A Cookie for You (思维)

    题意:有\(a\)个蛋糕,\(b\)个巧克力,第一类人有\(n\)个,总是吃多的东西(若\(a>b\),吃蛋糕,否则吃巧克力),第二类人有\(m\)个,总是吃少的,可以随便调整这两类人吃的顺序, ...

  6. Codeforces Round #342 (Div. 2) C. K-special Tables 构造

    C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...

  7. Codeforces Round #140 (Div. 1) D. The table 构造

    D. The table 题目连接: http://www.codeforces.com/contest/226/problem/D Description Harry Potter has a di ...

  8. Codeforces Round #337 (Div. 2) C. Harmony Analysis 构造

    C. Harmony Analysis 题目连接: http://www.codeforces.com/contest/610/problem/C Description The semester i ...

  9. Codeforces Round #335 (Div. 2) D. Lazy Student 构造

    D. Lazy Student Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/606/probl ...

随机推荐

  1. mac安装Navicat Premium Mac 12 破解版

    参考:https://www.cnblogs.com/lyfstorm/p/11123159.html 激活后:

  2. 怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中

    怎么启用apache的mod_log_sql模块将所有的访问信息直接记录在mysql中

  3. 【ORA】ORA-27090: Unable to reserve kernel resources for asynchronous disk I/O

    操作系统是CentOS 5.11 数据库 10.2.0.5.0 晚上查看数据库,发现数据库报错查看相关的trace文件内容如下: *** SERVICE NAME:(SYS$BACKGROUND) 2 ...

  4. 强制删除 Terminating 状态的pod

    [root@k8s-master coredns]# kubectl get podNAME                     READY   STATUS        RESTARTS   ...

  5. 07--Docker安装Redis

    1.拉取redis:3.2 docker pull redis:3.2 2.创建redis容器 docker run -p 6379:6379 -v /zhengcj/myredis/data:/da ...

  6. Vijos-P1103题解【线段树】

    本文为原创,转载请注明:http://www.cnblogs.com/kylewilson/ 题目出处: https://www.vijos.org/p/1103 题目描述: 一条马路从数轴0到L,每 ...

  7. JVM虚拟机基础

    JVM 全称Java Virtual Machine,也就是我们耳熟能详的Java 虚拟机.它能识别.class 后缀的文件,并且能够解析它的指令,最终调用操作系统上的函数,完成我们想要的操作. Ja ...

  8. 记一次Nginx反向代理500的排查记录

    今天公司项目遇到一个奇怪的问题,记录一下. 注: 数据已经过脱敏处理,未暴露公司具体的IP等数据. TLDR; 项目简单介绍 用 Vue + ElementUI 实现的后台项目(以下简称:a-proj ...

  9. How to Gracefully Close Channels

    小结: 1. When a goroutine sends a value to a channel, we can view the goroutine releases the ownership ...

  10. windows命令行关闭IE代理

    打开:reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnab ...