Electronic Auction

Time limit: 0.5 second
Memory limit: 64 MB
There is a deficit in cast-iron pigs in the country. They are sold at an electronic auction. Customers make their bids: announce a price at which they are ready to buy a pig. From time to time a seller puts up for sale К pigs at a price of X bibriks each. The first К customers who offered the same or higher price get one pig each.
Customers may cancel their bids (after a purchase a bid remains valid until it is canceled). Only bids made in a current month are valid, so each month a customer should renew his bid. If a seller did not sell all the pigs offered for sale, then the unsold pigs remain at his storehouse and don’t participate in the auction any more.
Each sold cast-iron pig makes a profit of 0.01 bibriks for the auction. Having a month's log of auction operations, you are to calculate the profit of the auction in this month.

Input

The input contains a month's operations log, one operation per line. There are three types of operations:

  • “BID X” — a customer announces that he is ready to buy a pig at a price of X bibriks;
  • “DEL X” — a customer cancels his bid for a pig at a price of X bibriks;
  • “SALE X K” — a seller puts up for sale К pigs at a price of X bibriks.

X is between 0.01 and 10000.00 bibriks and has at most 2 digits after the decimal point. K is an integer between 1 and 100000. The number of operations does not exceed 100000. All operations are correct. The last line contains the word “QUIT”.

Output

Output the profit of the auction in the current month with 2 digits after the decimal point.

Sample

input output
BID 0.01
BID 10000
BID 5000
BID 5000
SALE 7000 3
DEL 5000
SALE 3000 3
SALE 0.01 3
QUIT
0.06

分析:离散化+树状数组;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <hash_map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
const int dis[][]={,,-,,,-,,};
using namespace std;
using namespace __gnu_cxx;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,a[maxn],num;
double c[maxn];
ll ans;
struct node
{
char a[];
double b;
int c;
}op[maxn];
void add(int x,int y)
{
for(int i=x;i<=num;i+=(i&(-i)))
{
a[i]+=y;
}
}
int get(int x)
{
int ans=;
for(int i=x;i;i-=(i&(-i)))
ans+=a[i];
return ans;
}
int main()
{
int i,j;
while(~scanf("%s",op[++n].a)&&op[n].a[]!='Q')
{
scanf("%lf",&op[n].b);
c[n]=op[n].b;
if(op[n].a[]=='S')scanf("%d",&op[n].c);
}
n--;
sort(c+,c+n+);
num=unique(c+,c+n+)-c-;
rep(i,,n)op[i].b=lower_bound(c+,c+num+,op[i].b)-c;
rep(i,,n)
{
if(op[i].a[]=='B')add((int)op[i].b,);
else if(op[i].a[]=='D')add((int)op[i].b,-);
else ans+=min(op[i].c,get(num)-get((int)op[i].b-));
}
printf("%.2f\n",(double)ans/);
//system("Pause");
return ;
}

ural1316 Electronic Auction的更多相关文章

  1. 1316. Electronic Auction(树状数组)

    1316 我想说 要不要这么坑 WA了一个小时啊 ,都快交疯了,拿着题解的代码交都WA 最后很无语的觉得题解都错了 重读了N遍题意 发现没读错啊 难道写题解的那个人和我都想错了?? 最后把g++换个C ...

  2. Electronic oscillator

    https://en.wikipedia.org/wiki/Electronic_oscillator An electronic oscillator is an electronic circui ...

  3. Electronic Payment App analysis

    Electronic Payment App is getting more and more popular now. People don't have to bring credit cards ...

  4. 维克里拍卖 Vickrey auction

    https://en.wikipedia.org/wiki/Vickrey_auction 维克里拍卖(Vickrey auction),即次价密封投标拍卖(Second-price sealed-b ...

  5. 【BZOJ-1974】auction代码拍卖会 DP + 排列组合

    1974: [Sdoi2010]auction 代码拍卖会 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 305  Solved: 122[Submit ...

  6. EMR,电子病历(Electronic Medical Record)

    电子病历 电子病历(EMR,Electronic Medical Record),也叫计算机化的病案系统或称基于计算机的病人记录(CPR,Computer-Based Patient Record). ...

  7. electronic data interchange 电子数据交换

    electronic data interchange 电子数据交换

  8. WordPress Ultimate Auction插件跨站请求伪造漏洞

    漏洞名称: WordPress Ultimate Auction插件跨站请求伪造漏洞 CNNVD编号: CNNVD-201306-396 发布时间: 2013-09-11 更新时间: 2013-09- ...

  9. BZOJ 1974: [Sdoi2010]auction 代码拍卖会( dp )

    在1, 11, 111……中选<=8个, + 11..(n个1)拼出所有可能...这些数mod p至多有p中可能, 找出循环的处理一下. 那么dp就很显然了...dp(i, j, k)表示前i种 ...

随机推荐

  1. git clone 太慢怎么办?

    Git 和 GitHub 的出现打开了开源世界的另一扇大门,版本控制变得更强大(也更复杂),项目的管理变得更加容易,项目的开发也变得更容易进行多人协作.GitHub 无疑是程序员的 Facebook ...

  2. 解读QML之一

    http://cache.baiducontent.com/c?m=9d78d513d98002b8599dcb201a17a7374408c6347691c4523f8a9c12d522195646 ...

  3. groupbox 下的datagridview的列标题字体修改混乱

        groupbox 下的datagridview的列标题字体修改混乱

  4. 获取表空间的语句 以及 建表和索引的ddl

    alter session set container=PHD1; SET SERVEROUTPUT ON SET LINESIZE SET FEEDBACK OFF SET PAGESIZE sel ...

  5. 在idea的maven项目使用el或jstl表达式

    必须加上这句: <%@ page isELIgnored="false" %> 否则无法解析el或jstl表达式 <%@ taglib prefix=" ...

  6. 基于Sublime Text搭建Python IDE

    http://loosky.net/2967.html(包括SublimeREPL插件的安装和设置快捷键) SublimeCodeIntel,智能提示功能,查找自定义函数引用的快捷键--Alt+鼠标左 ...

  7. linux进程、管道和重定向

    1.shell先后使用fork和exec系统调用来执行一个外部命令. 2.在linux系统中,有三个文件会被内核自动打开,分别是stdin.stdout.stderr. 3.进程的属性相关命令: 查看 ...

  8. spark中groupByKey与reducByKey

    [译]避免使用GroupByKey Scala Spark 技术   by:leotse 原文:Avoid GroupByKey 译文 让我们来看两个wordcount的例子,一个使用了reduceB ...

  9. ecshop后台增加模块菜单项详细教程(图文)

    有的时候我们会在后台增加新的功能,菜单项是一个程序的入口,是必不可少的,如何在后台增加菜单项呢,大家可以参考下面的教程:   例如:想在后台左侧的菜单栏的"促销管理"下添加一个&q ...

  10. Ubuntu Linux系统下apt-get命令详解

    整理了Ubuntu Linux操作系统下apt-get命令的详细说明,分享给大家.常用的APT命令参数: apt-cache search package 搜索包 apt-cache show pac ...