ural1316 Electronic Auction
Electronic Auction
Memory limit: 64 MB
Input
- “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
Sample
| input | output |
|---|---|
BID 0.01 |
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的更多相关文章
- 1316. Electronic Auction(树状数组)
1316 我想说 要不要这么坑 WA了一个小时啊 ,都快交疯了,拿着题解的代码交都WA 最后很无语的觉得题解都错了 重读了N遍题意 发现没读错啊 难道写题解的那个人和我都想错了?? 最后把g++换个C ...
- Electronic oscillator
https://en.wikipedia.org/wiki/Electronic_oscillator An electronic oscillator is an electronic circui ...
- Electronic Payment App analysis
Electronic Payment App is getting more and more popular now. People don't have to bring credit cards ...
- 维克里拍卖 Vickrey auction
https://en.wikipedia.org/wiki/Vickrey_auction 维克里拍卖(Vickrey auction),即次价密封投标拍卖(Second-price sealed-b ...
- 【BZOJ-1974】auction代码拍卖会 DP + 排列组合
1974: [Sdoi2010]auction 代码拍卖会 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 305 Solved: 122[Submit ...
- EMR,电子病历(Electronic Medical Record)
电子病历 电子病历(EMR,Electronic Medical Record),也叫计算机化的病案系统或称基于计算机的病人记录(CPR,Computer-Based Patient Record). ...
- electronic data interchange 电子数据交换
electronic data interchange 电子数据交换
- WordPress Ultimate Auction插件跨站请求伪造漏洞
漏洞名称: WordPress Ultimate Auction插件跨站请求伪造漏洞 CNNVD编号: CNNVD-201306-396 发布时间: 2013-09-11 更新时间: 2013-09- ...
- BZOJ 1974: [Sdoi2010]auction 代码拍卖会( dp )
在1, 11, 111……中选<=8个, + 11..(n个1)拼出所有可能...这些数mod p至多有p中可能, 找出循环的处理一下. 那么dp就很显然了...dp(i, j, k)表示前i种 ...
随机推荐
- javascript小数乘法精确率问题
做前端页面开发的经常会遇到数值的乘法计算,带小数位计算会出现值溢出的问题,如: JS里做小数的乘法运算时会出现浮点错误,具体可以测试一下: <script>alert(11*22.9)&l ...
- 校验 MD5 值
Linux 环境下:打开终端,输入命令:"md5sum filename",将结果与网页提供值对比.Windows 环境下:下载 MD5 校验软件并使用.
- laravel多种安装方法
首先请确保环境为 PHP >= 5.5.9 OpenSSL PHP 扩展 PDO PHP 扩展 Mbstring PHP 扩展 Tokenizer PHP 扩展 方法一: 直接下载安装好的lar ...
- Let'sencrypt认证的网站Https配置
推荐使用这个脚本,具体说明里面都有 https://github.com/xdtianyu/scripts/tree/master/le-dns 它是通过调用dns服务商的api更新txt记录实现,无 ...
- Row_Number实现分页
1:首先是 select ROW_NUMBER() over(order by id asc) as 'rowNumber', * from table1 生成带序号的集合 2:再查询该集合的 第 1 ...
- UITextfield的一些属性
//设置左视图 不用设置frame UIImageView *imageV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@&quo ...
- merge 语句的语法
/*Merge into 详细介绍 MERGE语句是Oracle9i新增的语法,用来合并UPDATE和INSERT语句. 通过MERGE语句,根据一张表或子查询的连接条件对另外一张表进行查询, 连接条 ...
- cURL: Learning..
CURL usage.. -v, -m, -H, -I, -s, --connect-timeout, -x, -X GET|POST, -d, -T, -o. --retry, -u curl [o ...
- ThreadLocal类及常用的线程安全类探究
1.ThreadLocal类 ThreadLocal是Thread Local Variable的简称,意思是线程局部变量.作用是为每一个使用该变量的线程都提供一个该变量的副本,使每一个线程都能独立操 ...
- linux下环境变量PS1设置
PS1变量中提示符各项含义: \d :代表日期,格式为weekday month date,例如:Wed Dec 12 \H :完整的主机名称.例如:hostname是debian.linux \ ...