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 ...
随机推荐
- C#面向过程之冒泡排序
//定义一个数组,准备冒泡排序 ,,-,,,,-,}; //定义一个中间变量 ; //n个数字比较需要进行n-1次比较 ; j < arr.Length - - i; j++) { //每一趟的 ...
- win10设置锁屏时间
这里应该修改成自己希望的分钟数 比如120分钟
- IE6的3像素BUG产生条件及解决方法
1.IE6中第一个元素浮动第二个元素不浮动,这两个元素之间就会产生3像素BUG 2.解决方案: 2.1若若宽度一定则给第二个元素添加 float 样式即可: 2.2若宽度自适应: 2.2.1 _ma ...
- Kettle 连接 oracle 报错:could not be found, make sure the 'Oracle' driver (jar file) is installed.
我的ETL版本为6.0 oracle版本为11.2.0 报错如下: Driver class 'oracle.jdbc.driver.OracleDriver' could not be found, ...
- 多条件查询测试用例设计方法(1)—Pairwise(转)
在我的工作中,我也遇到类似需求.正交法是一种不错的选择,而在我们实践过程中,我们还用了Pairwise方法,以及另一种方法(如下): 假设查询因子:A,B,C,D,E 1.单独查询:A:B:C:D:E ...
- react hooks 全面转换攻略(二) react本篇剩余 api
useCallback,useMemo 因为这两个 api 的作用是一样的,所以我放在一起讲; 语法: function useMemo<T>(factory: () => T, d ...
- web界面bug-临时
一.登录页面 二.首页 三.项目 四.项目池 五.专家管理 六.审批 七.日/周报 八.设置
- 01背包(类) UVA 10564 Paths through the Hourglass
题目传送门 /* 01背包(类):dp[i][j][k] 表示从(i, j)出发的和为k的方案数,那么cnt = sum (dp[1][i][s]) 状态转移方程:dp[i][j][k] = dp[i ...
- MySQL replace into 用法(insert into 的增强版)
转 http://blog.csdn.net/risingsun001/article/details/38977797 MySQL replace into 用法(insert into 的增强版) ...
- jquery.autocomplete.js用法及示例,小白进
8 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 ...