当前位置:网站首页>(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;
}边栏推荐
- [exercise-4] (UVA 11988) broken keyboard = = (linked list)
- Socket communication
- Perform general operations on iptables
- 双向链表—全部操作
- E. Breaking the Wall
- MySQL import database error [err] 1273 - unknown collation: 'utf8mb4_ 0900_ ai_ ci’
- [exercise 4-1] cake distribution
- [exercise -11] 4 values why sum is 0 (and 4 values of 0)
- Research Report of peripheral venous catheter (pivc) industry - market status analysis and development prospect prediction
- [exercise-5] (UVA 839) not so mobile (balance)
猜你喜欢

Luogu P1102 A-B number pair (dichotomy, map, double pointer)
Frida hook so layer, protobuf data analysis

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

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

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

Openwrt source code generation image
![[exercise-5] (UVA 839) not so mobile (balance)](/img/8e/48dcf75f7347b36301df6fc129c09d.png)
[exercise-5] (UVA 839) not so mobile (balance)

B - Code Party (girls' competition)

Penetration test (1) -- necessary tools, navigation

Gartner: five suggestions on best practices for zero trust network access
随机推荐
Openwrt source code generation image
双向链表—全部操作
1013. Divide the array into three parts equal to and
Opencv learning log 18 Canny operator
[exercise -10] unread messages
X-Forwarded-For详解、如何获取到客户端IP
Socket communication
Opencv learning log 13 corrosion, expansion, opening and closing operations
信息安全-史诗级漏洞Log4j的漏洞机理和防范措施
B - 代码派对(女生赛)
渗透测试 ( 7 ) --- 漏洞扫描工具 Nessus
b站 实时弹幕和历史弹幕 Protobuf 格式解析
Penetration test (8) -- official document of burp Suite Pro
[exercise-8] (UVA 246) 10-20-30== simulation
Penetration test (4) -- detailed explanation of meterpreter command
Programmers, what are your skills in code writing?
Gartner: five suggestions on best practices for zero trust network access
Shell Scripting
Borg maze (bfs+ minimum spanning tree) (problem solving report)
Alice and Bob (2021 Niuke summer multi school training camp 1)