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 ...
随机推荐
- vim配置入门,到豪华版vim配置
这几天一直研究vim的配置,许多版本总是不尽如人意,网上确实有许多优秀的文章值得参考,我的博客后面会贴上具有参考价值的博客链接,本文的将手把手教你配置一个功能详尽的vim. 首先你要明白的是linux ...
- CCmdUI
原文链接地址:http://blog.csdn.net/luicha/article/details/6771185 CCmdUI是一个只被使用于ON_UPDATECOMMAND_UI消息的响应函数中 ...
- BZOJ3289 Mato的文件管理 【莫队 + 树状数组】
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MB Submit: 3964 Solved: 1613 [Submit][Status] ...
- 2017年研究生数学建模D题(前景目标检测)相关论文与实验结果
一直都想参加下数学建模,通过几个月培训学到一些好的数学思想和方法,今年终于有时间有机会有队友一起参加了研究生数模,but,为啥今年说不培训直接参加国赛,泪目~_~~,然后比赛前也基本没看,直接硬刚.比 ...
- 使用adobe pdf去除PDF文档中的批量雷同文本
一.问题的提出 MgoSoft tiff to pdf软件没有提供中国地区的非VISA用户的购买渠道,中国通常都是银联标识走天下,卡不是VISA买不了这样的软件, 那么, MgoSoft tiff t ...
- bzoj 2756 [SCOI2012]奇怪的游戏 二分+网络流
2756:[SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 4926 Solved: 1362[Submit][Stat ...
- 转:安装成功的nginx如何添加未编译安装模块
原已经安装好的nginx,现在需要添加一个未被编译安装的模块 举例说明:安装第三方的ngx_cache_purge模块(用于清除指定URL的缓存) nginx的模块是需要重新编译nginx,而不是像a ...
- spring结合Mybatis的框架搭建(一)
一:前沿 2015年新年上班的第二天,第一天就打了一天的酱油哦,只是下午开始搭建自己毕业设计的框架,搭建的是spring+spring mvc+MyBatis的框架.今天遇到了一个问题,结果弄了我一天 ...
- Ubuntu gnome 16.04下的一些个人配置
虽说并没有改什么,但还是花了我很长时间去搞明白…… 最开始要看下这里,调下比如系统时间等东西 UPD:安装时千万不要对主目录进行加密 1.登录前调整一下触控板和打开小键盘 先打开/etc/gdm3/I ...
- 【洛谷 P1896】[SCOI2005]互不侵犯(状压dp)
题目链接 题意:在N×N的棋盘里面放K个国王,使他们互不攻击,共有多少种摆放方案.国王能攻击到它上下左右,以及左上左下右上右下八个方向上附近的各一个格子,共8个格子. 这是道状压\(DP\)好题啊.. ...