Codeforces 938C - Constructing Tests
传送门:http://codeforces.com/contest/938/problem/C
给定两个正整数n,m(m≤n),对于一个n阶0-1方阵,其任意m阶子方阵中至少有一个元素“0”,则可以求解这个方阵中的“1”的最大数目。现求解这个问题的逆向问题:已知这个最大数目为X,求相应的n和m。
由原问题可以得到方程:$n^2-\left\lfloor\frac{n}{m}\right\rfloor^2=X\cdots(1)$,于是,对于给定的X,求解不定方程(1)。
令$k=\left\lfloor\frac{n}{m}\right\rfloor$,则$\left\lfloor\frac{n}{k+1}\right\rfloor<\left\lfloor\frac{n}{k}\right\rfloor$时,$\left\lfloor\frac{n}{m}\right\rfloor=k\Rightarrow k\le\frac{n}{m}<k+1\Rightarrow \frac{n}{k+1}<m\le\frac{n}{k}\Rightarrow m=\left\lfloor\frac{n}{k}\right\rfloor$;于是,原方程化为$n^2-k^2=X\Rightarrow (n+k)(n-k)=X\cdots(2)$。
①若X=0,显然n=k,其中的一组解为n=1,m=1;
②若X≠0,则将X分解,设X=a·b(b<a)。
则解不定方程:$u^2-v^2=ab\Rightarrow u=\frac{a+b}{2},v=\frac{a-b}{2}$。
于是,方程(2)可能有解n=u,k=v。
于是,当u、v均为正整数,且$\left\lfloor\frac{u}{v+1}\right\rfloor<\left\lfloor\frac{u}{v}\right\rfloor$时,方程(1)有解:$n=u,m=\left\lfloor\frac{u}{v}\right\rfloor$。
参考程序如下:
#include <stdio.h> int main(void)
{
int t;
scanf("%d", &t);
while (t--) {
int x;
int n = -, m = -;
scanf("%d", &x);
if (x == ) {
n = ;
m = ;
}
else {
for (int i = ; i * i < x; i++) {
int j = x / i;
if (x == i * j && !((i ^ j) & )) {
int u = (j + i) / ;
int v = (j - i) / ;
if (u / v - u / (v + ) > ) {
n = u;
m = u / v;
break;
}
}
}
}
if (n == -) printf("-1\n");
else printf("%d %d\n", n, m);
}
return ;
}
Codeforces 938C - Constructing Tests的更多相关文章
- Codeforces 938.C Constructing Tests
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Constructing Tests CodeForces - 938C
大意: 定义m-free矩阵: 所有$m*m$的子矩阵至少有一个$0$的$01$矩阵. 定义一个函数$f(n,m)=n*n$的m-free矩阵最大$1$的个数. 给出$t$个询问, 每个询问给出$x$ ...
- Educational Codeforces Round 38 (Rated for Div. 2) C
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 38 (Rated for Div. 2)
这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...
- 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解
[比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B Run for your prize[贪心] ...
- Tree Constructing CodeForces - 1003E(构造)
题意: 就是让构造一个直径为d的树 每个结点的度数不能超过k 解析: 先构造出一条直径为d的树枝 然后去遍历这条树枝上的每个点 为每个点在不超过度数和直径的条件下添加子嗣即可 #include & ...
- 【模拟】 Codeforces Round #434 (Div. 1, based on Technocup 2018 Elimination Round 1) C. Tests Renumeration
题意:有一堆数据,某些是样例数据(假设X个),某些是大数据(假设Y个),但这些数据文件的命名非常混乱.要你给它们一个一个地重命名,保证任意时刻没有重名文件的前提之下,使得样例数据命名为1~X,大数据命 ...
- CodeForces - 1003-B-Binary String Constructing (规律+模拟)
You are given three integers aa, bb and xx. Your task is to construct a binary string ssof length n= ...
- Codeforces Round #642 (Div. 3) D. Constructing the Array (优先队列)
题意:有一个长度为\(n\)元素均为\(0\)的序列,进行\(n\)次操作构造出一个新序列\(a\):每次选择最长的连续为\(0\)的区间\([l,r]\),使得第\(i\)次操作时,\(a[\fra ...
随机推荐
- XML消息解析_php
初识php——微信消息处理 <?php $test = new weixin(); $test->Message(); class weixin{ public function Mess ...
- 为什么JavaWeb项目要分层
首先让我们坐着时光机回到n年前的web开发.那个时候最早都是静态的html页面,后来有了数据库,有了所谓的动态页面,然后程序猿在编码的时候,会把所有的代码都写在页面上,包括数据库连接,包括事务控制,接 ...
- UI Design Do's and Don'ts
转载自-Apple 官网,感觉不错,记录之 (https://developer.apple.com/design/tips/) Some useful design tips about IOS. ...
- bzoj 1626: [Usaco2007 Dec]Building Roads 修建道路【最小生成树】
先把已有的边并查集了,然后MST即可 记得开double #include<iostream> #include<cstdio> #include<algorithm&g ...
- Unity项目 - Boids集群模拟算法
1987年Craig W.Reynolds发表一篇名为<鸟群.牧群.鱼群:分布式行为模式>的论文,描述了一种非常简单的.以面向对象思维模拟群体类行为的方法,称之为 Boids ,Boids ...
- SQL 索引篇
索引介绍: 1.索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 数据库索引好比是一本书前面的目录, SQL Server的B树结构 2.加快数据库的查询速 ...
- JDK API文档下载
java SE 8 API文档:http://www.oracle.com/technetwork/java/javase/documentation/jdk8-doc-downloads-21331 ...
- 这样的设计是否有违背MVC设计原则??
MVC 皆知为 Model-View-Controller 请求模型-〉Client发现请求-〉Controller接收+处理-〉返回Model给前端-〉前端接收处理模型Result 但是最近发现一个 ...
- LR接口测试---webservices
//================================================================================== /* //事务开始 lr_st ...
- 前端er怎样操作剪切复制以及禁止复制+破解等
前言 有时候我们经常会碰到这些场景:玩掘金.知乎的时候复制一段文字,总是会在内容后面加上一些版权信息,以及像小说网站等都有禁止选中,禁止复制这种功能,还有点击自动复制账号的功能. 我也经常遇到这些场景 ...