poj3685 Matrix
思路:
二分套二分。
矩阵在每一列上是严格递增的,可以利用这一点进行二分。
实现:
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll n, m;
ll cal(ll i, ll j)
{
return i * i + i * + j * j - j * + i * j;
}
bool check(ll x)
{
ll sum = ;
for (int i = ; i <= n; i++)
{
int l = , r = n, ans = ;
while (l <= r)
{
int m = l + r >> ;
ll tmp = cal(m, i);
if (tmp <= x) { ans = m; l = m + ; }
else r = m - ;
}
sum += ans;
}
return sum >= m;
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%lld %lld", &n, &m);
ll l = INF, r = -INF, ans = -INF;
for (int i = ; i <= n; i++)
{
l = min(l, cal(, i));
r = max(r, cal(n, i));
}
while (l <= r)
{
ll m = l + r >> ;
if (check(m)) { ans = m; r = m - ; }
else l = m + ;
}
printf("%lld\n", ans);
}
return ;
}
poj3685 Matrix的更多相关文章
- POJ3685 Matrix —— 二分
题目链接:http://poj.org/problem?id=3685 Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissio ...
- POJ3685 Matrix(嵌套二分)
同行元素递减,同列元素递增,采用嵌套二分的方法 #include<cstdio> #include<iostream> #include<cstdlib> #inc ...
- Day3-P - Matrix POJ3685
Given a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i ...
- Matrix [POJ3685] [二分套二分]
Description 有一个N阶方阵 第i行,j列的值Aij =i2 + 100000 × i + j2 - 100000 × j + i × j,需要找出这个方阵的第M小值. Input 第一行输 ...
- 【POJ - 3685】Matrix(二分)
Matrix Descriptions 有一个N阶方阵 第i行,j列的值Aij =i2 + 100000 × i + j2 - 100000 × j + i × j,需要找出这个方阵的第M小值. In ...
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
- Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
- Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
随机推荐
- leetcode:283. Move Zeroes(Java)解答
转载请注明出处:z_zhaojun的博客 原文地址:http://blog.csdn.net/u012975705/article/details/50493772 题目地址:https://leet ...
- Swift开发--Storyboard的使用教程
假设App中包含非常多不同的页面,使用Storyboard能够帮你降低实现页面间跳转的胶合代码. 过去的开发人员相应每一个视图控制器分别创建界面设计文件(即"nib"或" ...
- What to do about Eclipse's “No repository found containing: …” error messages?
As Mauro said: "you have to remove and re-add the Eclipse Project Update site, so that its meta ...
- HDU 5405 Sometimes Naive 树链剖分+bit*****
Sometimes Naive Problem Description Rhason Cheung had a naive problem, and asked Teacher Mai for h ...
- docker启动centos容器后如何用putty连接
在前面的文章中,我提到过,win10 docker启动容器时,只有配置了宿主机和docker容器的端口映射,外部应用才能访问到容器中的服务,比如映射到Nginx的80端口.现在我将宿主机的某个端口映射 ...
- maven工具使用
一.工具安装: 所需工具 : JDK 1.8Maven 3.3.3 1.安装JDK 和 JAVA_HOME 2.添加 M2_HOME 和 MAVEN_HOME 3.添加到环境变量 - PATH 4.验 ...
- 线程之间的通信socketpair【学习笔记】【原创】
平台信息:内核:linux3.1.0系统:android5.0平台:tiny4412 作者:庄泽彬(欢迎转载,请注明作者) 说明: 韦老师的安卓视频学习笔记 一.在一个进程中多个线程如何进行通信,主要 ...
- 连通图(Tarjan算法) 专题总结
一.题目类型: 1.有向图的强连通分量: POJ1236 Network of Schools HDU1269 迷宫城堡 2.割点 & 割边: UESTC - 900 方老师炸弹 UVA315 ...
- 添加数据成功之后,通过true、false决定是否跳转
/** * 新增版本 * * @return */ public String AddVersionInfo() { // 快捷菜单 Integer code = Integer.parseInt(g ...
- HDU4704:Sum(欧拉降幂公式)
Input 2 Output 2 Sample Input 2 由公式,ans=2^(N-1)%Mod=2^((N-1)%(Mod-1)+(Mod-1)) %Mod. 注意:降幂的之后再加一个Mod- ...