@HDU 6313 @2018杭电 多校第二次 Hack it

Hack It

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 418    Accepted Submission(s): 119
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(n2):

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≤n≤2000 and number of 1s not less than 85000.

 

 

Input

Nothing.

 

 

Output

The first line should be one positive integer n where 1≤n≤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)

 

 

 

构造题,

大佬就是大佬., 看的视频讲解, 真丶划水..

 

题意:

构造一个n*n 的矩阵 满足, 任意一个子矩阵 的4个角 不能全是1 , 且满足 1 的个数>= 85000.

n = 5,  1的位置 在 j 上 依次 + 0,1,2,3,4,5......   mod n 的 意义下

+0 : 10000 10000 10000 10000 10000

+1 : 10000 01000 00100 00010 00001

+2 : 10000 00100 00001 01000 00010

+3 : 10000 00010 01000 00001 00100

+4 : 10000 00001 00010 00100 01000

sqrt(2000) 最接近的质数是47 , 为的 时 构造不会重复, 所以使用质数,

可以看出分块,  每一块 保证 是不重复的, 

构造代码 借鉴 dls 的,  

哇的就哭出来了.jpg   不会构造哇.jpg

代码:

#include <bits/stdc++.h>
#include <stdlib.h>
#include <utility>
#define findx(x,b,n) lower_bound(b+1,b+1+n,x)-b
#define FIN      freopen("input.txt","r",stdin)
#define FOUT     freopen("output.txt","w",stdout)
#define SHUT ios_base::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(20); cout.tie(nullptr); cin.tie(nullptr);
#define lson rt << 1, l, mid
#define rson rt << 1|1, mid + 1, r

#pragma comment(linker, "/STACK:1024000000,1024000000")  // 扩栈
//next_permutation(a+1,a+x) 全排列
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())

using namespace std;

typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;


const double PI=acos(-1.0);
const ll INF=0x3f3f3f3f;
const double esp=1e-6;
const int maxn=1e6+5;
const int MOD=1e9+7;
const int mod=1e9+7;
int dir[5][2]={0,1,0,-1,1,0,-1,0};


inline void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){ x=1; y=0; d=a; }else{ ex_gcd(b,a%b,d,y,x); y-=x*(a/b);};}
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll ans=exgcd(b,a%b,x,y);ll temp=x;x=y;y=temp-a/b*y;return ans;}
inline ll lcm(ll a,ll b){ return b/gcd(a,b)*a;}

inline ll inv_exgcd(ll a,ll n){ll d,x,y;ex_gcd(a,n,d,x,y);return d==1?(x+n)%n:-1;}
inline ll inv1(ll b){return b==1?1:(MOD-MOD/b)*inv1(MOD%b)%MOD;}


/*********************************head************************/

/*
 * Author : siz
 */

int maps[3000][3000];
int n = 47;
int main()
{
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            rep(k,0,n)
            {
                maps[i*n+j][ k*n+(j*k+i)%n ] = 1;
            }
        }
    }
    cout<<2000<<endl;
    rep(i,0,2000)
    {
        rep(j,0,2000)
        {
            cout<<maps[i][j];
        }
        cout<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值