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 二分套二分的更多相关文章

  1. poj 3685 Matrix 二分套二分 经典题型

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 5724   Accepted: 1606 Descriptio ...

  2. poj 3579 Median 二分套二分 或 二分加尺取

    Median Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5118   Accepted: 1641 Descriptio ...

  3. poj3579 二分套二分

    和poj3685类似,都是二分答案然后在判断时再二分 这题的内层二分可以用stl代替 /* 二分套二分,思路:升序排序数据,先二分答案x进行判断,判断时枚举每个元素,二分找到和其之差小于等于x的所有值 ...

  4. POJ-3579 Median---二分第k大(二分套二分)

    题目链接: https://cn.vjudge.net/problem/POJ-3579 题目大意: 求的是一列数所有相互之间差值的序列的最中间的值是多少. 解题思路: 可以用二分套二分的方法求解第m ...

  5. POJ 3685 Matrix (二分套二分)

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8674   Accepted: 2634 Descriptio ...

  6. poj 3685 Matrix 【二分】

    <题目链接> 题目大意: 给你一个n*n的矩阵,这个矩阵中的每个点的数值由   i2 + 100000 × i + j2 - 100000 × j + i × j  这个公式计算得到,N( ...

  7. POJ 3685:Matrix 二分

    Matrix Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 5489   Accepted: 1511 Descriptio ...

  8. 二分套二分 hrbeu.acm.1211Kth Largest

    Kth Largest TimeLimit: 1 Second   MemoryLimit: 32 Megabyte Description There are two sequences A and ...

  9. poj3685 二分套二分

    F - 二分二分 Crawling in process... Crawling failed Time Limit:6000MS     Memory Limit:65536KB     64bit ...

随机推荐

  1. myeclipse2015复制项目需要修改的地方

    项目下  D:\Workspaces\MyEclipse 2015\angular001\.settings  的org.eclipse.wst.common.component文件,修改里面未原来的 ...

  2. idea 集成sonarLint

    1.目标 idea集成sonar的代码检查,实现可以在提交代码前就检查你的代码,而不是将代码提交之后,之后再去检查. Sonar可以从以下七个维度检测代码质量,而作为开发人员至少需要处理前5种代码质量 ...

  3. ZJOI2017 Round#2 滚粗记

    在杭州的火车站的KFC餐厅里,独自一人,闲来无事,便写写这篇博客.刚刚的一个礼拜,经历了余姚的省选和杭州的数学集训,感觉有些浪,学校里现在还在上新课,我已经落下一个礼拜的文化课了,回去估计补死:最重要 ...

  4. unity collider 和 trigger 触发条件

    物体A,物体B(都含有collider组件) collider触发条件:A和B至少一方是  未勾选is Kinematic的rigidbody,且都未勾选 is trigger.当只有一方是rigid ...

  5. java线程(一)

    java线程基础 什么是线程? 这里引用百度百科的一句话:"线程,有时被称为轻量级进程(Lightweight Process,LWP),是程序执行流的最小单元.一个标准的线程由线程ID,当 ...

  6. jquery的ajax与spring mvc对接注意事项

    昨天一直纠结这么一个问题,应用场景是这样的: 这里登陆是通过jquery的ajax传输数据到后台controller类相应的映射mapping接收.本来是想,在后台验证成功之后返回一个视图modelA ...

  7. Charles抓取https请求详解

    大家好,我是TT,互联网测试行业多年,没有牛逼的背景,也没有什么可炫耀的,唯独比他人更努力,在职场打拼.遇到过的坑,走过的弯路,愿意与大家分享,分享自己的经验,少走弯路.首发于个人公众号[测试架构师] ...

  8. WebGIS开源解决方案之环境搭建(二)

    续上篇,本文主要介绍开源GIS数据库产品postgres的安装, 从postgis官网下载安装文件,下载地址http://postgis.net 本文一postgresql-9.4.4-3-windo ...

  9. Apache网站服务源码安装与站点部署

    简介: 在Internet 网络环境中,Web服务无疑是最为主流的应用系统,有了WEB站点,企业可以充分展示自己的产品,公司,宣传自己的企业形象,提供各种网上交流,业务平台等. Apache起源:源于 ...

  10. Integer浅谈

    别BB,亮代码. 结果: 结果分析: 1.true 相信大家对第一个的比较结果应该不意外,只是单纯的数值比较 2.true 这个和第三个结果一比较起来就感觉迷惑了,明明两个都是同样的赋值方式,为什么一 ...