D - Recommendations
就是有n组,每组的数量是num,只能增加数字,增加的代价为t,求能使所有组的数量都不同的最小代价。
#include<bits/stdc++.h>
#define N 200005
#define endl '\n'
#define _for(i,a,b) for(int i=a;i<b;i++)
using namespace std;
typedef long long ll;
struct Node{
int num; ll t;
bool operator < (const Node &o){
return t>o.t;
}
}a[N];
map<int,int > F;
int find(int k){
if(F[k]==){
return k;
}
else return F[k]=find(F[k]);
}
void link(int a,int b){
int fa=find(a),fb=find(b);
if(fa!=fb) F[fa]=fb;
}
ll res;
int main(){
ios::sync_with_stdio(),cin.tie(),cout.tie();
int n ; cin>>n;
_for(i,,n+) cin>>a[i].num;
_for(i,,n+) cin>>a[i].t;
sort(a+,a+n+);
_for(i,,n+){
int tem=a[i].num;
int to= find(tem);
link(to,to+);
if( to == tem ) ;
else {
res+= 1ll*(to-tem)*a[i].t;
}
}
cout<<res<<endl;
return ;
}
#include<bits/stdc++.h> #define N 200005#define endl '\n' #define _for(i,a,b) for(int i=a;i<b;i++)using namespace std;typedef long long ll; struct Node{int num; ll t;bool operator < (const Node &o){ return t>o.t;}}a[N];map<int,int > F;int find(int k){if(F[k]==0){return k;}else return F[k]=find(F[k]); }void link(int a,int b){int fa=find(a),fb=find(b);if(fa!=fb) F[fa]=fb;}ll res;int main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n ; cin>>n;_for(i,1,n+1) cin>>a[i].num;_for(i,1,n+1) cin>>a[i].t;sort(a+1,a+n+1);_for(i,1,n+1){int tem=a[i].num;int to= find(tem);link(to,to+1);if( to == tem ) ;else { res+= 1ll*(to-tem)*a[i].t;}}cout<<res<<endl;return 0;}
D - Recommendations的更多相关文章
- 【转载】Recommendations with Thompson Sampling (Part II)
[原文链接:http://engineering.richrelevance.com/recommendations-thompson-sampling/.] [本文链接:http://www.cnb ...
- <Programming Collective Intelligence> Chapter2:Making Recommendations
<Programming Collective Intelligence> Chapter2:Making Recommendations 欧几里得距离评价 皮尔逊相关度评价 它相比于欧几 ...
- C# - Recommendations for Abstract Classes vs. Interfaces
The choice of whether to design your functionality as an interface or an abstract class can somet ...
- xDB and sitecore 8 hardware Recommendations
xDB and sitecore 8 hardware Recommendations as below: xDB hardware guidelines https://doc.sitecore.n ...
- XML Publisher Report Issues, Recommendations and Errors
In this Document Purpose Questions and Answers References APPLIES TO: Oracle Process Manufactu ...
- Netflix Recommendations
by Xavier Amatriain and Justin Basilico (Personalization Science and Engineering) In part one of thi ...
- Best Practices and Recommendations for RAC databases with SGA size over 100GB (文档 ID 1619155.1)
Best Practices and Recommendations for RAC databases with SGA size over 100GB (文档 ID 1619155.1) APPL ...
- 1950261 - SAP HANA Database Backup Policy Recommendations and Regular Backup Script
=====Symptom For SAP Business One, version for SAP HANA users, SAP HANA provides a range of database ...
- 【RS】Amazon.com recommendations: item-to-item collaborative filtering - 亚马逊推荐:基于物品的协同过滤
[论文标题]Amazon.com recommendations: item-to-item collaborative filtering (2003,Published by the IEEE C ...
- ambari-server启动报错500 status code received on GET method for API:/api/v1/stacks/HDP/versions/2.4/recommendations Error message : Server Error解决办法(图文详解)
问题详情 来源是,我在Ambari集群里,安装Hue. 给Ambari集群里安装可视化分析利器工具Hue步骤(图文详解 所遇到的这个问题. 然后,去ambari-server的log日志,查看,如下 ...
随机推荐
- dojo框架笔记
一.模块定义 1.定义只含值对,没有任何依赖的模块(moudle1.js) define({ color: "black", size: "unisize" } ...
- Nginx+Openssl实现HTTPs(重点)
[root@localhost ~]# rz -E //导入jdk源码包 z waiting to receive.**B0100000023 ...
- Flask - 运行APP
from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return 'Hello, ...
- input、raw_input区别,运算符,运算优先级,多变赋值方式
目录 1. Python2中的input.raw_input赋值方式和Python3中的input赋值方式的差别 2. 运算符 3. python运算符优先级 4. 格式化输出 5. 链式赋值 6. ...
- Vue——解决报错 Computed property "****" was assigned to but it has no setter.
在最近的项目中遇到了如下的警告信息: [Vue warn]: Computed property " currentStep" was assigned to but it has ...
- 借助工具解决DNS污染
我第一次接触到DNS污染,是在GitHub上面进行学习的时候,发现头像加载出问题,加载失败,而且文档里面的图片也无法显示...... 百度了很多内容,差不多都试了一下,最终选择了使用DNS工具去解决 ...
- Microsoft Cortana移动版除美国市场外不再可用
导读 先前已经透露,Microsoft Cortana的移动版本已不复存在.目前,Microsoft Cortana在移动设备上的多个国家和地区中支持多种语言.微软的Cortana移动版本不再支持的市 ...
- vs code 本地调试配置
{ "name": "使用本机 Chrome 调试", "type": "chrome", "request& ...
- Mybatis 条件判断单双引号解析问题
最近使用 Mybatis 遇到了一个奇怪的问题,前端传了一个数字字符串(type = "1") ,我做了如下判断: <if test=" type == '1' & ...
- hbase meta中分区信息错误的记录
bulk write hbase 时遇到下面的错误: 19/03/20 02:16:02 ERROR LoadIncrementalHFiles: IOException during splitti ...