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 ...
随机推荐
- Extjs iconCls 的用法
如何在按钮中加icon: 1.在Extjs中 { xtype:'button', text:'学生档案', iconCls:'file', }, 2.在css中写: .file{ background ...
- UDP Linux编程(客户端&服务器端)
服务器端 服务器不用绑定地址,他只需要进行绑定相应的监听端口即可. #include <sys/types.h> #include <sys/socket.h> #includ ...
- koa,express,node 通用方法连接MySQL
这个教程不管node,express,koa都可以用下面方法连接,这里用koa做个参考 这个教程的源码地址: https://github.com/xiaqijian/... 新建文件目录,我是这样子 ...
- 解决utf8' codec can't decode byte 0xe5 in position 0: unexpected end of data
使用unicode对象的话,除了这样使用u标记,还可以使用unicode类以及字符串的encode和decode方法. unicode类的构造函数接受一个字符串参数和一个编码参数,将字符串封装为一个u ...
- CRM系统 - 总结 (一) 权限
1. 问:为什么程序需要权限控制? 答:生活中的权限限制,① 看灾难片电影<2012>中富人和权贵有权登上诺亚方舟,穷苦老百姓只有等着灾难的来临:② 屌丝们,有没有想过为什么那些长得漂亮身 ...
- java字符文件的读写
1.java文件读写,首先我们需要导入相应的包:java.io.*; 2.代码如下: package Demo1; import java.io.*; public class FileWirteTe ...
- WinCE C#程序,控制启动时仅仅能启动一个程序,使用相互排斥量来实现,该实现方法測试通过
</pre><pre code_snippet_id="430174" snippet_file_name="blog_20140718_5_46349 ...
- Qt 3D教程(三)实现对模型材质參数的控制
Qt 3D教程(三)实现对模型材质參数的控制 蒋彩阳原创文章,首发地址:http://blog.csdn.net/gamesdev/article/details/47131841.欢迎同行前来探讨. ...
- Android之怎样改变焦点状态【EditText】
以EditText为例 1.改变焦点状态 password.setOnFocusChangeListener(new OnFocusChangeListener() { @Override publi ...
- Asp.net动态页面静态化之初始NVelocity模板引擎
Asp.net动态页面静态化之初始NVelocity模板引擎 静态页面是网页的代码都在页面中,不须要运行asp,php,jsp,.net等程序生成client网页代码的网页,静态页面网址中一般不含&q ...