HDU 6313 Hack It(构造+数论)

256 篇文章 0 订阅
201 篇文章 10 订阅

Description

给出下面一个代码用来判断一个 n×n n × n 01 01 矩阵中是否存在一个子矩形的四个角的值均为 1 1

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

要求构造一个n×n 01 01 矩形使得 1n2000 1 ≤ n ≤ 2000 且至少有 85000 85000 个位置是 1 1 ,使得其不存在四个角均为1的子矩形但是上述代码的运行结果会判断为存在

Input

Output

输出 n n 以及这个n×n 01 01 矩阵

Sample Input

Sample Output

Solution

显然只要一行有两个 1 1 且不存在四个角都为1的矩形即为反例,问题转化为构造 n n 个序列使得任意两个序列不存在两个都为1的位置

给定 0a,b,c,d<p 0 ≤ a , b , c , d < p ,其中 p p 为素数,假设对于两个不同的k满足 a+kb=c+kd mod p a + k b = c + k d   m o d   p ,则有 a=c,b=d a = c , b = d ,故取不同的二元组 (a,b) ( a , b ) ,通过 a+kb mod p a + k b   m o d   p 可以构造出来 p2 p 2 个长度为 p p 的序列,且这些序列中任意两个序列不存在两个位置的值相同,那么我们取素数47满足 472>2000 47 2 > 2000 ,把 2000 2000 分成若干长度为 47 47 的段,第 k k 段的第a+kb mod p个值为 1 1 ,其余值为0,则可以构造出满足条件的矩阵

Code

#include<cstdio>
using namespace std;
int main()
{
    int n=2000,k=47;
    printf("%d\n",n);
    int num=0;
    for(int i=0;i<k;i++)
        for(int j=0;j<k;j++)
        {
            int m=i*k+j+1;
            if(m<=n)
            {
                int res=0;
                for(int x=0;x<43;x++)
                {
                    int t=(i+x*j)%k+1;
                    for(int l=1;l<=k;l++)
                    {
                        res++;
                        if(l!=t)printf("0");
                        else printf("1");
                        if(res==n)
                        {
                            printf("\n");
                            break;
                        }
                    }
                }
            }
            else break;
        } 
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值