就是有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的更多相关文章

  1. 【转载】Recommendations with Thompson Sampling (Part II)

    [原文链接:http://engineering.richrelevance.com/recommendations-thompson-sampling/.] [本文链接:http://www.cnb ...

  2. <Programming Collective Intelligence> Chapter2:Making Recommendations

    <Programming Collective Intelligence> Chapter2:Making Recommendations 欧几里得距离评价 皮尔逊相关度评价 它相比于欧几 ...

  3. C# - Recommendations for Abstract Classes vs. Interfaces

     The choice of whether to design your functionality as an interface or an abstract class can somet ...

  4. xDB and sitecore 8 hardware Recommendations

    xDB and sitecore 8 hardware Recommendations as below: xDB hardware guidelines https://doc.sitecore.n ...

  5. XML Publisher Report Issues, Recommendations and Errors

    In this Document   Purpose   Questions and Answers   References APPLIES TO: Oracle Process Manufactu ...

  6. Netflix Recommendations

    by Xavier Amatriain and Justin Basilico (Personalization Science and Engineering) In part one of thi ...

  7. 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 ...

  8. 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 ...

  9. 【RS】Amazon.com recommendations: item-to-item collaborative filtering - 亚马逊推荐:基于物品的协同过滤

    [论文标题]Amazon.com recommendations: item-to-item collaborative filtering (2003,Published by the IEEE C ...

  10. 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日志,查看,如下 ...

随机推荐

  1. 二十二、mysql 执行计划与存储引擎

    1.explain(执行计划)中涉及的各字段理解1.1) select_type列的取值及含义:    SIMPLE                 :简单的SELECT语句(不包括UNION操作或子 ...

  2. vue 之 axios Vue路由与element-UI

    一. 在组件中使用axios获取数据 1. 安装和配置axios 默认情况下,我们的项目中并没有对axios包的支持,所以我们需要下载安装. 在项目根目录中使用 npm安装包 npm install ...

  3. js中的原生Ajax和JQuery中的Ajax

    AJAX = Asynchronous JavaScript and XML(异步的 JavaScript 和 XML). js中的Ajax: 参数介绍: open(String method,Str ...

  4. 牛茶冲天的ip命令

    一.修改二层链路相关设置 1.修改网卡名称(修改前要先停止) ip link set eth0 name  testname 2.修改网卡地址 ip link set eth0 address xxx ...

  5. day 11 笔记

    # 装饰器形成的过程 : 最简单的装饰器 有返回值的 有一个参数 万能参数 # 装饰器的作用 # 原则 :开放封闭原则 # 语法糖 :@ # 装饰器的固定模式 #不懂技术 import time # ...

  6. spring demo

    参考: https://www.tutorialspoint.com/spring/spring_applicationcontext_container.htm

  7. 腾讯玄武实验室向(CNVD)提交了一个重大漏洞“BucketShock”

    导读 11 月 21 日,在小米 IoT 安全峰会上,腾讯安全玄武实验室负责人于旸(花名:TK 教主)在演讲中透露,腾讯玄武实验室最近向国家信息安全漏洞共享平台(CNVD)提交了一个重大漏洞“Buck ...

  8. 物联网协议CoAP协议学习

    CoAP:Constrained Application Protocol协议是为物联网中资源受限的设备制定的应用层协议,即简化版的基于UDP的HTTP协议.其核心内容为资源抽象.REST式交互可扩展 ...

  9. How to backup on MSSQL by table level ?

    MSSQL is good database.   Unlike as Oracle,  it seems that can not backup sqlserver databasee tables ...

  10. redhat 7.6 ssh 服务配置

    安装ssh yum install openssh 查看端口 netstat -ntpl netstat -ntpl | grep :22 启动和关闭 service sshd restart/sta ...