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. python快速改造:基础知识

    改造"Hacking"并不同于破坏"cracking" python快速改造:基础知识 一行就是一行,不管多少,不用加分号 交互式python解释器可以当作计算 ...

  2. 密码发生器 南阳acm519

    密码发生器 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 在对银行账户等重要权限设置密码的时候,我们常常遇到这样的烦恼:如果为了好记用生日吧,容易被破解,不安全:如 ...

  3. android staido 断点遇到的坑

    今天排查数据布点问题,发现sd卡上面的文件莫名消失. 怎么可能?系统不可能删除你的文件,但是我调试,删除文件的代码, 一直都没有执行啊. 后来发现,子线程里面代码,android stadio 可能断 ...

  4. java Spring boot使用spring反射

    spring 反射 当你配置各种各样的bean时,是以配置文件的形式配置的,你需要用到哪些bean就配哪些,spring容器就会根据你的需求去动态加载,你的程序就能健壮地运行. 1.可以通过类名去实例 ...

  5. Hibernate-ORM:15.Hibernate中的Criteria查询

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客讲师Hibernate中的Criteria查询! 一,Criteria简介: 刚接触Hibernate ...

  6. runtime总结 iOS

    Runtime的特性主要是消息(方法)传递,如果消息(方法)在对象中找不到,就进行转发,具体怎么实现的呢.我们从下面几个方面探寻Runtime的实现机制. Runtime介绍 Runtime消息传递 ...

  7. Django admin源码剖析

    单例模式 单例模式(Singleton Pattern)是一种常用的软件设计模式,该模式的主要目的是确保某一个类只有一个实例存在.当你希望在整个系统中,某个类只能出现一个实例时,单例对象就能派上用场. ...

  8. virtualBox 安装 CentOs 6.8 以及网络配置

    安装 virtual box 基本设置: 1.创建虚拟电脑 类型:Linux 版本:Red Hat(64-bit) 这个64/32 和电脑具体配置关系. 然后就是路next or 设置常规的东西. 2 ...

  9. Hyperledger04

    代码 'use strict'; var Fabric_Client = require('fabric-client'); var path = require('path'); var util ...

  10. android命令模式IntentService 远程下载文件

    服务可用在一下情景: 1,用户离开activity后,仍需要继续工作,例如从网络下载文件,播放音乐. 2,无论activity出现或离开,都需要持续工作,例如网络聊天应用. 3,连接网络服务,正在使用 ...