本文共 821 字,大约阅读时间需要 2 分钟。
同行元素递减,同列元素递增,采用嵌套二分的方法
#include #include #include #include #include #include #include #include #include #include #include using namespace std;typedef __int64 LL;LL n, m;LL F(LL l, LL r){ return l * l + 100000 * l + r * r - 100000 * r + l *r;}LL solve(LL x){ LL sum = 0; for(int i = 1; i <= n; i++){ int l = 1, r = n + 1; while(l < r){ LL mid = (l + r)>>1; if(F(mid, i) > x){ r = mid; }else{ l = mid + 1; } } sum += l - 1; } return sum;}int main(){ int t; cin>>t; while(t--){ cin>>n>>m; LL l = -100000*n, r = n*n+100000*n+n*n+n*n; while(l < r){ LL mid = (l + r) >> 1; if(solve(mid) < m){ l = mid + 1; }else{ r = mid; } } cout< <<'\n'; } return 0;}
转载于:https://www.cnblogs.com/IMGavin/p/5926692.html