Minimize the error
思路
贪心:先把a[i]-b[i]的绝对值存入优先队列,在一 一取出最大值,每次把top元素减一,再把结果的绝对值存入队列。直到操作次数用完,在统计一下结果就好了。
代码
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int n,k1,k2;
const int N=1e3+5;
ll a[N],b[N];
priority_queue<ll> q;
int main(){cin >> n >> k1 >> k2;int sum=k1+k2;for(int i=0;i<n;i++){cin >> a[i];}for(int i=0;i<n;i++){cin >> b[i];}for(int i=0;i<n;i++){q.push(abs(a[i]-b[i]));}while(sum--){ll t=q.top();q.pop();t--;q.push(abs(t));}ll ans=0;while(q.size()){ll t=q.top();q.pop();ans+=t*t;}cout << ans;
}
Minimize the error相关推荐
- 19 Error handling and Go go语言错误处理
Error handling and Go go语言错误处理 12 July 2011 Introduction If you have written any Go code you have pr ...
- webapck运行报错- css-loader minimize
在使用css-loader的minimize时报错: ERROR in ./index.css (./node_modules/css-loader/dist/cjs.js??ruleSet[1].r ...
- 基于DQN强化学习训练一个超级玛丽
点击上方"小白学视觉",选择加"星标"或"置顶" 重磅干货,第一时间送达 Author:MyEncyclopedia From:MyEncy ...
- 棋盘格检测--Automatic camera and range sensor calibration using a single shot
Automatic camera and range sensor calibration using a single shot Robotics and Automation (ICRA), IE ...
- 基于TensorFlow理解三大降维技术:PCA、t-SNE 和自编码器
ythonista 数据科学家 Elior Cohen 近日在 Medium 上发文解读了最常见的三大降维技术:PCA.t-SNE 和自编码器.为了帮助理解,他还为其中每种相关算法编写了代码(也发布在 ...
- 资源推荐 | TensorFlow电子书《FIRST CONTACT WITH TENSORFLOW》
资源推荐 | TensorFlow电子书<FIRST CONTACT WITH TENSORFLOW> 2016-06-29 系统科学社 本书由 UPC Barcelona Tech大学教 ...
- 李宏毅深度学习——Tips for Deep Learning
目录 一.神经网络的表现 二.改进神经网络 (一)梯度消失以及改进办法 (二)Adaptive Learning Rate (三)Local minimize问题 三.解决overfitting (一 ...
- Matlab神经网络十讲(7): Adaptive Filter and Adaptive Training
1. Adaptive Function The function adapt can change the weight and bias of a network incrementally du ...
- 机器人学习--Hans Moravec在斯坦福博士论文1980年-Obstacle Avoidance and Navigation in the Real World by a Seeing Ro
Hans Moravec,占用栅格地图的发明人. Obstacle Avoidance and Navigation in the Real World by a Seeing Robot Rover ...
最新文章
- DFA在C#中的实现:过滤敏感词
- js、PHP将分数字符串转换为小数
- HDUOJ-----Brave Game
- 编程php分析器,如何编程访问分析器数据
- jboss默认进程名称_快速指南:剖析JBoss BPM跨进程通信
- case mybatis 不同表_解决mybatis case when 报错的问题
- python装饰器class_PYTHON里的装饰器能装饰类吗
- Tomcat详解(四)——Tomcat配置详解
- sqlmap批量扫描burpsuite拦截的日志记录
- .net5项目托管到iis无法访问
- r2d 小米路由器2_维修一台亮黄灯的R2D小米路由器2
- android qq分享纯图片,手机照片批量上传QQ空间一键分享省流量
- DOM及DOM二级事件
- 资深运维也不知道的那些事
- UE4材质初探(转载)
- 南卫理公会大学计算机科学,南卫理公会大学计算机科学专业.pdf
- Cesium 源码解析 Model(一)
- 55 非谓语动词语法
- 能ping通ip却不能ping通域名
- 史上最易懂——一文详解线性回归算法的纯Python实现