URAL 2092 Bolero 贪心
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
| input | output |
|---|---|
6 2 |
2680.00 |
Notes
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll; #define MM(a,b) memset(a,b,sizeof(a));
#define inf 0x7f7f7f7f
#define FOR(i,n) for(int i=1;i<=n;i++)
#define CT continue;
#define PF printf
#define SC scanf
const int maxn=100000+10; struct node{
ll val;int id;
bool operator<(const node &a) const{
return this->val>a.val;
}
};
vector<int> G[105];
priority_queue<node> q;
int num[105],g[105];
int main()
{
int n,m;
while(~SC("%d%d",&n,&m)){
ll ori=0,ans=0;
for(int i=0;i<=100;i++) G[i].clear();
FOR(i,n) {
int cost,p;
SC("%d%d",&cost,&p);
ori+=cost*(100-p);
G[p].push_back(cost);
}
for(int i=0;i<=100;i++) sort(G[i].begin(),G[i].end());
MM(num,inf);
FOR(i,m){
int peo,dis;
SC("%d%d",&peo,&dis);
num[dis]=min(num[dis],peo);
}
// PF("111111\n");
ans=ori;
FOR(k,100){
if(num[k]>n) CT;
MM(g,0);
// PF("2222222\n");
ll tmp=ori,cnt=0;
for(int i=0;i<=k;i++)
for(int j=0;j<G[i].size();j++){
tmp+=G[i][j]*(i-k);cnt++;
}
// PF("3333333\n");
while(q.size()) q.pop();
for(int i=k+1;i<=100;i++) {
if(G[i].size()) q.push((node){G[i][0]*(i-k),i});
g[i]=1;
}
// PF("444444\n");
while(cnt<num[k]){
node u=q.top();q.pop();
tmp+=u.val;
cnt++;
if(g[u.id]<G[u.id].size()){
int r=g[u.id];
q.push((node){G[u.id][r]*(u.id-k),u.id});
g[u.id]++;
}
}
ans=min(ans,tmp);
}
PF("%.2f\n",(double)ans/100.00);
}
return 0;
}
错点:如果直接枚举优惠券的优惠值大小k(0-100),然后,计算出每种票在此优惠券下的可优惠
价格,再sort排下序是100*1e5*log1e5是会超时的,所以需要优化一下,考虑买单个票的时候,打的折
<=k的必须要算(可优惠),对于>k的,对每种k,每次都只能选其中的一种(贪心),所以,可用优先队列将复杂度降到1e5log100,
注意==k的也必须要贪啊,,因为要让大与k的数量尽可能小
URAL 2092 Bolero 贪心的更多相关文章
- D - Binary Lexicographic Sequence URAL - 1081 (贪心)
题目链接:https://cn.vjudge.net/contest/275079#problem/D 具体思路:首先,我们可以观察到1-n位数的种数连起来是一个很有规律的数列,然后我们开始倒序建立. ...
- 贪心 URAL 1303 Minimal Coverage
题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l < ...
- ural 1303 Minimal Coverage【贪心】
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...
- URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场
比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...
- ural 1303 Minimal Coverage(贪心)
链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 按照贪心的思想,每次找到覆盖要求区间左端点时,右端点最大的线段,然后把要求覆盖的区间 ...
- URAL 1203 Scientific Conference dp?贪心
题目:click here 分明就是贪心怎么会在dp的专题 #include <bits/stdc++.h> using namespace std; typedef unsigned l ...
- URAL 1203 Scientific Conference(贪心 || DP)
Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校.补多校的题目.刷一下一直薄弱的DP.多校假设有计算几何一定要干掉-.- 题意:给 ...
- URAL 1995 Illegal spices 贪心构造
Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, m ...
- URAL 2021 Scarily interesting! (贪心+题意)
题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. ...
随机推荐
- 使用python的ctypes库实现内存的动态申请和释放
1.申请前内存占用情况 2.申请内存 from ctypes import * import time #在这里申请1G的内存,单位k mem = create_string_buffer(1024* ...
- ueditor 编译出错
错误 CS0433 类型“Uploader”同时存在于“com.80community.xy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=nul ...
- js循环遍历性能
定length for循环 (有length) 不定length for循环(使用数组length) 不定length for循环(判断数组length是否存在) forEach(Array自带,对某 ...
- PostgreSQL 初学常用实用命令
常用命令 psql -h ip -p port -U user -d dbName 数据库 \dt(当前数据库所有表) \l(所有数据库) \c(切换数据库) \d 表名(查看表结构) table \ ...
- element-ui 中 el-table 根据scope.row行数据变化动态显示行内控件
加入本行的数据为scope.row,其数据格式为 { "propertyId": 4, "propertyName": "标题", &quo ...
- U盘安装 CentOS7图解
参考 https://jingyan.baidu.com/article/e75aca856cca69142fdac673.html
- IIS出现Server Error in '/' Application 错误的解决办法
C:\Windows\Temp"文件夹加上 IIS_IUSRS的权限
- linux命令详解——sed
sed是一个很好的文件处理工具,本身是一个管道命令,主要是以行为单位进行处理,可以将数据行进行替换.删除.新增.选取等特定工作,下面先了解一下sed的用法 sed命令行格式为: se ...
- 【转】全志A10/A20 Bootloader加载过程分析
原文 : http://blog.csdn.net/allen6268198/article/details/12905425 从这里开始:http://linux-sunxi.org/Bootabl ...
- SQL语句复习【专题九】
SQL语句复习[专题九] 视图:View视图的概念:视图是从若干基本表或其他视图构造出来的表.在创建一个视图时,只是存放的视图的定义,也即是动态检索数据的查询语句,而并不存放视图对应的数据在用户使用视 ...