【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 ...
随机推荐
- Nginx(三) 常用配置整理
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debug | ...
- Quartz定时调度jar包的执行Demo分享
1.Quartz简介 Quartz框架的核心是调度器.调度器负责管理Quartz应用运行时环境.调度器不是靠自己做所有的工作,而是依赖框架内一些非常重要的部件.Quartz不仅仅是线程和线程管理. ...
- 基于Web的Kafka管理器工具之Kafka-manager启动时出现Exception in thread "main" java.lang.UnsupportedClassVersionError错误解决办法(图文详解)
不多说,直接上干货! 前期博客 基于Web的Kafka管理器工具之Kafka-manager的编译部署详细安装 (支持kafka0.8.0.9和0.10以后版本)(图文详解) 问题详情 我在Kaf ...
- Javascript DOM 编程艺术(第二版)读书笔记——基本语法
Javascript DOM 编程艺术(第二版),英Jeremy Keith.加Jeffrey Sambells著,杨涛.王建桥等译,人民邮电出版社. 学到这的时候,我发现一个问题:学习过程中,相当一 ...
- 一个完整的网站记录(springmvc hibernate juery bootstrap)
总述 该网站为了满足测试人员自主添加测试条目,编辑更新信息和删除信息,同时同步到后台数据库的基本功能. 关键技术:oracle数据库.tomcat8.5.springMVC.Hibernate.aja ...
- Farseer.net轻量级开源框架 入门篇:使用前说明
导航 目 录:Farseer.net轻量级开源框架 目录 上一篇:Farseer.net轻量级开源框架 入门篇: 框架性能测试 下一篇:Farseer.net轻量级开源框架 入门篇: 增.删.改. ...
- ubuntu部署java环境
一.安装java sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracl ...
- HDU_2112_最短路
题目链接:http://acm.hdu.edu.cn/status.php?user=l1526789512&pid=2112&status=5 HDU Today Time Limi ...
- [HNOI2006]最短母串 (AC自动机+状压)
Description 给定n个字符串(S1,S2,„,Sn),要求找到一个最短的字符串T,使得这n个字符串(S1,S2,„,Sn)都是T的子串. Input 第一行是一个正整数n(n<=12) ...
- 00Extensible Markup Language
Extensible Markup Language XML(Extensible Markup Language)可扩展标记语言是用来网络数据的组织结构,传输及存储.