Annoying Present
http://codeforces.com/group/1EzrFFyOc0/contest/1009/problem/C
题意:原本有一个n个0的数组a[],你对它进行m次操作,每次操作让a[j]+=x+d*(dish(i,j))(dish(i,j)代表abs(i-j))。其中i是任意的。让你求经过这m次操作所能得到数组的平均值最大为多少。其实这里有一点贪心的思想,就是我们要尽量的让a[j]最大,那么和x是没有关系的,初始时数组和为ans=0;那么以后每次操作ans肯定会+=n*x;重点是对d的讨论,d<0是我们要让距离和最小,d>=0让距离和最大,这样就达到了我们的步步最优的条件。接下来就很简单了,直接讨论距离和即可
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<cstring> 5 #include<cmath> 6 #include<string> 7 #include<cmath> 8 #include<set> 9 #include<vector> 10 #include<stack> 11 #include<queue> 12 #include<map> 13 using namespace std; 14 #define ll long long 15 #define se second 16 #define fi first 17 const int INF= 0x3f3f3f3f; 18 const int N=1e5+5; 19 20 ll n,m,x,d; 21 22 int main() 23 { 24 cin>>n>>m; 25 ll ans=0; 26 while(m--) 27 { 28 cin>>x>>d; 29 if(d<0){ 30 if(n&1) 31 ans+=(n*n-1)/4*d+n*x; 32 else 33 ans+=n*n/4*d+n*x; 34 } 35 else if(d>=0){ 36 ans+=n*(n-1)/2*d+n*x; 37 } 38 } 39 double res=ans*1.0/n; 40 printf("%.15lf",res); 41 }
转载于:https://www.cnblogs.com/thunder-110/p/9318001.html
Annoying Present相关推荐
- Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)
题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...
- Educational Codeforces Round 47 (Div 2) (A~G)
目录 Codeforces 1009 A.Game Shopping B.Minimum Ternary String C.Annoying Present D.Relatively Prime Gr ...
- 基础算法 —— 贪心算法
[概述] 贪心算法是从问题的初始状态出发,通过若干次的贪心选择而得到的最优值的一种求解策略,即贪心策略. 简单来说,贪心策略是一种在每次决策时采取当前意义下最优策略的算法,做出的选择至少在某种约束条件 ...
- CentOS Linux解决 Device eth0 does not seem to be present
通过OVF部署Linux主机后提示 ringing up interface eth0: Device eth0 does not seem to be present,delaying initi ...
- 【ASP.NET Core】解决“The required antiforgery cookie xxx is not present”的错误
当你在页面上用 form post 内容时,可能会遇到以下异常: The required antiforgery cookie "????????" is not present ...
- UserWarning: Label not :NUMBER: is present in all training examples
UserWarning: Label not :NUMBER: is present in all training examples 目录 UserWarning: Label not :NUMBE ...
- Genomes correction and assembling - Present methods and tools
Genomes correction and assembling - Present methods and tools 基因组校正和组装-现有的方法和工具 摘要 新一代测序(NGS)技术的迅速发展 ...
- 自定义present和dismiss的转场动画
趁周末闲暇之余,重新写一下present和push的自定义动画. 本来之前有写过一个,因为没有及时整理,到导致一时凌乱,找不到具体在哪了,提醒各位,平时要注意代码的整理和归档,不然到时候重复的代码写了 ...
- No 'Access-Control-Allow-Origin' header is present on the requested resource.
/********************************************************************************** No 'Access-Contr ...
- vmware虚拟机克隆后,启动网卡报错device eth0 does not seem to be present, delaying initialization...
克隆的虚拟机,启动网卡时报错,device eth0 does not seem to be present, delaying initialization 1. vi /etc/sysconfig ...
最新文章
- 实时监控用户输入--中文输入解决方案
- 2021年要关注这5个开源Kubernetes项目
- JavaScript的几个概念简单理解(深入解释见You Don't know JavaScript这本书)
- easypoi导出word表格_拒绝加班,批量将word文档中的信息高效率提取出来存储到Excel中...
- linux 无法访问docker mysql8_Apple M1芯片不支持Docker?Docker:正在努力适配
- 前端学习(712):数组的概念
- JVM Class 类文件结构 (系列号2)
- Git基础教程(四)
- HBase常用Shell命令
- 利用POI导出excel
- 创新金融科技:从零到一构建新房交易供应链金融服务 PPT分享
- 安装Ubuntu系统时硬盘分区最合理的方法
- 简简单单批量安装windows主机
- java我的世界溺尸为啥这么少,我的世界:溺尸刷新几率存在问题?溺尸刷怪塔为何得不到三叉戟?...
- 一行代码帮你彻底解决pip下载速度慢的问题,更改pip源至国内镜像(无须新建文件夹), 享受飞一般的速度
- 贪便宜给自己带来的麻烦,哈哈。
- 360阻止了java运行,Java破绽利用-jre安装路径绕过360拦截
- Qt字符转换、文件操作、加密、电脑操作
- 【邢不行|量化小讲堂系列58-实战篇】零基础了解什么是期权,抓住下轮牛市红利
- 吃海鲜视频软件测试,IDE硬盘用HD Tune Pro检测健康状态警告分析。是否需要低级格式化?...
热门文章
- 【golang】go app 优雅关机 Graceful Shutdown How?
- JavaScript 删除Dom节点
- 从零开始变成一个脚本小子002-初窥密码2
- python自动购买12306票_python+splinter实现12306网址刷票并自动购票流程
- 电脑装两个硬盘在计算机只显示一个,电脑有两个硬盘,如何去掉机械硬盘中的那套系统?...
- 同一个浏览器多用户同时登录的解决方案
- java socket 实现原理_java socket原理
- 怎么学计算机打字输入,电脑怎么学习打字
- 阿里云智能编码插件,Cosy文档搜索上新了
- 切片器可以设置日期格式?_切片器——一个筛选神器