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)$:

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,。。。

#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#define range(i,a,b) for(auto i=a;i<=b;++i)
#define LL long long
#define itrange(i,a,b) for(auto i=a;i!=b;++i)
#define rerange(i,a,b) for(auto i=a;i>=b;--i)
#define fill(arr,tmp) memset(arr,tmp,sizeof(arr))
using namespace std;
int grid[][],p=;
void init(){
range(i,,p)range(j,,p)range(k,,p)grid[i*p+j][(j*k+i)%p+k*p]=;
}
void solve(){
puts("");
range(i,,) {
range(j,,){
putchar(grid[i][j]+);
if(!((j+)%))putchar(' ');
}
putchar('\n');
}
}
int main() {
init();
solve();
return ;
}

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

#include <stdio.h>
int P=,f[],an=,gg[][];
int main()
{
for(int i=;i<P;i++)
{
for(int r=;r<P;++r)
{
++an;
for(int j=i,k=;k<P;k++,j=(j+r)%P)
f[j*P+k]=an;
for(int j=;j<P*P;++j)
if(f[j]==an) gg[i*P+r][j]=;
}
}
printf("%d\n",);
for(int i=;i<;++i,puts(""))
for(int j=;j<;++j)
putchar(gg[i+][j+]+);
}

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. [Leetcode] String to integer atoi 字符串转换成整数

    Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...

  2. BZOJ5323 [Jxoi2018]游戏 【数论/数学】

    题目链接 BZOJ5323 题解 有一些数是不能被别的数筛掉的 这些数出现最晚的位置就是该排列的\(t(p)\) 所以我们只需找出所有这些数,线性筛一下即可,设有\(m\)个 然后枚举最后的位置 \[ ...

  3. java AWT repaint paint update 方法

    paint(Graphic g): awt调用这个方法有2种形式.程序驱动方式和系统驱动方式. 在系统驱动的情况下(比如界面第一次显示组件),系统会判断组件的显示区域,然后向事件分发线程发出调用pai ...

  4. HTTP请求中同步与异步有什么不同

    普通的B/S模式就是同步,而AJAX技术就是异步,当然XMLHttpReques有同步的选项. 同步:提交请求->等待服务器处理->处理完毕返回.这个期间客户端浏览器不能干任何事. 异步: ...

  5. hive对有特殊值null的数据倾斜处理

    对有特殊值的数据倾斜处理 SET mapred.reduce.tasks=20;SET hive.map.aggr=TRUE;SET hive.groupby.skewindata=TRUE;SET ...

  6. [CVPR2018]Learning to Adapt Structured Output Space for Semantic Segmentation

    学习适应结构化输出空间进行语义分割 在语义分割场景中,虽然物体在外表上不同,但是他们的输出是结构化且共享很多例如空间分布, 局部内容等信息.所以作者提出了multi-level的输出空间adaptat ...

  7. php文件上传错误代码

    注意: 1.上传文件的时候,在html里面的form表单一定要标注:enctype='multipart/form-data' 2.有种说法,要求一定要在form表单里面,在file前面加上隐藏域如: ...

  8. js中Date()对象详解

    var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整的年份(4位,1970-???? ...

  9. [转载]解决clickonce不支持administer权限问题

    转自ClickOnce deployment vs. requestedExecutionLevel = requireAdministrator ClickOnce方式部署应用简单方便,估计很多人都 ...

  10. [bzoj2186][Sdoi2008]沙拉公主的困惑——数论

    题目大意 求 \[\sum_{i = 1}^{N!} [gcd(i, M!) = 1]\] 题解 显然,题目就是求 \[N!(1-\frac{1}{p_1})(1-\frac{1}{p_2})...\ ...