• 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


    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[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;
    }
    View Code

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

    #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);
    }
    View Code
  • 相关阅读:
    WebApi整合Unity容器实现IOC编程
    用户登录
    Mvc验证码
    代理模式 实现aop
    装饰器模式,实现aop
    Redis
    图片缩放
    递归操作文件
    几种文件的读写方式
    C#WebApi自动生成文档
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/9371123.html
Copyright © 2020-2023  润新知