A. The Fair Nut and Elevator

题目链接:https://codeforces.com/contest/1084/problem/A

题意:

一栋房子有n层楼,同时有个电梯(每次只能载一个人),每层楼都有ai个人。

当电梯从x层到y层时,花费电力|x-y|。

现在要求当电梯位于哪一层时,所有人上下两次费用最少。电梯每次到一层后若电梯里面没人会回到我们选定的楼层。

题解:

枚举电梯位于的层数模拟一下就好了。

代码如下:

#include <bits/stdc++.h>
using namespace std; const int N = ;
int a[N];
int n; int main(){
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int ans = ;
for(int x=;x<=n;x++){
int sum = ;
for(int i=;i<=n;i++)
sum+=(abs(x-i)+i+x-)*a[i]*;
ans=min(ans,sum);
}
printf("%d",ans);
return ;
}

B. Kvass and the Fair Nut

题目链接https://codeforces.com/contest/1084/problem/B

题意:

给出n个桶,每个桶里面都有一定高度的东西,现在要从里面总共减少s的高度。问最后桶里面最小高度的最大值是多少。当桶里面高度都为0而s为正时,则输出-1。

题解:

一开始听他们说是二分,的确二分也可以。但这题没这个必要,直接贪心就好了。

首先我们肯定减少高度较高的高度,当所有高度都一样时,这时就n个n个地减少,这样即可保证高度最小值最大。

代码如下:

#include <bits/stdc++.h>
#define INF 9999999999999999
using namespace std;
typedef long long ll;
const int N = ;
ll n,s,minx=INF;
ll v[N];
int main(){
cin>>n>>s;
for(int i=;i<=n;i++) scanf("%I64d",&v[i]),minx=min(minx,v[i]);
ll sum=;
for(int i=;i<=n;i++) sum+=(v[i]-minx);
if(sum>=s){
cout<<minx;
return ;
}
s-=sum;
ll now = s/n+(s%n!=);
ll ans = minx-now;
if(ans>=) cout<<ans;
else cout<<-;
return ;
}

The Fair Nut lives in nn story house. aiai people live on the ii-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening.

It was decided that elevator, when it is not used, will stay on the xx-th floor, but xx hasn't been chosen yet. When a person needs to get from floor aa to floor bb, elevator follows the simple algorithm:

  • Moves from the xx-th floor (initially it stays on the xx-th floor) to the aa-th and takes the passenger.
  • Moves from the aa-th floor to the bb-th floor and lets out the passenger (if aa equals bb, elevator just opens and closes the doors, but stillcomes to the floor from the xx-th floor).
  • Moves from the bb-th floor back to the xx-th.

The elevator never transposes more than one person and always goes back to the floor xx before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the aa-th floor to the bb-th floor requires |a−b||a−b|units of electricity.

Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the xx-th floor. Don't forget than elevator initially stays on the xx-th floor.

Codeforces Round #526 (Div. 2) A.B的更多相关文章

  1. [Codeforces Round #526 (Div. 2)]

    https://codeforces.com/contest/1084 A题 数据量很小,枚举就行 #include<iostream> #include<cstdio> #i ...

  2. Codeforces Round #526 (Div. 2) E. The Fair Nut and Strings

    E. The Fair Nut and Strings 题目链接:https://codeforces.com/contest/1084/problem/E 题意: 输入n,k,k代表一共有长度为n的 ...

  3. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path

    D. The Fair Nut and the Best Path 题目链接:https://codeforces.com/contest/1084/problem/D 题意: 给出一棵树,走不重复的 ...

  4. Codeforces Round #526 (Div. 2) C. The Fair Nut and String

    C. The Fair Nut and String 题目链接:https://codeforces.com/contest/1084/problem/C 题意: 给出一个字符串,找出都为a的子序列( ...

  5. Codeforces Round #526 Div. 1 自闭记

    日常猝死. A:f[i]表示子树内包含根且可以继续向上延伸的路径的最大价值,统计答案考虑合并两条路径即可. #include<iostream> #include<cstdio> ...

  6. Codeforces Round #526 (Div. 2) Solution

    A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...

  7. Codeforces Round #526 (Div. 1)

    毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...

  8. Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp

    D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...

  9. A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))

    A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...

随机推荐

  1. 中恳中笨 搭建flask封装环境

    话不多说,先干再说..... 打开pycharm,创建一个关于flask的项目 2.创建一个App的文件包 3.把staic和templates文件包拖进App里 4.把app.py文件改为manag ...

  2. nodejs环境变量配置

    步骤 创建文件夹:安装包 配置环境变量: export NODE_HOME=/root/安装包/node-v7.6.0-linux-x64 export PATH=$NODE_HOME/bin:$PA ...

  3. Kubernetes-设计理念(三)

    Kubernetes设计理念与分布式系统 分析和理解Kubernetes的设计理念可以使我们更深入的了解Kubernetes系统,更好的利用它管理分布式部署的云原生应用,另一方面也可以让我们借鉴其在分 ...

  4. JavaScript---设计模式简介

    概念 设计模式(Design pattern)是一套被反复使用.思想成熟.经过分类和无数次实战设计经验的总结的.使用设计模式是为了让系统代码可重用.可扩展.可解耦.更容易被人理解且能保证代码的可靠性. ...

  5. CentOS 7 systemd添加自定义系统服务

    systemd: CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,即:/usr/lib/systemd/syste ...

  6. 4 class类 web服务器

    1.换行符 2.pycharm 连接Ubuntu 1)添加环境变量 2)查看ip 3)配置目录 4)上传或者下载 3.面向对象抽象web服务器 1)版本1:类 class HttpServer(obj ...

  7. Gradle 设置本地meaven

    repositories { maven { url uri("F:\\meaven")} }

  8. 常用js方法合集

    var Default = { init: function () { }, addCookie: function (name,data) { var expdate = new Date(); / ...

  9. SGU刷题之路,开始了

    0. 关于SGU的简介 SGU的网址是:acm.sgu.ru 向不了解的同学介绍一下SGU这个题库: 1. 题目难度很高,题目大多很经典. 2. 其数据范围很小,时间和空间要求也都很小,同时很精确.甚 ...

  10. Qt 蓝牙部分翻译

    这是我第一次尝试翻译技术文档,自己英语太烂,一直不敢尝试,感谢生活,让我勇敢迈出这第一步. 大部分都是直译,如有不妥,还请制导. Qt Bluetooth The Bluetooth API prov ...