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. 鸟哥linux私房菜学习笔记,U盘安装centos5.3不能正常引导的问题

    前言: 一直都想学习linux,毕竟是做测试的标配.听过鸟哥的linux私房菜大名,作为新手我淘来了第三版,到手看到书的厚度,心都凉了半截,本着不能浪费的原则,还是学吧! 过程:        开始看 ...

  2. while循环语句的几种方式

    我们知道,在Python中经常我们要使用循环,其中最常用的是while循环,while有很多结合方式,我们知道,如果一个循环没有结束语句那么就失去了意义,所以我们一定要有结束语句,下面来看看while ...

  3. 【转】JDBC学习笔记(9)——DBUtils的使用

    转自:http://www.cnblogs.com/ysw-go/ 使用DBUtils提供的功能需要使用commons-dbutils-1.6.jar这个JAR包,在Apache官网可以下载到 使用D ...

  4. Patterns for application development with ASP.NET Core

    此文章翻译自 NDC { London } 16-20 January 2017 上, Damian Edwards和David Fowler的演讲,如果翻译不周,请大家指出错误. Logging 生 ...

  5. JS函数与BOM

    [函数的声明及调用]1.函数声明的格式:function 函数名(参数1,参数2,....){//函数体return结果;}函数名(参数1的值,参数2的值,....)>>>函数的调用 ...

  6. IDEA第一章----下载安装idea,设置背景字体编码,配置JDK/Maven

    写在前面的话: 在程序的世界混迹了5年+,认真过,蹉跎过,回首突然发现自己得到的东西却很少.于是想写点东西记录下学习.工作抑或生活的种种,人生不只是眼前的苟且还有诗和远方,任沧海桑田韶华不在,愿无岁月 ...

  7. mina.net 梳理

    LZ最近离职,闲着也是闲着,打算梳理下 公司做的是电商,CTO打算把2.0系统用java 语言开发,LZ目前不打算做java,所以 选择离职.离职前,在公司负责的最后一个项目 供应链系统. 系统分为 ...

  8. Silverlight的DataGrid合并单元格

    现在也不知道还有没有同学做Silverlight开发了,我是一个Silverlight菜鸟,遇到问题也很难百度查到.就简单的记录一下这两天遇到的问题,并做了一个简单的小Demo,希望能够帮助到其他同学 ...

  9. ES6之"let"能替代"var"吗?

    译者按: 使用let的确会比var安全很多. 原文: Why You Shouldn't Use 'var' Anymore 译者: Fundebug 为了保证可读性,本文采用意译而非直译. 我已经使 ...

  10. 构建你人生里的第一个 Laravel 项目

    安装 Laravel 安装器 composer global require "laravel/installer" 创建项目 laravel new links 检查是否安装成功 ...