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 ...
最新文章
- iOS:(接口适配器3)--iPhone适应不同型号 6/6plus 前
- redis持久化策略梳理及主从环境下的策略调整记录
- SAP建议客户将UI技术迁移到Fiori的六大原因
- Ubuntu16.04下制作deb包的方法详解
- CCF201412-2 Z字形扫描
- java web权限设计_java web简单权限管理设计
- base64图裁剪 php_3分钟短文 | 有挑战!PHP用1个函数实现post请求,你用哪个?
- Linux驱动开发-编写OLED显示屏驱动
- Java算法面试题(008) 字符串反转
- 常用IP扫描工具整理一下
- Element-Ui组件 单选框(Radio) 修改点击激活时的文本颜色,填充色和边框色
- 简单几步实现Ubuntu22.04启用Nvidia显卡
- [附源码]Python计算机毕业设计Django的小区宠物管理系统
- 基于微信小程序的组装机配置商城设计与实现-计算机毕业设计源码+LW文档
- 2003服务器系统QQ安装不了,qq怎么安装不了(QQ怎么都安装不上重装也不行,是哪里出了问题?)...
- SciML求解简谐振动的微分方程
- python中的多线程 GIL(全局解释器锁) 死锁与递归锁
- SpringMVC——过滤器
- MysqlSql数据库事务特性
- android 寺库trytry_wpf 中使用 ttf
热门文章
- crx什么意思_CRX文件怎么打开-CRX是什么格式-CRX文件是什么意思-腾牛网
- 省市县三级联动封装邮编数据列表
- 奇迹mu修改服务器名,奇迹MU 红名设置调整方案说明
- 奇迹 与服务器连接中断,奇迹少女连接服务器失败 连接不上网络怎么办
- 1-十四烷基-3-甲基咪唑六氟磷酸盐([C14MIm][PF6])修饰纳米SiO2二氧化硅(mg级瓶装)
- c语言中gets与puts,请教puts和gets函数
- 【LOJ2863】【IOI2018】组合动作(交互)
- php 多版本 安装包下载,wamp 安装多版本php
- 笔记本一直提示计算机内存不足怎么办,电脑总是提醒内存不足怎么办,电脑提醒内存不足-...
- Blender图解教程:手把手教你独立游戏开发必备的极简式贴图法