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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值