Chemical Reaction

Time Limit: 3000ms
Memory Limit: 65536KB

This problem will be judged on OpenJudge. Original ID: C14H
64-bit integer IO format: %lld      Java class name: Main

 

There are n chemical elements. Each of them has two attributes, a and b. When two different elements are mixed, a chemical reaction will occur. During a chemical reaction, energy will be released. The following expression tells the amount of energy that is released when i-th element and j-th element are mixed:

|ai - aj| ∙ bi ∙ bj / max(|bi|, |bj|)

Could you find the maximal energy that can be released by mixing two elements?

Note that the value of the expression may be negative, which means the chemical reaction absorbs energy. For simplicity, we regard it as releasing negative energy, so you can compare two values of the expression directly to determine which releases more energy.

 

Input

The first line contains an integer T (1 ≤ T ≤ 10) -- the number of test cases.

For each test case:
The first line contains an integer n. 2 ≤ n ≤ 500 000.
Then follows n lines, each line contains two integers: a, b, indicate the two attributes of a chemical element. 0 ≤ | a | ≤ 10 000. 1 < | b | ≤ 10 000.

 

Output

For each test case, output one integer in a single line -- the maximal energy that can be released by mixing two elements.

 

Sample Input

1
5
1 5
-2 4
3 7
5 -3
-6 -2

Sample Output

22

解题:把b进行分类,负数的一边,正数的一边,然后就可以了。。。。
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
const int maxn = ;
struct node {
int x,y,id,minv,maxv;
node(int tx = ,int ty = ,int tz = ) {
x = tx;
y = ty;
id = tz;
}
bool operator< (const node &t)const{
return y < t.y;
}
};
node pa[maxn],pb[maxn];
int ca,cb,u[maxn],v[maxn],T,n;
int bsearch(int lt,int rt,int val,node *d){
int ans = rt+;
while(lt <= rt){
int mid = (lt+rt)>>;
if(d[mid].y >= val){
ans = mid;
rt = mid-;
}else lt = mid+;
}
return ans;
}
int main() {
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
for(int i = ca = cb = ; i < n; ++i) {
scanf("%d %d",u+i,v+i);
if(v[i] < ) pa[ca++] = node(u[i],-v[i],i);
else pb[cb++] = node(u[i],v[i],i);
}
sort(pa,pa+ca);
sort(pb,pb+cb);
if(ca) pa[ca-].minv = pa[ca-].maxv = pa[ca-].x;
if(cb) pb[cb-].minv = pb[cb-].maxv = pb[cb-].x;
for(int i = ca-; i >= ; --i) {
pa[i].minv = min(pa[i].x,pa[i+].minv);
pa[i].maxv = max(pa[i].x,pa[i+].maxv);
}
for(int i = cb-; i >= ; --i) {
pb[i].minv = min(pb[i].x,pb[i+].minv);
pb[i].maxv = max(pb[i].x,pb[i+].maxv);
}
int ans = -INF;
for(int i = ; i < n; ++i) {
int idx = INF;
if(ca) {
idx = bsearch(,ca-,abs(v[i]),pa);
if(idx < ca && pa[idx].id == i) idx++;
if(idx < ca) {
ans = max(ans,-abs(u[i] - pa[idx].minv)*v[i]);
ans = max(ans,-abs(u[i] - pa[idx].maxv)*v[i]);
ans = max(ans,-abs(pa[idx].minv - u[i])*v[i]);
ans = max(ans,-abs(pa[idx].maxv - u[i])*v[i]);
}
}
if(cb) {
idx = bsearch(,cb-,abs(v[i]),pb);
if(idx < cb && pb[idx].id == i) idx++;
if(idx < cb) {
ans = max(ans,abs(u[i] - pb[idx].minv)*v[i]);
ans = max(ans,abs(u[i] - pb[idx].maxv)*v[i]);
ans = max(ans,abs(pb[idx].minv - u[i])*v[i]);
ans = max(ans,abs(pb[idx].maxv - u[i])*v[i]);
}
}
}
printf("%d\n",ans); }
return ;
}

