C - Bolero

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

Description

Winter in Yekaterinburg is the longest time of the year. And everyone spends long winter evenings in his own way. Denis is a big fan of classical music, at least twice a week he attends concerts at the Philharmonic.
This year, Denis wants to buy tickets for the whole season at once and even already has chosen a list of concerts, which he wants to attend. Now, he thinks, how to buy tickets. There is an opportunity in the Philharmonic to choose any k or more concerts and to buy a single subscription for all of them. The cost of this subscription will be equal to the total cost of all concerts in it but with a discount ppercent. There are many types of such subscriptions, with different k and p. In addition, for some concerts Denis, as a student, has a discount. This discount is valid only if he buys the ticket separately, outside the subscription.
Denis, like any other poor student, wants to attend all the concerts, spending as little money as possible. However, he knows that there are always more people wanting to attend a concert than the number of seats in the Philharmonic hall. So he will not buy more than one ticket for one concert (separately or in a subscription), even if it allows him to save money.

Input

The first line contains integers n and m that are the number of concerts Denis wants to attend, and a number of different subscription types at the Philharmonic (2 ≤ n ≤ 10 5; 1 ≤ m ≤ 10 5). The i-th of the following n lines contains integers si and di that are the price of a ticket and the discount for students in percent at the i-th concert (100 ≤ si ≤ 50 000; 0 ≤ di ≤ 100). The  j-th of the following m lines contains integers kj and pj that are the minimum number of concerts that can be combined in the subscription of the j-th type, and a discount for it in percent (2 ≤ kj ≤ n; 1 ≤ pj ≤ 100).

Output

Output the minimum amount of money Denis has to spend to attend all the concerts. The answer should be given with an absolute or relative error not exceeding 10 −6.

Sample Input

input output
6 2
500 0
700 0
300 0
400 0
500 50
800 0
5 10
6 15
2680.00

Notes

In the example, Denis needs to buy a subscription of the first type (with 10% discount) for all concerts, except the fifth one, and to buy a ticket for the fifth concert with a student discount of 50%.
#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 贪心的更多相关文章

  1. D - Binary Lexicographic Sequence URAL - 1081 (贪心)

    题目链接:https://cn.vjudge.net/contest/275079#problem/D 具体思路:首先,我们可以观察到1-n位数的种数连起来是一个很有规律的数列,然后我们开始倒序建立. ...

  2. 贪心 URAL 1303 Minimal Coverage

    题目传送门 /* 题意:最少需要多少条线段能覆盖[0, m]的长度 贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优 接着就是从p=0开始,以p点为标志,选取 (node[i].l < ...

  3. ural 1303 Minimal Coverage【贪心】

    链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/contest/view ...

  4. URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场

    比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全 ...

  5. ural 1303 Minimal Coverage(贪心)

    链接: http://acm.timus.ru/problem.aspx?space=1&num=1303 按照贪心的思想,每次找到覆盖要求区间左端点时,右端点最大的线段,然后把要求覆盖的区间 ...

  6. URAL 1203 Scientific Conference dp?贪心

    题目:click here 分明就是贪心怎么会在dp的专题 #include <bits/stdc++.h> using namespace std; typedef unsigned l ...

  7. URAL 1203 Scientific Conference(贪心 || DP)

    Scientific Conference 之前一直在刷计算几何,邀请赛连计算几何的毛都买见着,暑假这一段时间就做多校.补多校的题目.刷一下一直薄弱的DP.多校假设有计算几何一定要干掉-.- 题意:给 ...

  8. URAL 1995 Illegal spices 贪心构造

    Illegal spices 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=1995 Description Jabba: Han, m ...

  9. URAL 2021 Scarily interesting! (贪心+题意)

    题意:给定两个队伍的每个人的得分,让你安排怎么比赛才能使得观众知道冠军的时间最长. 析:贪心,很简单,就是先开始总分高的先出最差劲的,总分低的先出最厉害的,这个题当时实在是读的不明白啊,WA了好多次. ...

随机推荐

  1. django 模块查询

    # 查询轮播图slider_list = Slider.objects.filter(type = constants.SLIDER_TYPE_INDEX) # 查询新闻now_time = date ...

  2. C#异步编程学习笔记之-async和await(续)

    书接上文,本篇主要记录的内容要点:1.针对async和await在实际应用中的使用方式:2.异步方法返回值(有返回值和无返回值)的两种情况: 示例一(无返回值): using System; usin ...

  3. The method getContextPath() from the type HttpServletRequest

    在做java项目开发的时候,jsp页面很容易报出这个错误. 错误的原因很多,但是都和JRE有关. 一般在导入项目的时候容易报出这个错误,主要因为JRE(jdk版本不一致). 解决方法:就是重新配置路径 ...

  4. python之uWSGI和WSGI

    WSGI协议 首先弄清下面几个概念:WSGI:全称是Web Server Gateway Interface,WSGI不是服务器,python模块,框架,API或者任何软件,只是一种规范,描述web ...

  5. Shell脚本case语句

    case语句格式 case 变量 in PAT1) 执行语句 ;; PAT2) 执行语句 ;; *) 默认执行语句 ;; esac 使用示例: 编写一个shell脚本,通过提示用户输入信息,输出cpu ...

  6. 关于api接口以及页面数据通信域名,缓存cdn设置优化

    以B站为例: 主域名:www.bilibili.com 账户登录注册相关域名,包括app登录:passport.bilibili.com 静态资源css,js,img等相关域名:static.bili ...

  7. 基于Dockerfile搭建JAVA Tomcat运行环境

    前言 在第一篇文字中,我们完全人工方式,一个命令一个命令输入,实现一个java tomcat运行环境,虽然也初见成效,但很累人.如果依靠依靠脚本构建一个Tomcat容器实例,一个命令可以搞定,何乐而不 ...

  8. Oracle笔记(五) 单行函数

    虽然各个数据库都是支持SQL语句的,但是每一个数据库也有每一个数据库自己所支持的操作函数,这些就是单行函数,而如果要想进行数据库开发的话,除了要会使用SQL之外 ,就是要多学习函数. 单行函数主要分为 ...

  9. 蓝牙App漏洞系列分析之一CVE-2017-0601

    蓝牙App漏洞系列分析之一CVE-2017-0601 0x01 概要 2017年5月的 Android 安全公告修复了我们提交的一个蓝牙提权中危漏洞,这个漏洞尽管简单,但比较有意思,能够使本地恶意 A ...

  10. JVM 字节码指令手册 - 查看 Java 字节码

    JVM 字节码指令手册 - 查看 Java 字节码 jdk 进行的编译生成的 .class 是 16 进制数据文件,不利于学习分析.通过下命令 javap -c Demo.class > Dem ...