【Codeforces 1009C】Annoying Present
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
其实就是让你最后这n个数字的和最大。
加上的x没有关系。因为肯定都是加上n个x
所以直接加上就可以了
主要在于如何选取j
显然我们要找到一个位置j.
然后pre[j]+aft[j]的值最大(pre[j]=1+2+3+...+j-1,aft类似
(这是在d大于0的时候,小于0的时候找pre[j]+aft[j]最小的就好)
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5;
int n,m;
ll x[N+10],d[N+10];
ll pre[N+10],aft[N+10];
ll ma,maidx = 1,mi,miidx = 1;
double ans = 0;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= m;i++) cin >> x[i] >> d[i];
for (int i = 1;i <= n;i++){
pre[i] = pre[i-1]+i-1;
}
for (int i = n;i >= 1;i--){
aft[i] = aft[i+1] + (n-i);
}
ma = pre[1]+aft[1];
for (int i = 2;i <= n;i++){
ll temp = pre[i]+aft[i];
if (temp>ma){
ma = temp;
maidx = i;
}
}
mi = pre[1]+aft[1];
for (int i = 2;i <= n;i++){
ll temp = pre[i]+aft[i];
if (temp<mi){
mi = temp;
miidx = i;
}
}
for (int i = 1;i <= m;i++){
ans = ans + n*x[i];
if (d[i]<0){
ans = ans + mi*d[i];
}else{
ans = ans + ma*d[i];
}
}
ans = 1.0*ans / n;
cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
}
【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 4D】Mysterious Present
[链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【39.66%】【codeforces 740C】Alyona and mex
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 758A】Holiday Of Equality
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【13.91%】【codeforces 593D】Happy Tree Party
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【26.67%】【codeforces 596C】Wilbur and Points
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 764B】Timofey and cubes
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 766C】Mahmoud and a Message
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- centOS命令随笔记(杂):cd、pwd
1.向上向下翻页: 反向的命令一般是Shift-PageUp和Shift-PageDown. 每日一命令:cd 1.cd / 进入系统根目录 2.cd .. 进入系统根目录可以使用“ cd . ...
- E20170527-ts
asset n. 资产,财产; 有价值的人或物; 有用的东西; 优点; serializer [词典] 串行(化)器(把并行数据变成串行数据的寄存器); 编程语言中,可被序列化的; inflec ...
- 树网的核 2007年NOIP全国联赛提高组(floyed)
树网的核 2007年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description [问题描述]设 T= ...
- LoadRunner监控Linux配置教程
LoadRunner监控Linux资源时弹出如下错误: Monitor name :UNIX Resources. Cannot initialize the monitoring on 192.16 ...
- Pycharm初始创建项目和环境搭建(解决aconda库文件引入不全等问题)
1.新建工程 1.选择新建一个Pure Python项目,新建项目路径可以在Location处选择. 2.Project Interpreter部分是选择新建项目所依赖的python库,第一个选项会在 ...
- STL之set和multiset
set是与集合相关的容器,STL为我们提供了set的实现,在编程题中遇见集合问题直接调用是十分方便 SET set模版类的定义在头文件<set>中. 定义set对象的示例代码如下: set ...
- DHTML_____window对象的事件
<html> <head> <meta charset="utf-8"> <title>window对象事件</title&g ...
- Shell脚本,简单& 强大
摘自<码农增刊Linus与Linux>,章节:你可能不知道的Shell. 最近阅读完这本书,觉得其中有很多不错的内容,这是其中的一个Shell小甜点,拿来和大家一起分享一下,增加了 ...
- ASP.NET控件之RadioButtonList
“RadioButtonList”控件表示一个封装了一组单选按钮控件的列表控件. 可以使用两种类型的 ASP.NET 控件将单选按钮添加到网页上:各个“RadioButton”控件或一个“RadioB ...
- Python(1)-第一天
PTVS下载地址:https://pytools.codeplex.com/releases/view/109707 Python下载地址:https://www.python.org/downloa ...