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日志,查看,如下 ...
随机推荐
- Python3.5学习之旅——day1
本节内容: 1.Python介绍 2.Hello World程序 3.变量\字符编码 4.用户输入 5.if-else语句 6.循环语句 一.Python介绍 Python是一种动态解释性的强类型定义 ...
- 如何查看NXP产品的供货计划?
大的半导体厂商一般会提供每个产品的生命周期计划,NXP的工业级IC一般供货10年,汽车级是15年,具体的时间可以在官网查询得到. 首先,打开NXP官网链接 产品长期供货计划,可以看到以下页面 接着,筛 ...
- ubuntu13.10更新sources.list
步骤: 1>设置网络连接方式,NAT 2>自动获取ip address 10.0.2.15 3>更新源soureces.list soureces.list deb http://m ...
- 怎么HTML表格中的所有字体居中?
一开始,我在table标签里加入align="center" 发现没什么用.... 后来在css里加入,就可以了 成果如图:
- Zenefits CodeSprint:Knight or Knave
题意是一堆人,从1到n编号,每个人i说一句话,x.x是正数表示i说x君是个好人,x是负数表示i说x君是坏人.问这个群体中最多能有多少好人,把这种情况用字典序的方式输出(好人用A表示,坏人用B表示),希 ...
- jdbc学习over
这次的代码和之前学习到一般的代码主要就是将一些很常见的操作(建立连接.清除连接)不管做什么操作都需要用到它们,所以将它们单独放到另一个工具类里面去. 用到的术语: 1.事务:https://www.c ...
- rhel7 系统服务——unit(单元)
Linux内核版本从3.10后开始使用systemd管理服务,这也是系统开机后的第一个服务.systemd通过unit单元文件来管理服务. 它保存了服务.设备.挂载点和操作系统其他信息的配置文件,并能 ...
- 设计模式课程 设计模式精讲 12-2 适配器模式coding
1 重要 1.1 类适配器和对象适配器最大的区别 2 代码演练 2.1 代码演练1(类适配器模式) 2.2 代码演练2(对象适配模式) 2.3 代码演练3(具体应用场景) 1 重要 1.1 类适配器和 ...
- UniGui学习之部署(06)只 有Loading...,
procedure TUniServerModule.UniGUIServerModuleBeforeInit(Sender: TObject);begin Self.ExtRoot:='ext-6. ...
- 反射工具类【ReflectionUtils】
反射工具类[ReflectionUtils] 原创 2017年05月05日 00:45:43 标签: java / 反射 / reflection / 893 编辑 删除 import java.la ...