Codeforces ~ 1009C ~ Annoying Present (贪心)
题意
一个长度为n的数组(初始全为0),进行m次操作。
操作:给你x,d,你任意挑选一个 i (1~n),每个数字加上 x+|i-j|*d( j 表示对应数字的下标)
问m次操作后的最大算术平均值为多少?
题解
首先对于x,每次数组的和sum都增加n*x。(Σ|i-j|)*d跟我们选的 i 有关系,如果d>0,我们就让 Σ|i-j| 尽量大,如果d<0,我们就让 Σ|i-j| 尽量小。Σ|i-j|的最大值就是 i 取0或n的时候,Σ|i-j|的最小值就是 i 取n/2的时候。维护sum就行了
#include<stdio.h>
#define ll long long
int main( )
{
ll n,m,x,d;
ll sum=;
scanf("%I64d%I64d",&n,&m);
ll MAX,MIN;
MAX=n*(n-)/;
MIN=(n/+)*(n/) - (n%?:n/); while(m--)
{
scanf("%I64d%I64d",&x,&d);
sum+=x*n;
if(d>)
sum+=MAX*d;
if(d<)
sum+=MIN*d; }
printf("%.7f\n",1.0*sum/n);
}
Codeforces ~ 1009C ~ Annoying Present (贪心)的更多相关文章
- Codeforces 1009C: Annoying Present
C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- codeforces 704B - Ant Man 贪心
codeforces 704B - Ant Man 贪心 题意:n个点,每个点有5个值,每次从一个点跳到另一个点,向左跳:abs(b.x-a.x)+a.ll+b.rr 向右跳:abs(b.x-a.x) ...
- CodeForces - 50A Domino piling (贪心+递归)
CodeForces - 50A Domino piling (贪心+递归) 题意分析 奇数*偶数=偶数,如果两个都为奇数,最小的奇数-1递归求解,知道两个数都为1,返回0. 代码 #include ...
- C. Annoying Present SB题
C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【Codeforces 1009C】Annoying Present
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...
- Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)
题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...
- Codeforces 700B Connecting Universities - 贪心
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's poss ...
- Codeforces 161 B. Discounts (贪心)
题目链接:http://codeforces.com/contest/161/problem/B 题意: 有n个商品和k辆购物车,给出每个商品的价钱c和类别t(1表示凳子,2表示铅笔),如果一辆购物车 ...
- CodeForces 176A Trading Business 贪心
Trading Business 题目连接: http://codeforces.com/problemset/problem/176/A Description To get money for a ...
随机推荐
- Linux系统之-TCP-IP链路层
一.基本 网络层协议的数据单元是 IP 数据报 ,而数据链路层的工作就是把网络层交下来的 IP 数据报 封装为 帧(frame)发送到链路上,以及把接收到的帧中的数据取出并上交给网络层. 为达到这一目 ...
- python re模块常用的正则表达式
'.' 默认匹配除\n之外的任意一个字符,若指定flag DOTALL,则匹配任意字符,包括换行 '^' 匹配字符开头,若指定flags MULTILINE,这种也可以匹配上(r&qu ...
- The Preliminary Contest for ICPC Asia Shenyang 2019 H
H. Texas hold'em Poker 思路:根据每个牌型分等级,然后排序按照等级优先,最大值次之,次大值,最后比较剩下值的和. #include<bits/stdc++.h> us ...
- DataFrame读取CSV文件
读取csv的代码: print pd.read_csv("ex1.csv") print "\n" print "Can also use read ...
- MySQL总结01
window删除MySQL服务 cmd下执行 sc delete MySQL 登陆登出 登陆: mysql -uroot -ppasswd -h host 退出登陆 mysqladmin -uroot ...
- Spring 使用@Async出现循环依赖Bean报错的解决方案
初现端倪 Caused by:org.springframework.beans.factory.BeanCurrentlyInCreationException: Errorcreating bea ...
- GCD 与XOR
题目:UVA12716 题意: 问 gcd(i,j) = i ^ j 的对数(j <=i <= N ) N的范围为30000000,有10000组样例 分析: 有几个结论:(1)若 a ...
- v-distpicker 一个好用的三级联动的插件
// 引入插件npm install v-distpicker --save import VDistpicker from 'v-distpicker' Vue.component('v-distp ...
- Guava之controller中使用缓存cache
之前介绍过的Guava这个工具包中有很多方便的用法,下面要使用它封装的Cache来实现功能. 示例: import com.google.common.cache.CacheBuilder; impo ...
- Javascript高级程序设计--读书笔记之面向对象(一)
哈哈哈万物皆对象,终于到了js的面向对象篇. 一.属性类型 (1)数据属性 数据属性包含一个数据值的位置,在这个位置可以写入和读取数值,数据属性有四个描述器行为的特性 [[Configurable]] ...