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日志,查看,如下 ...
随机推荐
- vue.js 第九课
这次讲红色框框. 方法与事件处理器: 方法处理器: 内联语句处理器: 事件修饰符: 按键修饰符: 为什么在HTML中监听事件? 1.v-on绑定事件 带参数 2.事件对象$event: 有时也需要调用 ...
- 图解jvm--(四)内存模型
内存模型 java 内存模型 很多人将[java 内存结构]与[java 内存模型]傻傻分不清,[java 内存模型]是 Java Memory Model(JMM)的意思. 简单的说,JMM 定义了 ...
- python脚本调用iftop 统计业务应用流量
因公司服务器上部署应用较多,在有大并发访问.业务逻辑有问题的情况下反复互相调用或者有异常流量访问的时候,需要对业务应用进行故障定位,所以利用python调用iftop命令来获取应用进程流量,结合zab ...
- ubuntu-18.04 修改用户名密码
1. 开放root登录 设置root密码 $ sudo passwd root 切换到root 用户 $ sudo -i 修改/etc/pam.d/gdm-autologin $ vim /etc/p ...
- 【转】bug management process
What is Bug? A bug is the consequence/outcome of a coding fault What is Defect? A defect is a variat ...
- MFC中写入汉语到文本文档
目录 1.首先要引入头文件 2.在打开文件后,要进行设置,然后在关闭文档时,进行设置的后处理 3.输出的文本 1.首先要引入头文件 #include <locale> 2.在打开文件后,要 ...
- Java基础 -4.4
For循环 for循环也是一种常规的使用结构 public static void main(String[] args) { for(定义循环的初始值;循环判断;修改循环条件) { 循环语句的执行; ...
- Java--对象与类(二)
final 实例域 可以将实例域定义为final.构建对象时必须初始化这样的域.也就是说在一个构造器执行之后,这个域被设置,并且之后无法对其修改 final 修饰符大多应用于基本(primitive) ...
- SpringCloud入门——(1)创建Eureka项目
Eureka是Spring Cloud Netflix微服务套件中的一部分,可以与Springboot构建的微服务很容易的整合起来.Eureka包含了服务器端和客户端组件.服务器端,也被称作是服务注册 ...
- JS html页面
js窗口置顶 if (window != top) top.location.href = location.href; js打开新窗口 js window.open()弹出窗口参数说明及居中设置 f ...