BNUOJ 36005 Chemical Reaction的更多相关文章

  1. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  2. 一位学长的ACM总结(感触颇深)

    发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...

  3. 蝕刻技術(Etching Technology)

    1. 前言 蚀刻是将材料使用化学反应或物理撞击作用而移除的技术. 蚀刻技术可以分为『湿蚀刻』(wet etching)及『干蚀刻』(dry etching)两类.在湿蚀刻中是使用化学溶液,经由化学反应 ...

  4. STAT UN2102 Homework

    STAT UN2102 Homework 4 [100 pts]Due 11:59pm Monday, May 6th on CanvasYour homework should be submitt ...

  5. (转)Applications of Reinforcement Learning in Real World

    Applications of Reinforcement Learning in Real World 2018-08-05 18:58:04 This blog is copied from: h ...

  6. lammps模拟化学反应(1)

    1. Can I use lammps to chemical reaction systems?Please note that you can only get as good an answer ...

  7. Some day some time we will do

    Age has been reached the end of the beginning of the world,May be guilty in his seems to passing a l ...

  8. zz【清华NLP】图神经网络GNN论文分门别类,16大应用200+篇论文最新推荐

    [清华NLP]图神经网络GNN论文分门别类,16大应用200+篇论文最新推荐 图神经网络研究成为当前深度学习领域的热点.最近,清华大学NLP课题组Jie Zhou, Ganqu Cui, Zhengy ...

  9. Paper Review: Epigenetic Landscape, Cell Differentiation 02

    I'll share another review paper about Epigenetic Landscape, it comes from Nature Review, published i ...

随机推荐

  1. CMDB设计

    CMDB(资产管理数据库) CMDB是所有运维工具的数据基础 CMDB包含的内容 用户管理,记录测试,开发,运维人员的用户表 业务线管理,需要记录业务的详情 项目管理,指定此项目用属于哪条业务线,以及 ...

  2. git与github的连接流程

    https://blog.csdn.net/sssssuuuuu666/article/details/78565381 https://www.cnblogs.com/wzd5230/p/49064 ...

  3. oracle 用户解锁和修改用户密码

    1.安装教程参看:https://jingyan.baidu.com/article/3c48dd34be2a32e10be35881.html 2.用户解锁 --> 运行cmd --> ...

  4. jvm 虚拟机参数_栈内存分配

    1.参数 -Xss 指定线程最大的栈空间,整个参数也直接决定了函数可调用的最大深度 2.测试代码 private static int count; public static void addCou ...

  5. HDU 4253 Two Famous Companies

    Two Famous Companies Time Limit: 15000ms Memory Limit: 32768KB This problem will be judged on HDU. O ...

  6. NYIST 677 碟战

    碟战时间限制:2000 ms | 内存限制:65535 KB难度:4 描述知己知彼,百战不殆!在战争中如果被敌人掌握了自己的机密,失败是必然的.K国在一场战争中屡屡失败,就想到自己的某些城市可能会有敌 ...

  7. ASP.NET-Microsoft.Management.Infrastructure错误

    错误如图所示,将MVC发布到IIS上就会出现这个错误,我用到了NPOI这个EXCEL插件,不知道是不是这个造成的,但是实在找不到解决方案,就直接将BIN目录下的这个Microsoft.Manageme ...

  8. CF 567C(Geometric Progression-map)

    C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...

  9. oracle 下操作blob字段是否会产生大量redo

    操作blob字段是否会产生大量redo,答案是不会.以下来做一个实验,測试数据库版本号是11.2.0.1.0: --创建一张表做測试之用 create table test_blob (   id n ...

  10. Qt Quick Controls 与 Qt Quick Controls 2的区别(详细对照)

    Qt Quick Controls 原本是为支持桌面平台而开发的,后来又加入了移动平台和嵌入式平台的支持.它们应用非常广泛,因为它们提供了足够灵活的样式系统,以允许开发具有平台相关或者无关风格的应用程 ...