BNUOJ 36005 Chemical Reaction
Chemical Reaction
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
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
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的更多相关文章
- UVA题目分类
题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...
- 一位学长的ACM总结(感触颇深)
发信人: fennec (fennec), 信区: Algorithm 标 题: acm 总结 by fennec 发信站: 吉林大学牡丹园站 (Wed Dec 8 16:27:55 2004) AC ...
- 蝕刻技術(Etching Technology)
1. 前言 蚀刻是将材料使用化学反应或物理撞击作用而移除的技术. 蚀刻技术可以分为『湿蚀刻』(wet etching)及『干蚀刻』(dry etching)两类.在湿蚀刻中是使用化学溶液,经由化学反应 ...
- STAT UN2102 Homework
STAT UN2102 Homework 4 [100 pts]Due 11:59pm Monday, May 6th on CanvasYour homework should be submitt ...
- (转)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 ...
- lammps模拟化学反应(1)
1. Can I use lammps to chemical reaction systems?Please note that you can only get as good an answer ...
- 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 ...
- zz【清华NLP】图神经网络GNN论文分门别类,16大应用200+篇论文最新推荐
[清华NLP]图神经网络GNN论文分门别类,16大应用200+篇论文最新推荐 图神经网络研究成为当前深度学习领域的热点.最近,清华大学NLP课题组Jie Zhou, Ganqu Cui, Zhengy ...
- Paper Review: Epigenetic Landscape, Cell Differentiation 02
I'll share another review paper about Epigenetic Landscape, it comes from Nature Review, published i ...
随机推荐
- pythone 学习笔记(粗略)
文档目录 概述 安装 基本语法 数据结构 4.1 数字和字符串类型 4.2 元祖 4.3 列表 4.4 字典 流程语句 5.1 分支结构 5.2 逻辑运算符(if) 5.3 循环 5.3.1 for ...
- Vue学习之路第七篇:跑马灯项目实现
前面六篇讲解了Vue的一些基础知识,正所谓:学以致用,今天我们将用前六篇的基础知识,来实现类似跑马灯的项目. 学前准备: 需要掌握定时器的两个函数:setInterval和clearInterval以 ...
- Linux之awk使用
基本语法 $n :当前记录的第n个字段,比如n为1表示第一个字段,n为2表示第二个字段 $0:执行过程中当前行的文本内容 \t:制表符 \n:换行符 -F'[:#/]' : 定义三个分隔符,注意有-F ...
- 虚拟机安装mac
没成功,把几篇不错的文章先记录下地址 http://bbs.pcbeta.com/forum.php?mod=viewthread&tid=1437039 http://bbs.pcbeta. ...
- 《你又怎么了我错了行了吧》第九次团队作业:Beta冲刺与验收准备
项目 内容 这个作业属于哪个课程 软件工程 这个作业的要求在哪里 实验十三 团队作业9 团队名称 你又怎么了我错了行了吧 作业学习目标 (1)掌握软件黑盒测试技术: (2)学会编制软件项目总结PPT. ...
- Git学习总结(10)——git 常用命令汇总
1.git 基本概念: 工作区:改动(增删文件和内容) 暂存区:输入命令:git add 改动的文件名,此次改动就放到了'暂存区'(新增的文件) 本地仓库(简称:本地):输入命令:git commit ...
- DML语句的使用(delete,update,insert)
8)DML语句的使用 在PL/SQL中,DML语句与前面学习的 相同. begin --执行插入操作 insert into t001(id) values(1); - ...
- tomcat使用及原理
1,Tomcat作为Servlet容器的基本功能 2,Tomcat的组成结构 Tomcat本身由一列的可配置的组件构成,其中核心组件是Servlet容器组件,它是所有其他Tomcat组件的顶层容器.T ...
- 赵雅智_使用SQLiteDatabase操作SQLite数据库及事务
知识点具体解释:http://blog.csdn.net/zhaoyazhi2129/article/details/9025995 详细代码: MainActivity.java package c ...
- leetcode 题解 || Longest Common Prefix 问题
problem: Write a function to find the longest common prefix string amongst an array of strings. 寻找 0 ...