HDU 6313: Hack it
Posted rhythm-
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
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[3005][3005],p=47; void init(){ range(i,0,p)range(j,0,p)range(k,0,p)grid[i*p+j][(j*k+i)%p+k*p]=1; } void solve(){ puts("2000"); range(i,0,1999) { range(j,0,1999){ putchar(grid[i][j]+48); if(!((j+1)%5))putchar(‘ ‘); } putchar(‘ ‘); } } int main() { init(); solve(); return 0; }
面向题解编程后,勉强理解了公式。。。这里直接放标程了。。
#include <stdio.h> int P=47,f[233333],an=0,gg[2333][2333]; int main() { for(int i=0;i<P;i++) { for(int r=0;r<P;++r) { ++an; for(int j=i,k=0;k<P;k++,j=(j+r)%P) f[j*P+k]=an; for(int j=0;j<P*P;++j) if(f[j]==an) gg[i*P+r][j]=1; } } printf("%d ",1999); for(int i=0;i<1999;++i,puts("")) for(int j=0;j<1999;++j) putchar(gg[i+2][j+2]+48); }
以上是关于HDU 6313: Hack it的主要内容,如果未能解决你的问题,请参考以下文章
(You Can Hack It, Architecture and Design) => { Dependency Injection; }
Visual Studio 2015 setup issue with Android SDK – hack it!
2018/7/27 补了一点线段树hack it QAQ...
(You Can Hack It, Architecture and Design) => { Dependency Injection; MEF sample; }