HDU 6313: Hack it
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
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.
n lines following, each line contains only a string of length n consisted of zero and one.
010
000
000
(obviously it's not a correct output, it's just used for showing output format)
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的更多相关文章
- HDU - 6313 Hack It(构造)
http://acm.hdu.edu.cn/showproblem.php?pid=6313 题意 让你构造一个矩阵使得里面不存在四个顶点都为1的矩形,并且矩阵里面1的个数要>=85000 分析 ...
- HDU 6313
题意略. 思路:数论题. #include<bits/stdc++.h> using namespace std; ; const int maxn = p * p; ][maxn + ] ...
- ( 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 ...
- codechef: ADAROKS2 ,Ada Rooks 2
又是道原题... (HDU 6313 Hack It , 多校 ACM 里面的题) 题目说构造一个 n * n 矩阵,染色点不得构成矩形...然后染色点个数至少 8 * n 然后我们生成一个数 m , ...
- BestCoder24 1001.Sum Sum Sum(hdu 5150) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5150 题目意思:就是直接求素数. 不过 n = 1,也属于答案范围!!只能说,一失足成千古恨啊---- ...
- 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,使得 ...
- 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 ...
- hdu 5504 GT and sequence
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5504 GT and sequence Time Limit: 2000/1000 MS (Java/O ...
- hdu 5452 Minimum Cut 树形dp
Minimum Cut Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...
随机推荐
- IPVS和Nginx两种WRR负载均衡算法详解
动机 五一临近,四月也接近尾声,五一节乃小长假的最后一天.今天是最后一天工作日,竟然感冒了,半夜里翻来覆去无法安睡,加上窗外大飞机屋里小飞机(也就是蚊子)的骚扰,实在是必须起来做点有意义的事了! ...
- 如何用setInterval调用类的方法
setInterval() 方法可按照指定的周期(以毫秒计)来调用函数或计算表达式.setInterval() 方法会不停地调用函数,直到 clearInterval() 被调用或窗口被关闭.由 se ...
- lhgdialog的传值问题
一前言 今天就离职了,顺便把还没有记载下来得Js有关知识给记载下来,其实这个是lhgdialog.js中的传值问题.就是弹出框选择数据后加载到父页面上,自己用html做了测试. 二:内容 html代码 ...
- c#之字符串函数
1.常用的字符串函数 Compare 比较字符串的内容,考虑文化背景(场所),确定某些字符是否相等 int Compare(string str1,string str2) int Compare(s ...
- jQuery操纵DOM
一.基本操作 1.html() - 类似于原生DOM的innerHTML属性 *获取 - html(); *设置 - html("html代码"); 2.val() - 类似于原生 ...
- bzoj1503: [NOI2004]郁闷的出纳员 fhqtreap版
这道题写法和之前差不多 但是fhqtreap在加点的时候为了同时维护大根堆以及二叉排序树的性质所以插入时也要注意分裂 fhqteap需要判断指针是否为空 不然就会re 这个我调了很久 #include ...
- [BZOJ3033]太鼓达人|欧拉图
Description 七夕祭上,Vani牵着cl的手,在明亮的灯光和欢乐的气氛中愉快地穿行.这时,在前面忽然出现了一台太鼓达人机台,而在机台前坐着的是刚刚被精英队伍成员XLk.Poet_shy和ly ...
- 【洛谷 P1666】 前缀单词 (Trie)
题目链接 考试时暴搜50分...其实看到"单词","前缀"这种字眼时就要想到\(Trie\)的,哎,我太蒻了. 以一个虚点为根,建一棵\(Trie\),然后\( ...
- ShadowBroker公开的SMB远程命令执行漏洞修复
有人不知道如何获得MS对应的补丁KB编号,可以看这篇文章了~ 漏洞编号为ms17-010,如何查看对应MS号的补丁已经安装: 下载微软官方的补丁信息列表(Microsoft Security Bull ...
- 【Mysql优化】key和index区别
mysql的key和index多少有点令人迷惑,这实际上考察对数据库体系结构的了解的. 1).key 是数据库的物理结构,它包含两层意义,一是约束(偏重于约束和规范数据库的结构完整性),二是索引 ...