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. gcp – 源于CP的高级命令行文件拷贝工具

    作者:linux 出处:http://linux.cn/thread/11868/1/1/ gcp – 源于CP的高级命令行文件拷贝工具 几周前,我们讨论了高级拷贝(修改于cp命令,让其可以显示复制进 ...

  2. IOS - 总结(网络状态变更)

    - (void)initNetworkMonitor { NSURL *baseURL = [NSURL URLWithString:@"http://www.baidu.com/" ...

  3. AMD包下载及使用

    AMD下载 下载地址 选择837.zip下载即可,将837.zib考入相应的文件夹下,并解压缩 wget http://netlib.org/toms/837.zip unzip 837.zip cd ...

  4. Django - 表与ORM操作

    Django - 表与ORM操作 一. 模板语言 模板中也有自己的语言, 该语言可以实现数据展示 - {{ 变量 }} - 循环 {% for i in all_publisher %} {{ for ...

  5. BlogEngine.NET架构学习:Extension扩展实现

    之前有个系列文章介绍过BlogEngine.NET,其中也有关于插件的介绍:"BlogEngine.Net架构与源代码分析系列part9:开发扩展(上)--Extension与管理上的实现& ...

  6. 集成swagger2构建Restful API

    集成swagger2构建Restful API 在pom.xml中进行版本管理 <swagger.version>2.8.0</swagger.version> 给taosir ...

  7. 极路由4pro(HC5962)安装python

    基本配置 其实极路由4.极路由4 pro.极路由B70都是一个型号的(HC5962) CPU:MT7621AT + MT7612EN + 7603EN 内存:256MB DDR3 RAM 闪存:128 ...

  8. Java7的那些新特性

    本文介绍的java 7新特性很多其它的感觉像是语法糖.毕竟java本身已经比較完好了.不完好的非常多比較难实现或者是依赖于某些底层(比如操作系统)的功能. 不过java7也实现了类似aio的强大功能. ...

  9. UVALive - 2031 Dance Dance Revolution 三维dp

    题目大意:有一个胖子在玩跳舞机.刚開始的位置在(0,0).跳舞机有四个方向键,上左下右分别相应1,2,3,4.如今有下面规则 1.假设从0位置移动到随意四个位置,消耗能量2 2.假设从非0位置跳到相邻 ...

  10. bzoj3993: [SDOI2015]星际战争(网络流)

    3993: [SDOI2015]星际战争 题目:传送门 题解: 洛谷AC了,但是因为bzoj的spj有问题所以暂时没A 一道老题目了,二分时间然后网络流判断. 每次st-->武器连时间*攻击力 ...