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 ...
随机推荐
- d3基础图形模板笔记
散点图(scatter plot): http://bl.ocks.org/weiglemc/6185069 雷达图(radar): http://xgfe.github.io/uploads/che ...
- Java web课程学习之JSP
JSP jsp隐式对象:JSP隐式对象是JSP容器为每个页面提供的Java对象,开发者可以直接使用它们而不用显式声明.JSP隐式对象也被称为预定义变量. jsp脚本片段 l jsp脚本片段是指 ...
- ansible 定义主机用户和密码
定义主机组用户和密码 [webservers] ansible[01:04] ansible_ssh_user='root' ansible_ssh_pass='AAbb0101' [root@ftp ...
- 【codeforces 505D】Mr. Kitayuta's Technology
[题目链接]:http://codeforces.com/problemset/problem/505/D [题意] 让你构造一张有向图; n个点; 以及所要求的m对联通关系(xi,yi) 即要求这张 ...
- WinServer-IIS-压缩及缓存
静态内容压缩: 默认10s内有2个客户端一起请求服务器的话,服务器就会把相关的静态内容压缩返回 动态内容压缩: 默认IIS的程序域最高可以占用CPU90%的资源,这个可以通过命令行修改 缓存和内核缓存 ...
- java ee5的新特性
1.标注 一种元数据,作用分为三类:编写文档@Document.代码分析@Deparecated(过时的)和编译检查@override(重写) 2.EJB3 EJB2的升级版,商业化的java bea ...
- CENTOS修改操作系统字符集
[root@localhost sysconfig]# cd /etc/sysconfig/ [root@localhost sysconfig]# vi i18n 修改并保存退出(:wq) LANG ...
- COGS 2479 奇怪的姿势卡♂过去 (bitset+折半)
思路: 此题显然是CDQ套CDQ套树套树 (然而我懒) 想用一种奇怪的姿势卡过去 就出现了以下解法 5w*5w/8的bitset hiahiahia 但是空间会爆怎么办啊- 折半~ 变成5w*2.5w ...
- Andoid CustomCircleProgress 半圆
package com.play.playgame.view; import android.content.Context; import android.graphics.Canvas; impo ...
- jQuery学习(一)——jQuery入门
1.jQuery基础 Jquery它是一个库(框架),要想使用它,必须先引入! jquery-1.8.3.js:一般用于学习阶段. jquery-1.8.3.min.js:用于项目使用阶段 官网下载后 ...