C. Annoying Present SB题
2 seconds
256 megabytes
standard input
standard output
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 ii (1≤i≤n1≤i≤n) and for every j∈[1,n]j∈[1,n] adds x+d⋅dist(i,j)x+d⋅dist(i,j) to the value of the jj-th cell. dist(i,j)dist(i,j) is the distance between positions ii and jj (i.e. dist(i,j)=|i−j|dist(i,j)=|i−j|, where |x||x| is an absolute value of xx).
For example, if Alice currently has an array [2,1,2,2][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][2−1+2⋅2, 1−1+2⋅1, 2−1+2⋅0, 2−1+2⋅1] = [5,2,1,3][5,2,1,3]. Note that Bob can't choose position ii outside of the array (that is, smaller than 11 or greater than nn).
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?
The first line contains two integers nn and mm (1≤n,m≤1051≤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−103≤xi,di≤103) — the parameters for the ii-th change.
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−610−6.
2 3
-1 3
0 0
-1 -4
-2.500000000000000
3 2
0 2
5 0
7.000000000000000 这题分析一下题目 就是对d的正负进行分类讨论
d>=0 则选择 i=1; 反之 i=(n+1)/2;
代码量也特别少
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
const int INF = 0x3fffffff;
typedef long long LL;
using namespace std;
LL n, m, x, d, ans = ;
int main() {
scanf("%lld%lld", &n, &m);
for (int i = ; i < m ; i++) {
scanf("%lld%lld", &x, &d);
if (d >= ) ans += n * x + d * (n - ) * n / ;
else ans += n * x + d * (n - (n + ) / ) * ((n + ) / );
}
printf("%.8f\n", 1.0 * ans / n);
return ;
}
C. Annoying Present SB题的更多相关文章
- Codeforces 1009C: Annoying Present
C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 最小生成树(prim和Kruskal操!!SB题)
Arctic Network Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 30571 Accepted: 9220 D ...
- 多项式乘法,sb题
给定一个n,输出\((a1+x)*(a2+x)*...(an+x)\)的多项式长度. 每一个字符(包括"a"."x"."(".") ...
- 扔几道sb题
1.给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. 你能求 ...
- nyoj744——异或(sb题)
蚂蚁的难题(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 小蚂蚁童鞋最近迷上了位运算,他感觉位运算非常神奇.不过他最近遇到了一个难题: 给定一个区间[a,b] ...
- Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)
题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...
- NOIPSB评测机+SB题DAY2
忍者钩爪 题目描述 小 Q 是一名酷爱钩爪的忍者, 最喜欢飞檐走壁的感觉, 有一天小 Q 发现一个练习使用钩 爪的好地方,决定在这里大显身手. 场景的天花板可以被描述为一个无穷长的数轴, 初始小 Q ...
- 【Codeforces 1009C】Annoying Present
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...
- Annoying Present
http://codeforces.com/group/1EzrFFyOc0/contest/1009/problem/C 题意:原本有一个n个0的数组a[],你对它进行m次操作,每次操作让a[j]+ ...
随机推荐
- python基础,导入模块,if语句,while语句
python基础 python代码 变为字节码 变为机器码 最后执行执行‘文件名.py’文件时出现的‘文件名.pyc’文件为字节码 缓存机制 使用pycharm的时候在文件最开始添加下面这两行代码,中 ...
- 通过SVI实现VLAN间通信
两个不同网段的计算机与三层交换机直连,通过SVI实现VLAN间通信vlan 1 //几个不同网段就创建几个VLANvlan 2 int f0/1 //划分VLANswitchport mode acc ...
- 【Leetcode】807. Max Increase to Keep City Skyline
Description In a 2 dimensional array grid, each value grid[i][j] represents the height of a building ...
- 1321. [ZJOI2012] 灾难
1321. [ZJOI2012] 灾难 ★★☆ 输入文件:catas.in 输出文件:catas.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 阿米巴是小强的 ...
- 详解jQuery中 .bind() vs .live() vs .delegate() vs .on() 的区别
转载自:http://zhuzhichao.com/2013/12/differences-between-jquery-bind-vs-live/ 我见过很多开发者很困惑关于jQuery中的.bin ...
- 基于Mysql-Proxy实现Mysql的主从复制以及读写分离(下)
基于Mysql-Proxy实现Mysql的主从复制以及读写分离(下) 昨天谈到了Mysql实现主从复制,但由于时间原因并未讲有关读写分离的实现,之所以有读写分离,是为了使数据库拥有双机热备功能,至于双 ...
- OpenCV入门:(一:安装与配置)
看到的不是自己的,只有写下来的才是自己的,上次接触OpenCV实在三个月前,亢奋的看完了OpenCV自带的入门文档,觉得对图形处理有了一点点了解,现在三个月过去了,由于学习需要,想深入了解OpenCV ...
- SSH公钥认证(码云)
开发者向码云版本库写入最常用到的协议是 SSH 协议,因为 SSH 协议使用公钥认证,可以实现无口令访问,而若使用 HTTPS 协议每次身份认证时都需要提供口令.使用 SSH 公钥认证,就涉及到公钥的 ...
- Python 3基础教程30-sys模块
本文介绍sys模块,简单打印两个重定向输出. 目前使用机会没有,以后实际用到了,再去研究和学习.
- 机器学习性能指标精确率、召回率、F1值、ROC、PRC与AUC--周振洋
机器学习性能指标精确率.召回率.F1值.ROC.PRC与AUC 精确率.召回率.F1.AUC和ROC曲线都是评价模型好坏的指标,那么它们之间有什么不同,又有什么联系呢.下面让我们分别来看一下这几个指标 ...