POJ 3685 二分套二分
Matrix
Given a N × N matrix A, whose element in the i-th row and j-th column Aij is an number that equals i2 + 100000 × i + j2 - 100000 × j + i × j, you are to find the M-th smallest element in the matrix.
Input
The first line of input is the number of test case.
For each test case there is only one line contains two integers, N(1 ≤ N ≤ 50,000) and M(1 ≤ M ≤ N × N). There is a blank line before each test case.
Output
For each test case output the answer on a single line.
Sample Input
12 1 1 2 1 2 2 2 3 2 4 3 1 3 2 3 8 3 9 5 1 5 25 5 10
Sample Output
3 -99993 3 12 100007 -199987 -99993 100019 200013 -399969 400031 -99939
代码:
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define db double
using namespace std;
;
;
ll f(ll x,ll y)
{
*x+y*y-*y+x*y);
}
ll n,m;
ll cal(ll x){
ll cnt=,ans=;
;i<=n;i++){
ll sl=,sr=n;
while (sl<=sr){
ll mid=(sr+sl)/;
if(f(mid,i)<=x){
ans=mid;
sl=mid+;
}
;
}
cnt+=ans;
}
return cnt;
}
int main(){
int t;
scanf("%d",&t);
while (t--)
{
scanf("%lld%lld",&n,&m);
ll l=-*n,r=n*n+*n+n*n+n*n;
ll ans=;
while (l<=r){
ll mid=(l+r)/;
;}
;}
}
printf("%lld\n",ans);
}
;
}
POJ 3685 二分套二分的更多相关文章
- poj 3685 Matrix 二分套二分 经典题型
Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 5724 Accepted: 1606 Descriptio ...
- poj 3579 Median 二分套二分 或 二分加尺取
Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5118 Accepted: 1641 Descriptio ...
- poj3579 二分套二分
和poj3685类似,都是二分答案然后在判断时再二分 这题的内层二分可以用stl代替 /* 二分套二分,思路:升序排序数据,先二分答案x进行判断,判断时枚举每个元素,二分找到和其之差小于等于x的所有值 ...
- POJ-3579 Median---二分第k大(二分套二分)
题目链接: https://cn.vjudge.net/problem/POJ-3579 题目大意: 求的是一列数所有相互之间差值的序列的最中间的值是多少. 解题思路: 可以用二分套二分的方法求解第m ...
- POJ 3685 Matrix (二分套二分)
Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8674 Accepted: 2634 Descriptio ...
- poj 3685 Matrix 【二分】
<题目链接> 题目大意: 给你一个n*n的矩阵,这个矩阵中的每个点的数值由 i2 + 100000 × i + j2 - 100000 × j + i × j 这个公式计算得到,N( ...
- POJ 3685:Matrix 二分
Matrix Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 5489 Accepted: 1511 Descriptio ...
- 二分套二分 hrbeu.acm.1211Kth Largest
Kth Largest TimeLimit: 1 Second MemoryLimit: 32 Megabyte Description There are two sequences A and ...
- poj3685 二分套二分
F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS Memory Limit:65536KB 64bit ...
随机推荐
- 你不得不知的逻辑或(||)与(&&)非(!)
最近重新翻开原生JS,又得到很多不同的体会,虽然现在开发框架那么多,但很多思想都还是离不开原生的基础.今天呢,我就根据自己的学习总结一下逻辑与(&&)和(逻辑或(||)和逻辑非(!). ...
- loopj.com android-async-http
loopj.com android-async-http Android异步Http客户端 用于Android的基于回调的Http客户端库 下载版本1.4.9(最新) 或者在github上fork ...
- sql中如何分割字符串
使用方式: SELECT AllItem AS BldGUID FROM dbo.fn_split('01.02.03','.') 函数: GO )) )) --实现split功能 的函数 as ...
- SQL基础增删改查
一.基础语句介绍 SQL 可以分为两个部分:数据操作语言(DML)和数据定义语言(DDL) 1.数据操作语言(DML)基本指令: select 从数据表中获取数据(现阶阶段,二次开发常用) ...
- js中元素(图片)切换和隐藏显示问题
这个知识点其实也简单,(当然是在理清思路的情况下),在没预习的情况下听的还真是艰难,上课以来唯一的一次懵逼了一天,感觉乱乱的,全是新属性,所以今晚的我破天荒的熬夜敲代码,一定要弄懂! 现在就来梳理下头 ...
- 【转载】32复用时钟AFIO开启情况
原文:http://blog.csdn.net/u012411027/article/details/44217313 百度了很多结果,打开看几乎全是下面这篇文章,真是天下文章一大抄啊.我也抄一下吧. ...
- 业务订单号生成算法,每秒50W左右,不同机器保证不重复,包含日期可读性好
参考snowflace算法,基本思路: 序列12位(更格式化的输出后,性能损耗导致每毫秒生成不了这么多,所以可以考虑减少这里的位,不过留着也并无影响) 机器位10位 毫秒为左移 22位 上述几个做或运 ...
- 商城项目实战 | 2.1 Android 仿京东商城——自定义 Toolbar (一)
前言 本文为菜鸟窝作者刘婷的连载."商城项目实战"系列来聊聊仿"京东淘宝的购物商城"如何实现. 现在很多的 APP 里面都有自己的自定义风格,特别是京东商城中自 ...
- xmlplus 组件设计系列之六 - 下拉刷新
"下拉刷新"由著名设计师 Loren Brichter 设计,并应用于 Twitter 第三方应用 Tweetie 中.2010年4月,Twitter 收购 Tweetie 开发商 ...
- 磁盘IO:缓存IO与直接IO
文件系统IO分为DirectIO和BufferIO,其中BufferIO也叫Normal IO. 1. 缓存IO 缓存I/O又被称作标准I/O,大多数文件系统的默认I/O操作都是缓存I/O.在Linu ...