Codeforces 954 E. Water Taps
http://codeforces.com/problemset/problem/954/E
式子变成Σ xi*(ti-T)=0
sum0表示>=T的ai*ti之和
sum1表示<T的ai*ti之和
那么如果sum0<sum1,所有ti>=T的ai全加上
那么现在的Σ xi*(ti-T)>=0
考虑用ti<T的来使这个式子变成0,还要让Σ xi 最大
显然是选的ti与T的差距越小 ,xi可以用的越多
将ti从大到小排序后,以此选用,直到式子变成0
sum1<sum0 时 同理
#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 200001 struct node
{
int a,t;
}e[N],z[N],f[N]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} bool cmp1(node p,node q)
{
return p.t<q.t;
} bool cmp2(node p,node q)
{
return p.t>q.t;
} int main()
{
int n,T;
read(n); read(T);
for(int i=;i<=n;++i) read(e[i].a);
for(int i=;i<=n;++i) read(e[i].t);
int cntz=,cntf=;
double sum0=,sum1=;
int cnt0=,cnt1=;
long long tot0=,tot1=;;
for(int i=;i<=n;++i)
if(e[i].t>=T)
{
z[++cnt0]=e[i];
sum0+=1LL*e[i].a*(e[i].t-T);
tot0+=e[i].a;
}
else
{
f[++cnt1]=e[i];
sum1+=1LL*e[i].a*(T-e[i].t);
tot1+=e[i].a;
}
sort(z+,z+cnt0+,cmp1);
sort(f+,f+cnt1+,cmp2);
double ans=;
if(sum0>=sum1)
{
ans=tot1;
for(int i=;i<=cnt0;++i)
if(1.0*z[i].a*(z[i].t-T)<=sum1)
{
sum1-=1.0*z[i].a*(z[i].t-T);
ans+=z[i].a;
}
else
{
ans+=sum1/(z[i].t-T);
break;
}
}
else
{
ans=tot0;
for(int i=;i<=cnt1;++i)
if(1.0*f[i].a*(T-f[i].t)<=sum0)
{
sum0-=1.0*f[i].a*(T-f[i].t);
ans+=f[i].a;
}
else
{
ans+=sum0/(T-f[i].t);
break;
}
}
printf("%.8lf",ans);
}
Codeforces 954 E. Water Taps的更多相关文章
- Codeforces 954E Water Taps
题目大意 有 $n$($1\le n\le 200000$)个变量 $x_1, x_2, \dots, x_n$,满足 \begin{equation} 0\le x_i \le a_i \label ...
- Codeforces 954 G. Castle Defense
http://codeforces.com/problemset/problem/954/G 二分答案 检验的时候,从前往后枚举,如果发现某个位置的防御力<二分的值,那么新加的位置肯定是越靠后越 ...
- Codeforces 954 D Fight Against Traffic
Discription Little town Nsk consists of n junctions connected by m bidirectional roads. Each road co ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- Educational Codeforces Round 40 (Rated for Div. 2) Solution
从这里开始 小结 题目列表 Problem A Diagonal Walking Problem B String Typing Problem C Matrix Walk Problem D Fig ...
- Educational Codeforces Round 40 A B C D E G
A. Diagonal Walking 题意 将一个序列中所有的\('RU'\)或者\('UR'\)替换成\('D'\),问最终得到的序列最短长度为多少. 思路 贪心 Code #include &l ...
- Educational Codeforces Round 37 (Rated for Div. 2)
我的代码应该不会被hack,立个flag A. Water The Garden time limit per test 1 second memory limit per test 256 mega ...
- C - Water The Garden
It is winter now, and Max decided it's about time he watered the garden. The garden can be represent ...
- 10月清北学堂培训 Day 6
今天是黄致焕老师的讲授~ T1 自信 AC 莫名 80 pts???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...
随机推荐
- STL数据结构
priority_queue "C++ reference"上如此解释priority queue:"This context is similar to a heap, ...
- JS判断浏览器种类
function myBrowser() { var userAgent = navigator.userAgent; //取得浏览器的userAgent ...
- Angular $scope和$rootScope
<!DOCTYPE html><html ng-app='myModule'><head lang="en"> <meta charset ...
- 一个很初级的错误 Destructor忘记override导致内存泄露
TxxObj= class public Destructor Destroy(); override;!!!此处若无override,将导致内存泄露 end; Destru ...
- BZOJ4891 TJOI2017龙舟(Polllard-Rho)
对给定模数分解质因数后约分即可.依然常数巨大过不了. #include<iostream> #include<cstdio> #include<cmath> #in ...
- java 使用 WebUploader
参考: http://blog.csdn.net/finalAmativeness/article/details/54668090 最近项目需要多文件上传. 所以使用了 baidu的 webuplo ...
- jquery 取id模糊查询
[属性名称] 匹配包含给定属性的元素[att=value] 匹配包含给定属性的元素 (大小写区分)[att*=value] 模糊匹配[att!=value] 不能是这个值[att$=value] 结尾 ...
- 洛谷P3345 [ZJOI2015]幻想乡战略游戏(动态点分治,树的重心,二分查找,Tarjan-LCA,树上差分)
洛谷题目传送门 动态点分治小白,光是因为思路不清晰就耗费了不知道多少时间去gang这题,所以还是来理理思路吧. 一个树\(T\)里面\(\sum\limits_{v\in T} D_vdist(u,v ...
- 自学Linux Shell13.1-命令行参数
点击返回 自学Linux命令行与Shell脚本之路 Bash shell提供了一些不同的方法来从用户处获得数据,包括以下3中方法: 命令行参数(添加在名利后面的数据) 命令行选项(可修改命令行为的单个 ...
- Intent 跳转Activity
Intent 跳转 显示跳转(用类名跳转) Intent i = new Intent(a.this,b.class); 隐士跳转 自定义Action <!--配置跳转Activity--> ...