当前位置:网站首页>(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;
}边栏推荐
- Opencv learning log 28 -- detect the red cup cover
- [exercise 4-1] cake distribution
- Opencv learning log 15 count the number of solder joints and output
- Information security - threat detection - Flink broadcast stream broadcaststate dual stream merging application in filtering security logs
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- 渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
- B - Code Party (girls' competition)
- Opencv learning log 31 -- background difference
- What is the difficulty of programming?
- 409. Longest palindrome
猜你喜欢

b站 實時彈幕和曆史彈幕 Protobuf 格式解析

渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具

Penetration test (3) -- Metasploit framework (MSF)

Analysis of protobuf format of real-time barrage and historical barrage at station B

C language learning notes

Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool

【练习-5】(Uva 839)Not so Mobile(天平)

Information security - threat detection - detailed design of NAT log access threat detection platform

【高老师UML软件建模基础】20级云班课习题答案合集

“鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
随机推荐
[exercise-7] crossover answers
[exercise -10] unread messages
Ball Dropping
Research Report on market supply and demand and strategy of China's earth drilling industry
STM32 how to use stlink download program: light LED running light (Library version)
1013. Divide the array into three parts equal to and
Penetration test (2) -- penetration test system, target, GoogleHacking, Kali tool
Penetration test 2 --- XSS, CSRF, file upload, file inclusion, deserialization vulnerability
[exercise-1] (UVA 673) parentheses balance/ balanced brackets (stack)
【练习-5】(Uva 839)Not so Mobile(天平)
Nodejs crawler
树莓派4B安装opencv3.4.0
Analysis of protobuf format of real-time barrage and historical barrage at station B
[exercise-8] (UVA 246) 10-20-30== simulation
【练习-2】(Uva 712) S-Trees (S树)
Interesting drink
树莓派CSI/USB摄像头使用mjpg实现网页摄像头监控
【练习-7】(Uva 10976)Fractions Again?!(分数拆分)
7-1 understand everything (20 points)
JS调用摄像头