Educational Codeforces Round 38 (Rated for Div. 2) C
1 second
256 megabytes
standard input
standard output
Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero.
Consider the following problem:
You are given two integers n and m. You have to construct an m-free square matrix of size n × n such that the number of 1's in this matrix is maximum possible. Print the maximum possible number of 1's in such matrix.
You don't have to solve this problem. Instead, you have to construct a few tests for it.
You will be given t numbers x1, x2, ..., xt. For every
, find two integers ni and mi (ni ≥ mi) such that the answer for the aforementioned problem is exactly xi if we set n = ni and m = mi.
The first line contains one integer t (1 ≤ t ≤ 100) — the number of tests you have to construct.
Then t lines follow, i-th line containing one integer xi (0 ≤ xi ≤ 109).
Note that in hacks you have to set t = 1.
For each test you have to construct, output two positive numbers ni and mi (1 ≤ mi ≤ ni ≤ 109) such that the maximum number of 1's in a mi-free ni × ni matrix is exactly xi. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test, output a single integer - 1.
3
21
0
1
5 2
1 1
-1
思路
一个n*n的矩阵(由01组成)分成若干个m*m的矩阵,每个m*m的矩阵中0的个数不得小于1.那么每一行都至少有n/m个0,每一列也是至少n/m个0,
可以推出公式 x = n*n - (n/m)*(n/m) 分解可得 x = (n - n.m)*(n + n/m) 然后直接对于x因式分解 设 x = a*b ,a = (n-n/m),b = (n + n/m).然后暴力枚举a,b
由 a + b 可以得出 a + b = 2*n; n/m = sqrt(n*n - x); 则 m = n/sqrt(n*n - x).....根据枚举的ab,看能否求出符合条件的n , m,如果没有的话就输出-1。
实现代码:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,x;
cin>>n;
while(n--){
cin>>x;
ll flag = ;
if(x==){ cout<<<<" "<<<<endl;continue;}
for(ll i = ;i*i <= x;i++){
if(x%i==){
if((i+x/i)%==) continue;
ll n1 = (i + x/i)/;
ll m = n1*n1 - x;
ll m1 = sqrt(m);
if(m1*m1 != m||n1==||m1==) continue;
if(n1*n1 - (n1/(n1/m1)*(n1/(n1/m1)))!=x) continue;
cout<<n1<<" "<<n1/m1<<endl;
flag = ;
break;
}
}
if(!flag) cout<<-<<endl;
}
return ;
}
Educational Codeforces Round 38 (Rated for Div. 2) C的更多相关文章
- 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[贪心] ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
随机推荐
- linux 文件夹和文件操作
1.统计目录有多少个文件数 find ./company -type f | wc -l 2.删除文件夹中的文件 rm -f * #最经典的方法,删除当前目录下的所有类型的文件 rsync --del ...
- spring-boot dubbo项目使用docker方式部署
项目结构 本项目采用maven构建,有三个模块,分别是pms-interfaces, pms-services, pms-portal. 模块 描述 pms-interfaces 接口层,只能存放实体 ...
- 2017-2018-2 20155315《网络对抗技术》Exp8 :Web基础
实验目的 理解HTML,学会Web前端.Web后端和数据库编程及SQL注入.XSS攻击测试 教程 实验内容 操作程序规律 运行脚本或可执行文件 查看配置文件 出错找日志 Web前端HTML 能正常安装 ...
- WPF编程,将控件所呈现的内容保存成图像的一种方法。
原文:WPF编程,将控件所呈现的内容保存成图像的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/detai ...
- 关于Trie的一些算法
最近学习了一下关于Trie的一些姿势,感觉很实用. 终于不用每次看到字符串判重等操作就只想到hash了 关于Trie的定义,来自百度百科 在计算机科学中,Trie,又称前缀树或字典树,是一种有序树状的 ...
- 未能使用“Csc”任务的输入参数初始化该任务
今天.NetCore2.1版本,建立Asp.net Core web应用程序项目时,报以下错误: 未能使用“Csc”任务的输入参数初始化该任务. “Csc”任务不支持“SharedCompilatio ...
- [C#]使用Join与GroupJoin将两个集合进行关联与分组
本文为原创文章.源代码为原创代码,如转载/复制,请在网页/代码处明显位置标明原文名称.作者及网址,谢谢! 本文使用的开发环境是VS2017及dotNet4.0,写此随笔的目的是给自己及新开发人员作为参 ...
- Jenkins Maven安装设置
Jenkins Maven安装设置 如果没有学习过 Maven 的朋友,可以先了解 Maven教程,然后再进一步学习本教程文章. 第1步:下载和设置Maven Maven的官方网站就是Apache M ...
- metasploit学习之情报搜集
3.1.被动信息搜集whois查询Netcraft nslookup>set type=mx>testfire.net Google Hacking 3.2 主动信息搜集 使用nmap进行 ...
- 就qq软件的优缺点
qq对于现在的人来说,可谓是无所不知的,这也使得它迅速融入到人们的生活中,但它也是一把双刃剑,就优缺点我进行一下举例说明: 它的优点:qq由最初设计的一种聊天工具现在已经发展成为一个很全面多用途的工具 ...