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???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...
随机推荐
- MySQL服务器监控注意事项
当开发,测试,生产的数据库环境配置不一致(比如:配置字符集不同)时而导致特殊现象时,可以从Navicat的<工具>-<服务器监控>-<变量>里查找原因.
- centos7黑客帝国装逼
黑客帝国既视感 搜 cmatrix 然后放到本地解压缩 ,安装 yum install ncurses-devel./configure && make && make ...
- idea编译器光标变为insert状态
idea鼠标变成inset状态,不能复制.粘贴使用快捷键 1.打开设置 点击 plugins 输入ideavim 把 这个勾去掉!这个是插件的配置问题. 2.如果上面的不管用,那么检查editor- ...
- notepad编写html
notepad写代码的过程: 1.打开notepad,新建一个文档,然后保存,文件的后缀名为.html,代码保存前界面上文件名称为红色,保存后蓝色: 2.保存为html后,进行代码的输入,如果设置好自 ...
- Lodop如何设置预览后导出带背景的图,打印不带背景图
Lodop中的ADD_PRINT_SETUP_BKIMG,可以加载上背景图,该背景图在预览的时候可以显示也可以不显示,打印可以打印出来也可以不打印出来.一般套打,都是不打印背景图的,比如一些快递的快递 ...
- js 单项链表
介绍链表 链表是由一组节点组成的集合.每一个节点都使用一个对象的引用指向它的后续借点.指向另外一个借点的引用叫做链. 很多编程语言中数组的长度是固定的,就是定义数组的时候需要定义数组的长度,所以当数组 ...
- mysql and不能同时运用在一个字段上
- day6 字符串
重复输出字符串 # * 重复输出字符串 print("hello"*2) 字符串切片 # 字符串也拥有索引,和列表切片操作类似 print("helloworld&quo ...
- day30 小面试题 去重 (考核 __eq__ 以及 __hash__ )
# 小面试题,要求将一个类的多个对象进行去重 # 使用set方法去重,但是无法实现,因为set 需要依赖eq以及hash, # hash 哈希的是内存地址, 必然不一样 # eq 比较的也是内存地址, ...
- MT【191】阿波罗尼乌斯圆
已知$f(x)=2\sqrt{(\cos x+\frac{1}{2})^2+\sin^2 x}-\sqrt{\cos^2 x+(\sin x-\frac{1}{2})^2}$,若$m\ge f(x)$ ...