Hack It

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 548    Accepted Submission(s): 170
Special Judge

Problem Description
Tonyfang is a clever student. The teacher is teaching he and other students "bao'sou".
The teacher drew an n*n matrix with zero or one filled in every grid, he wanted to judge if there is a rectangle with 1 filled in each of 4 corners.
He wrote the following pseudocode and claim it runs in $O(n^2)$:

  1. let count be a 2d array filled with 0s
    iterate through all 1s in the matrix:
    suppose this 1 lies in grid(x,y)
    iterate every row r:
    if grid(r,y)=1:
    ++count[min(r,x)][max(r,x)]
    if count[min(r,x)][max(r,x)]>1:
    claim there is a rectangle satisfying the condition
    claim there isn't any rectangle satisfying the condition

As a clever student, Tonyfang found the complexity is obviously wrong. But he is too lazy to generate datas, so now it's your turn.
Please hack the above code with an n*n matrix filled with zero or one without any rectangle with 1 filled in all 4 corners.
Your constructed matrix should satisfy $1 \leq n \leq 2000$ and number of 1s not less than 85000.

 
Input
Nothing.
 
Output
The first line should be one positive integer n where $1 \leq n \leq 2000$.

n lines following, each line contains only a string of length n consisted of zero and one.

 
Sample Input
(nothing here)
 
Sample Output
3
010
000
000
(obviously it's not a correct output, it's just used for showing output format)
 
Source
 
 分析:昨天听了dls的一顿操作后,顿时觉得有点东西。不过不知道为什么会WA。。。
比如这个矩阵:

10000 10000 10000 10000 10000
10000 01000 00100 00010 00001
10000 00100 00001 01000 00010
10000 00010 01000 00001 00100
10000 00001 00010 00100 01000
11000  11000 11000  11000 11000
01000 00100 00010 00001 10000
01000 00010 10000 00100 00001
01000 00001 00100 10000 00010
01000 10000 00001 00010 00100
01100 01100  01100  01100  01100

其实就是某种意义上的+1,+2,。。。

  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <queue>
  9. #include <deque>
  10. #include <map>
  11. #define range(i,a,b) for(auto i=a;i<=b;++i)
  12. #define LL long long
  13. #define itrange(i,a,b) for(auto i=a;i!=b;++i)
  14. #define rerange(i,a,b) for(auto i=a;i>=b;--i)
  15. #define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
  16. using namespace std;
  17. int grid[][],p=;
  18. void init(){
  19. range(i,,p)range(j,,p)range(k,,p)grid[i*p+j][(j*k+i)%p+k*p]=;
  20. }
  21. void solve(){
  22. puts("");
  23. range(i,,) {
  24. range(j,,){
  25. putchar(grid[i][j]+);
  26. if(!((j+)%))putchar(' ');
  27. }
  28. putchar('\n');
  29. }
  30. }
  31. int main() {
  32. init();
  33. solve();
  34. return ;
  35. }

面向题解编程后,勉强理解了公式。。。这里直接放标程了。。

  1. #include <stdio.h>
  2. int P=,f[],an=,gg[][];
  3. int main()
  4. {
  5. for(int i=;i<P;i++)
  6. {
  7. for(int r=;r<P;++r)
  8. {
  9. ++an;
  10. for(int j=i,k=;k<P;k++,j=(j+r)%P)
  11. f[j*P+k]=an;
  12. for(int j=;j<P*P;++j)
  13. if(f[j]==an) gg[i*P+r][j]=;
  14. }
  15. }
  16. printf("%d\n",);
  17. for(int i=;i<;++i,puts(""))
  18. for(int j=;j<;++j)
  19. putchar(gg[i+][j+]+);
  20. }

HDU 6313: Hack it的更多相关文章

  1. HDU - 6313 Hack It(构造)

    http://acm.hdu.edu.cn/showproblem.php?pid=6313 题意 让你构造一个矩阵使得里面不存在四个顶点都为1的矩形,并且矩阵里面1的个数要>=85000 分析 ...

  2. HDU 6313

    题意略. 思路:数论题. #include<bits/stdc++.h> using namespace std; ; const int maxn = p * p; ][maxn + ] ...

  3. ( 2018 Multi-University Training Contest 2)

    2018 Multi-University Training Contest 2) HDU 6311 Cover HDU 6312 Game HDU 6313 Hack It HDU 6314 Mat ...

  4. codechef: ADAROKS2 ,Ada Rooks 2

    又是道原题... (HDU 6313 Hack It , 多校 ACM 里面的题) 题目说构造一个 n * n 矩阵,染色点不得构成矩形...然后染色点个数至少 8 * n 然后我们生成一个数 m , ...

  5. BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...

  6. BestCoder18 1002.Math Problem(hdu 5105) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5105 题目意思:给出一个6个实数:a, b, c, d, l, r.通过在[l, r]中取数 x,使得 ...

  7. hdu 5264 pog loves szh I

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5264 pog loves szh I Description Pog has lots of stri ...

  8. hdu 5504 GT and sequence

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 GT and sequence Time Limit: 2000/1000 MS (Java/O ...

  9. hdu 5452 Minimum Cut 树形dp

    Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...

随机推荐

  1. 洛谷 P1379 八数码难题 解题报告

    P1379 八数码难题 题目描述 在3×3的棋盘上,摆有八个棋子,每个棋子上标有1至8的某一数字.棋盘中留有一个空格,空格用0来表示.空格周围的棋子可以移到空格中.要求解的问题是:给出一种初始布局(初 ...

  2. CentOS 7, Attempting to create directory /root/perl5

    By francis_hao    Apr 10,2017 在使用CentOS 7的时候,首次登陆会出现新建一个perl5文件夹的提示,删除该文件后,之后登陆还是会出现该提示并新建了perl5文件夹. ...

  3. Java的外部类为什么不能使用private、protected进行修饰

    对于顶级类(外部类)来说,只有两种修饰符:public和默认(default).因为外部类的上一单元是包,所以外部类只有两个作用域:同包,任何位置.因此,只需要两种控制权限:包控制权限和公开访问权限, ...

  4. 关于session variables 和 global variables

    背景 有同学问到这样一个问题:原来的binlog格式是statement,为什么执行了 set global binlog_format='row' 和 set binlog_format='row' ...

  5. Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)

    F. Elongated Matrix 题目链接:https://codeforces.com/contest/1102/problem/F 题意: 给出一个n*m的矩阵,现在可以随意交换任意的两行, ...

  6. TCP ------ keep-alive - 判断TCP链路的连接情况

    TCP 是面向连接的 , 在实际应用中通常都需要检测对端是否还处于连接中.如果已断开连接,主要分为以下几种情况: 1.           连接的对端正常关闭,即使用 closesocket 关闭连接 ...

  7. linux 监控网卡实时流量iftop

    一.安装iftop Centos也可以直接yum install iftop -y http://www.tcpdump.org/release/ 到如下获取libpcap.tcpdump iftop ...

  8. maven工程开启jetty调试

    转摘自:http://czj4451.iteye.com/blog/1942437 准备工作: a. 在pom.xml中配置jetty插件: <plugins> <plugin> ...

  9. 理解JWT(JSON Web Token)认证及python实践

    原文:https://segmentfault.com/a/1190000010312468?utm_source=tag-newest 几种常用的认证机制 HTTP Basic Auth HTTP ...

  10. [05] css优先级

    1.优先级计算规则(特殊性) 在css中,有不同的方式编写css,如果想给同一个标签设置样式,选择器的写法有很多种,那么当多个样式都应用于同一个标签,标签优先选择哪个样式呢?按照以下规则: 现有 0, ...