Codeforces Round #526 (Div. 2) A.B
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的更多相关文章
- [Codeforces Round #526 (Div. 2)]
https://codeforces.com/contest/1084 A题 数据量很小,枚举就行 #include<iostream> #include<cstdio> #i ...
- 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的 ...
- 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 题意: 给出一棵树,走不重复的 ...
- 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的子序列( ...
- Codeforces Round #526 Div. 1 自闭记
日常猝死. A:f[i]表示子树内包含根且可以继续向上延伸的路径的最大价值,统计答案考虑合并两条路径即可. #include<iostream> #include<cstdio> ...
- Codeforces Round #526 (Div. 2) Solution
A. The Fair Nut and Elevator Solved. 签. #include <bits/stdc++.h> using namespace std; #define ...
- Codeforces Round #526 (Div. 1)
毕竟是上紫之后的第一场div1,还是太菜了啊,看来我要滚回去打div2了. A. The Fair Nut and the Best Path 这题本来是傻逼贪心dfs,结果我越写越麻烦,然后就只有1 ...
- Codeforces Round #526 (Div. 2) D. The Fair Nut and the Best Path 树上dp
D. The Fair Nut and the Best Path 题意:给出一张图 点有权值 边也要权值 从任意点出发到任意点结束 到每个点的时候都可以获得每个点的权值,而从边走的时候都要消耗改边的 ...
- A. The Fair Nut and Elevator (Codeforces Round #526 (Div. 2))
A. The Fair Nut and Elevator 好笨啊QAQ. 暴力枚举的题,连分类都不用. 从电梯初始位置到第一层.人到第一层.间隔的层数,往返路程. #include <bits/ ...
随机推荐
- mongodb的学习之旅一
描述 作为一枚菜鸟级别的coder,刚接触nodejs没有多久.现在在学习微信公众号的开发,但是碰到了mongodb保存用户数据的时候,出现了DeprecationWarning: Mongoose: ...
- Angularjs 跨域post数据到springmvc
先贴网上己有解决方案链接: http://www.tuicool.com/articles/umymmqY (讲的是springmvc怎么做才可以跨域) http://my.oschina.net/ ...
- 在WPF中自定义控件(3) CustomControl (上)
原文:在WPF中自定义控件(3) CustomControl (上) 在WPF中自定义控件(3) CustomControl (上) 周银辉 ...
- ASP.NET MVC文件上传【转】
最近用到了文件上传功能,下面给出ASP.NET MVC文件上传的一个简单示例: 一.前端代码 @using (Html.BeginForm("UploadFile", " ...
- Android开发——View动画、帧动画和属性动画详解
0. 前言 Android动画是面试的时候经常被问到的话题.我们都知道Android动画分为三类:View动画.帧动画和属性动画. 先对这三种动画做一个概述: View动画是一种渐进式动画,通过图 ...
- 配置ORACLE的PRO*C环境
1.访问数据库的方法 在ORACLE数据库管理和系统中,有三种访问数据库的方法: ⑴.用SQL*Plus, 它有SQL命令以交互的应用程序访问数据库: ⑵.用第四代语言应用开发工具开 ...
- Vm Ubuntu 文件共享问题
其实也是差不多的,就是需要重新安装一次工具 ,自己安装有问题,自己在手动安装一次就好了 下面是一个我的参考文章 http://blog.csdn.net/zz962/article/details/7 ...
- Toward Convolutional Blind Denoising of Real Photographs
本文提出了一个针对真实图像的盲卷积去噪网络,增强了深度去噪模型的鲁棒性和实用性. 摘要 作者提出了一个 CBD-Net,由噪声估计子网络和去噪子网络两部分组成. 作者设计了一个更加真实的噪声模型,同时 ...
- Tensorflow编程基础之Mnist手写识别实验+关于cross_entropy的理解
好久没有静下心来写点东西了,最近好像又回到了高中时候的状态,休息不好,无法全心学习,恶性循环,现在终于调整的好一点了,听着纯音乐突然非常伤感,那些曾经快乐的大学时光啊,突然又慢慢的一下子出现在了眼前, ...
- C#程序中SQL语句作为函数参数形式问题
今天遇到一个神奇现象,目前正在写一个Demo,人事管理系统,首先肯定是初始化主页面,在初始化时,需要声明一个登陆窗体,但是当我在登陆窗体中填入登入名称和密码时直接就登陆成功了,但是发现我的status ...