A - Annoying Present codeforce1009c -csdn博客

Alice got an array of length nn as a birthday present once again! This is the third year in a row!

And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.

Bob has chosen mm changes of the following form. For some integer numbers xx and dd, he chooses an arbitrary position i(1≤i≤n) and for every j∈[1,n]adds x+d⋅dist(i,j) to the value of the j-th cell. dist(i,j) is the distance between positions ii and j (i.e. dist(i,j)=|i−j|, where |x| is an absolute value of xx).

For example, if Alice currently has an array [2,1,2,2] and Bob chooses position 33 for x=−1x=−1 and d=2d=2 then the array will become [2−1+2⋅2, 1−1+2⋅1, 2−1+2⋅0, 2−1+2⋅1]= [5,2,1,3]. Note that Bob can’t choose position ii outside of the array (that is, smaller than 11 or greater than n).

Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.

What is the maximum arithmetic mean value Bob can achieve?

Input
The first line contains two integers nn and mm (1≤n,m≤105) — the number of elements of the array and the number of changes.

Each of the next mm lines contains two integers xixi and didi (−103≤xi,di≤103) — the parameters for the ii-th change.

Output
Print the maximal average arithmetic mean of the elements Bob can achieve.

Your answer is considered correct if its absolute or relative error doesn’t exceed 10−6.

Examples
Input
2 3
-1 3
0 0
-1 -4
Output
-2.500000000000000
Input
3 2
0 2
5 0
Output
7.000000000000000

  • 解题思路:对于每组m,x值是一定会加到每个数中的,共有n个,因此ans+=n×x。对于d因为与距离有关,因此,如果为整数,应该尽可能是结果最大,发现在边上会最大,中间会最小。注意:计算时,应用整数存储,最后除的时候再换算成小数。并且输出只能用printf。
#include<bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define _ ios::sync_with_stdio(false)
bool SUBMIT = 1;
typedef long long ll;
using namespace std;
const double PI = acos(-1);
int main()
{//if(!SUBMIT)freopen("i.txt","r",stdin);else _;ll n,m,ans=0;cin>>n>>m;double anm=0;for(int i=0;i<m;i++){ll x,d;cin>>x>>d;ans+=x*n;if(d>0){ans+=n*(n-1)/2*d;}else if(d<0){ll k=n/2;if(k<=0)continue;if(n%2){ans+=k*(k+1)*d;}else{ans+=k*d*(k-1)/2+k*(k+1)*d/2;}}//cout<<ans<<endl;}anm=ans*1.0/n;printf("%.10lf\n",anm);return 0;
}

posted @ 2018-07-23 12:37 i-Curve 阅读(...) 评论(...) 编辑 收藏

A - Annoying Present codeforce1009c -csdn博客相关推荐

  1. taoqick 搜索自己CSDN博客

    L1 L2正则化和优化器的weight_decay参数 kaiming初始化的推导 Pytorch动态计算图 Pytorch自动微分机制 PyTorch中在反向传播前为什么要手动将梯度清零? 通俗讲解 ...

  2. 关于博客园与CSDN博客同步的说明

    把博客园与CSDN比较,我认为博客园有技术内容优势,CSDN有行业资源优势,两者都比较重要.因此在两家网站同步发布博客. CSDN博客地址:http://blog.csdn.net/caoshiyin ...

  3. 2019年度CSDN博客之星TOP10榜单揭晓,你上榜了吗?

    培根说,『读书造成充实的人,会议造成未能觉悟的人,写作造成正确的人』. 在短信短视频快速迭代的快时代,更深度的思考.更正确的实践,更成体系的写作与分享,尤显可贵.这里,每一篇博文都是开发者实战的经验解 ...

  4. CSDN博客的创建及使用

    文章目录 一.创建CSDN博客详细流程 1. 注册 2. 绑定手机 二.编辑和发布博客 1. 设置markdown格式 2. 发布文章 3. 常见的markdown语法 3.1 分级标题 3.2 目录 ...

  5. 这是一名南京985AI硕士,CSDN博客专家

    微信公众号推荐 AI蜗牛车公众号 微信公众号<AI蜗牛车>,公众号致力于技术项目化,具体化,思考化,会写系列的项目工程文章,细致到位,也会写一个读物的读书笔记,或者一个语言/框架的学习笔记 ...

  6. CSDN博客获取积分规则!不是下载积分!如何快速增长积分!

    博客积分是CSDN对用户努力的认可和奖励,也是衡量博客水平的重要标准. 博客等级也将由博客积分唯一决定.积分规则具体如下: 1.每发布一篇原创或者翻译文章:可获得10分: 2.每发布一篇转载文章:可获 ...

  7. 类选择器和所作用的标签一起写为什么不起作用? - CSDN博客

    原文:类选择器和所作用的标签一起写为什么不起作用? - CSDN博客 HTML代码: css样式: 这不是将样式作用于circle类下的有current类的li标签吗?为什么不起作用? 原因: 选择器 ...

  8. microsoft edge 打不开 csdn 博客

    microsoft edge 打不开 csdn 博客

  9. 如何转载别人的csdn博客

    起意 看到一篇不错的博客,想转载但是不会(没有转载键),网搜发现没有Chrome浏览器的详细转载办法,受博主Bily猪启发,弄了这个教程,给小白的,大神勿嗤.时间紧急的直接看总结. 实践 检查.在喜欢 ...

  10. 如何在简历中添加自己的CSDN博客链接

    如何在简历中添加自己的CSDN博客链接 添加以下网址https://blog.csdn.net/ID(ID为 ) 点开就是自己的博客

最新文章

  1. 《那些年啊,那些事——一个程序员的奋斗史15》
  2. PyCharm安装好vim后,怎么配置.vimrc
  3. JavaScript实现封闭区域布尔运算
  4. 易校网校园综合跑腿小程序源码修复运营版
  5. 零基础入门学习Python,我与python的第一次亲密接触后的感受
  6. crontab 定时备份 出现permission:denied
  7. python实现MD5加密
  8. matlab按行读文件
  9. php session auto_start,PHP出现 Warning: session_start()的解决方法
  10. QQ for linux不用udp8000端口?
  11. Snake算法与遥感影像应用,python matlab对比
  12. 经典散文集锦:读者杂志卷首语大荟萃
  13. 二维码定位算法流程图
  14. 微信公众号url接口配置,使微信公众号更多功能化(python简单解决)
  15. bootstrap4.0图标使用_详解Bootstrap glyphicons字体图标
  16. 测试/开发程序员值这么多钱么?“我“不会愿赌服输......
  17. 服务器 台式机性能比较,服务器与台式机的区别
  18. uniapp 日期计算年龄
  19. linux 怎么把新硬盘分区,linux添加新硬盘分区
  20. P4279 [SHOI2008]小约翰的游戏(博弈论)(Anti-SG)

热门文章

  1. F5负载均衡设备入门
  2. 负载均衡器 运行在2、3、4、7层之间的区别 [资料整理]
  3. Navicat中出现MySQL server has gone away错误
  4. 阮一峰老师-Auth 2.0 的一个简单解释
  5. spire.xls.free操作excel简单实用
  6. “出轨照”背后的真相:防骗启示录之相册病毒报告
  7. MacBook外接显示器的显示模式介绍及设置说明(分屏/多屏)
  8. python机械臂仿真_机械臂 python
  9. DNS解析常见问题:如何清理DNS缓存?
  10. 论文笔记-Monocular Depth Estimation as Regression of Classification using Piled Residual Networks