当前位置:网站首页>(POJ - 3685) matrix (two sets and two parts)
(POJ - 3685) matrix (two sets and two parts)
2022-07-06 16:08:00 【AC__ dream】


Chinese question meaning : There is one N Square matrix The first i That's ok ,j The value of the column Aij =i^2 + 100000 × i + j^2 - 100000 × j + i × j, We need to find out the third part of this matrix M Small value .
Looking at this equation first, we can find ,Aij along with i To increase by , So we can pass two points x To find out , The content of every two points is to judge the ratio x Whether the number of small numbers is greater than or equal to m, If the number is greater than or equal to m, Then the current binary value is greater than or equal to the answer , On the contrary, the current binary value is less than the answer , The specific dichotomy process is as follows :
We enumerate columns violently , The number of each column is monotonically increasing , So for each column, we can enumerate in two , The total complexity is n*log(n)*log(q)(q Is the range size of the possible values of the answer ), There are quite a lot of details , The code is attached below
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
ll n,m;
ll cal(ll i,ll j)
{
return i*i+100000*i+j*j-100000*j+i*j;
}
bool check(ll x)// If it is less than or equal to x The number of is greater than or equal to m One returns true, Instead, return to false
{
ll cnt=0;
for(int i=1;i<=n;i++)// Enumerating columns
{
ll l=0,r=n,mid;// Binary enumeration, each column is less than x The number of numbers
if(l==r) return cal(1,1)<=x;
while(l<r)
{
mid=l+r+1>>1;
if(cal(mid,i)<=x) l=mid;// Find a value greater than or equal to x The last number of
else r=mid-1;
}
cnt+=l;
if(cnt>=m) return true;
}
return false;
}
int main()
{
int T;
cin>>T;
while(T--)
{
cin>>n>>m;
ll l=-9999999999,r=9999999999,mid;// Enumerator
while(l<r)
{
mid=l+r>>1;
if(check(mid)) r=mid;// explain mid Larger
else l=mid+1;
}
printf("%lld\n",l);
}
return 0;
}边栏推荐
- The most complete programming language online API document
- Nodejs crawler
- 【练习-8】(Uva 246)10-20-30==模拟
- [exercise-9] Zombie's Treasury test
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- JS调用摄像头
- Opencv learning log 13 corrosion, expansion, opening and closing operations
- Socket communication
- 信息安全-威胁检测引擎-常见规则引擎底座性能比较
- Opencv learning log 29 -- gamma correction
猜你喜欢

Web based photo digital printing website

STM32 how to use stlink download program: light LED running light (Library version)
![[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class](/img/57/bc6eda91f7263acda38b9ee8732318.png)
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class

Information security - threat detection engine - common rule engine base performance comparison

信息安全-安全编排自动化与响应 (SOAR) 技术解析

Borg maze (bfs+ minimum spanning tree) (problem solving report)
Frida hook so layer, protobuf data analysis

Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability

D - function (HDU - 6546) girls' competition
![[exercise-7] crossover answers](/img/66/3dcba2e70a4cd899fbd78ce4d5bea2.png)
[exercise-7] crossover answers
随机推荐
Ball Dropping
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
【练习-2】(Uva 712) S-Trees (S树)
Opencv learning log 28 -- detect the red cup cover
frida hook so层、protobuf 数据解析
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
Common configuration files of SSM framework
Research Report of exterior wall insulation system (ewis) industry - market status analysis and development prospect prediction
渗透测试 ( 8 ) --- Burp Suite Pro 官方文档
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
CEP used by Flink
409. Longest palindrome
Opencv learning log 32 edge extraction
[exercise-6] (UVA 725) division = = violence
【练习-7】Crossword Answers
F - birthday cake (Shandong race)
【高老师UML软件建模基础】20级云班课习题答案合集
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
E. Breaking the Wall
1903. Maximum odd number in string