当前位置:网站首页>(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;
}边栏推荐
- Analyse du format protobuf du rideau en temps réel et du rideau historique de la station B
- [exercise-6] (PTA) divide and conquer
- nodejs爬虫
- Opencv learning log 18 Canny operator
- Quick to typescript Guide
- 1005. Maximized array sum after K negations
- 409. Longest palindrome
- 【练习-8】(Uva 246)10-20-30==模拟
- Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
- Interval sum ----- discretization
猜你喜欢

409. Longest palindrome

1005. Maximized array sum after K negations

b站 实时弹幕和历史弹幕 Protobuf 格式解析

信息安全-威胁检测-NAT日志接入威胁检测平台详细设计

1903. Maximum odd number in string

Vs2019 initial use

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

921. Minimum additions to make parentheses valid

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

Ball Dropping
随机推荐
[exercise-7] (UVA 10976) fractions again?! (fraction split)
D - function (HDU - 6546) girls' competition
The concept of C language array
Opencv learning log 15 count the number of solder joints and output
[analysis of teacher Gao's software needs] collection of exercises and answers for level 20 cloud class
C language must memorize code Encyclopedia
Hdu-6025-prime sequence (girls' competition)
Common configuration files of SSM framework
栈的经典应用—括号匹配问题
[teacher Gao UML software modeling foundation] collection of exercises and answers for level 20 cloud class
【高老师软件需求分析】20级云班课习题答案合集
【练习-5】(Uva 839)Not so Mobile(天平)
【练习-7】Crossword Answers
Borg Maze (BFS+最小生成树)(解题报告)
Differential (one-dimensional, two-dimensional, three-dimensional) Blue Bridge Cup three body attack
Interesting drink
Write web games in C language
【练习-6】(PTA)分而治之
Determine the Photo Position
Interval sum ----- discretization