当前位置: 首页 > news >正文

北京网站开发服务商移动网站seo

北京网站开发服务商,移动网站seo,惠州市网站建设公司,wordpress导入汉化包你的任务是为交易所设计一个订单处理系统。要求支持以下3种指令。 BUY p q#xff1a;有人想买#xff0c;数量为p#xff0c;价格为q。 SELL p q#xff1a;有人想卖#xff0c;数量为p#xff0c;价格为q。 CANCEL i#xff1a;取消第i条指令对应的订单#xff08;输…你的任务是为交易所设计一个订单处理系统。要求支持以下3种指令。 BUY p q有人想买数量为p价格为q。 SELL p q有人想卖数量为p价格为q。 CANCEL i取消第i条指令对应的订单输入保证该指令是BUY或者SELL。 交易规则如下对于当前买订单若当前最低卖价低于当前出价则发生交易对于当前卖订单若当前最高买价高于当前价格则发生交易。发生交易时按供需物品个数的最小值交易。交易后需修改订单的供需物品个数。当出价或价格相同时按订单产生的先后顺序发生交易。 样例 输入 11 BUY 100 35 CANCEL 1 BUY 100 34 SELL 150 36 SELL 300 37 SELL 100 36 BUY 100 38 CANCEL 4 CANCEL 7 BUY 200 32 SELL 500 30输出 QUOTE 100 35 - 0 99999 QUOTE 0 0 - 0 99999 QUOTE 100 34 - 0 99999 QUOTE 100 34 - 150 36 QUOTE 100 34 - 150 36 QUOTE 100 34 - 250 36 TRADE 100 36 QUOTE 100 34 - 150 36 QUOTE 100 34 - 100 36 QUOTE 100 34 - 100 36 QUOTE 100 34 - 100 36 TRADE 100 34 TRADE 200 32 QUOTE 0 0 - 200 30分析 一个订单成交过的部分不能取消。 解法 use std::{collections::{BinaryHeap, HashMap},io::{self, Read}, }; struct Order {_id: usize,amount: usize,price: usize,op: String, } #[derive(Debug, PartialEq, Eq)] struct Buy {id: usize,amount: usize,price: usize, } impl Ord for Buy {fn cmp(self, other: Self) - std::cmp::Ordering {if self.price ! other.price {self.price.cmp(other.price)} else {other.id.cmp(self.id)}} } impl PartialOrd for Buy {fn partial_cmp(self, other: Self) - Optionstd::cmp::Ordering {Some(self.cmp(other))} } #[derive(Debug, PartialEq, Eq)] struct Sell {id: usize,amount: usize,price: usize, } impl Ord for Sell {fn cmp(self, other: Self) - std::cmp::Ordering {if self.price ! other.price {other.price.cmp(self.price)} else {other.id.cmp(self.id)}} } impl PartialOrd for Sell {fn partial_cmp(self, other: Self) - Optionstd::cmp::Ordering {Some(self.cmp(other))} } fn main() {let mut buf String::new();io::stdin().read_line(mut buf).unwrap();let n: usize buf.trim().parse().unwrap();let mut orders: VecOrder vec![];let mut buy_list: BinaryHeapBuy BinaryHeap::new();let mut sell_list: BinaryHeapSell BinaryHeap::new();let mut buy_amount_price HashMap::new();let mut sell_amount_price HashMap::new();buy_list.push(Buy {id: usize::MAX,amount: 0,price: 0,});sell_list.push(Sell {id: usize::MAX,amount: 0,price: 99999,});buy_amount_price.insert(0, 0);sell_amount_price.insert(99999, 0);let mut bvalid: Vecbool vec![true; n];let mut buf String::new();io::stdin().read_to_string(mut buf).unwrap();let mut lines buf.lines();for i in 0..n {let mut it lines.next().unwrap().split_whitespace();let cmd it.next().unwrap();let v: Vecusize it.map(|x| x.parse().unwrap()).collect();if cmd CANCEL {orders.push(Order {_id: i,amount: 0,price: 0,op: cmd.to_string(),});let cancel_id v[0] - 1;let aorder orders[cancel_id];if aorder.op BUY bvalid[cancel_id] {if let Some(x) buy_amount_price.get_mut(aorder.price) {*x - aorder.amount;}} else if aorder.op SELL bvalid[cancel_id] {sell_amount_price.entry(aorder.price).and_modify(|x| *x - aorder.amount);}bvalid[cancel_id] false;} else if cmd BUY || cmd SELL {let id i;let amount v[0];let price v[1];let op cmd.to_string();if cmd BUY {buy_list.push(Buy { id, amount, price });buy_amount_price.entry(price).and_modify(|x| *x amount).or_insert(amount);} else {sell_list.push(Sell { id, amount, price });sell_amount_price.entry(price).and_modify(|x| *x amount).or_insert(amount);}let a Order {_id: id,amount,price,op,};orders.push(a);}trade(cmd.to_string(),mut buy_list,mut sell_list,mut buy_amount_price,mut sell_amount_price,mut orders,bvalid,);let price buy_list.peek().unwrap().price;print!(QUOTE {} {}, buy_amount_price.get(price).unwrap(), price);let price sell_list.peek().unwrap().price;print!( - {} {}, sell_amount_price.get(price).unwrap(), price);println!();} }fn trade(op: String,buy_list: mut BinaryHeapBuy,sell_list: mut BinaryHeapSell,buy_amount_price: mut HashMapusize, usize,sell_amount_price: mut HashMapusize, usize,orders: mut VecOrder,bvalid: Vecbool, ) {while buy_list.len() 1 sell_list.len() 1 {let buy buy_list.peek().unwrap();let sell sell_list.peek().unwrap();if buy.price sell.price {break;}if !bvalid[buy.id] {buy_list.pop();continue;}if !bvalid[sell.id] {sell_list.pop();continue;}let mut buy buy_list.pop().unwrap();let mut sell sell_list.pop().unwrap();let min_amount buy.amount.min(sell.amount);orders[buy.id].amount - min_amount;orders[sell.id].amount - min_amount;buy.amount - min_amount;sell.amount - min_amount;buy_amount_price.entry(buy.price).and_modify(|x| *x - min_amount);sell_amount_price.entry(sell.price).and_modify(|x| *x - min_amount);if op BUY {println!(TRADE {} {}, min_amount, sell.price);} else if op SELL {println!(TRADE {} {}, min_amount, buy.price);}if buy.amount 0 {buy_list.push(buy);}if sell.amount 0 {sell_list.push(sell);}}//如果队首是被取消的订单while buy_list.len() 1 {let buy buy_list.peek().unwrap();if bvalid[buy.id] {break;}buy_list.pop();}while sell_list.len() 1 {let sell sell_list.peek().unwrap();if bvalid[sell.id] {break;}sell_list.pop();} }
http://www.w-s-a.com/news/172743/

相关文章:

  • 企业网站建设市场的另一面wordpress分类插件
  • 网站建设名头公司展厅装修
  • 小型购物网站开发费用郑州企业网站模板建站
  • 个体商户建自己的网站做销售建设积分兑换官方网站
  • 网站建设与维护培训网页制作专业用语
  • 建站特别慢wordpress网页制作与设计项目策划书
  • 视频制作素材免费网站头像制作在线生成器
  • 网站建设是不是可以免费建站广州做网站 信科网络
  • 闸北区网站设计叫别人做网站后怎么更改密码
  • 为什么想做网站运营建设工程教育网站
  • 站长基地百度推广整体优化网站
  • 门窗 东莞网站建设wordpress外链论坛
  • 安徽省建设部网站官网还能用的wap网站
  • 企业网站设计开发网站关键词优化seo
  • 郑州高档网站建设台州网站建设推广
  • 广东省建设信息港网站WordPress手机缩略图设置
  • 优秀网站主题平顶山专业做网站公司
  • wordpress返回顶部插件wordpress站群seo
  • 企业网站建设报价表百度竞价托管哪家好
  • 织梦网站首页打开慢淄博网站推广那家好
  • 苏州高端网站建设kgwl互动网站建设的主页
  • 宿州网站建设哪家公司好个人网站制作方法
  • 网站正能量晚上在线观看视频站长之家关键词挖掘工具
  • 建设网站怎么判断是电脑还是手机仿租号网站源码网站开发
  • seo百度网站排名软件重庆巫山网站设计公司
  • 搭建视频播放网站网站排名诊断
  • 网站域名注册网站centos做网站服务器
  • 网站服务器共享的 vpsh5页面制作软件电脑版
  • 免费手机网站申请上海网站建设设计公司哪家好
  • 站长工具大全企业网上书店网站建设设计