csp20141203 集合竞价 解题报告
Solution:
对股票出价进行排序,然后按照价格递增的次序依次设定p的价格并求成交量。
1.
//prove that the result of price(maximum--maxprice) is info[k].price:
//If not,the nearest data that is bigger than price
//result=maxresult & price>maxprice , conflict
2.
//po assending as times by
//so if maxamount is the same, use the newest
3.buy
先比较并设置maxamount值
再 买单 减
4.
sell
先 卖单 加
再比较并设置maxamount值
注意
1.出价价格的重复性
2.buy sell出价价格相同
3.数据2^64内的范围,用long long 或__int64。
而c注意用%I64d或%lld。而与购买股数有关的变量全部用long long 或__int64,不要遗漏,如min和max函数要用到long long 或__int64。
当你的程序为80分时,就是第三点没考虑。
建议:
把buy,sell合并或分开都可以,把相同价格的值分开或合并都可以,虽然后者时间效率会高一点,
但是无疑考试期间把把buy,sell合并,不把相同价格的值合并更容易写,更容易理解,也不容易写错。
#include <iostream>
#include <stdlib.h>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 8000 //The softest way to write a right code in a competition
//Just time limite, we don't need to write the best code(in time aspect) struct node
{
double price;
//mode: 1:sell 0:buy
//why put sell ahead of buy?
//sell:add & buy:delete --- we need maximum
long amount,mode;
}info[maxn+]; bool cmp(struct node a,struct node b)
{
if (a.price<b.price)
return true;
else if (a.price>b.price)
return false;
else if (a.mode>b.mode)
return true;
else
return false;
} __int64 min(__int64 a,__int64 b)
{
if (a>b)
return b;
else
return a;
} int main()
{
long g,pos,ans,i,b[maxn+],c[maxn+];
__int64 x,y,z,maxamount;
double a[maxn+],maxprice;
char s[];
bool vis[maxn+];
//use stdlib.h faster!
g=;
while (scanf("%s",s)!=EOF)
{
g++;
if (strcmp(s,"cancel")==)
{
scanf("%ld",&pos);
vis[g]=false;
vis[pos]=false;
}
else
{
//pay attention:%lf double a[]
scanf("%lf%ld",&a[g],&b[g]);
if (strcmp(s,"sell")==)
c[g]=;
else
c[g]=;
vis[g]=true;
}
}
ans=;
for (i=;i<=g;i++)
if (vis[i])
{
info[ans].price=a[i];
info[ans].amount=b[i];
info[ans].mode=c[i];
ans++;
}
sort(info,info+ans,cmp);
//prove that the result of price(maximum--maxprice) is info[k].price:
//If not,the nearest data that is bigger than price
//result=maxresult & price>maxprice , conflict //choose
//in >= po
//out <= po //po assending as times by
//so if maxamount is the same, use the newest //buy
x=;
for (i=;i<ans;i++)
if (info[i].mode==)
x+=info[i].amount;
//sell
y=;
maxamount=;
for (i=;i<ans;i++)
//when po is info[i].price
//buy
if (info[i].mode==)
{
z=min(x,y);
if (z>=maxamount)
{
maxamount=z;
maxprice=info[i].price;
}
x-=info[i].amount;
}
//sell
else
{
y+=info[i].amount;
z=min(x,y);
if (z>=maxamount)
{
maxamount=z;
maxprice=info[i].price;
}
}
//数据默认maxamount>0
printf("%.2lf %I64d",maxprice,maxamount);
return ;
}
csp20141203 集合竞价 解题报告的更多相关文章
- CH Round #56 - 国庆节欢乐赛解题报告
最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...
- 二模13day1解题报告
二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...
- BZOJ 1051 最受欢迎的牛 解题报告
题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 4438 Solved: 2353[S ...
- 习题:codevs 2822 爱在心中 解题报告
这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...
- 习题:codevs 1035 火车停留解题报告
本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...
- 习题: codevs 2492 上帝造题的七分钟2 解题报告
这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...
- 习题:codevs 1519 过路费 解题报告
今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...
- NOIP2016提高组解题报告
NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合
- LeetCode 解题报告索引
最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中...... ...
随机推荐
- SQL中not in 和not exists
在SQL中倒是经常会用到子查询,而说到子查询,一般用的是in而不是exists,先不谈效率问题,就先说说会遇到哪些问题. 用到in当取反的时候,肯定先想到的就是not in.但是在使用not in的时 ...
- Software Engineering homework2
现在市面上有诸多软件,选取一类软件,请分析: Q1:此类软件是什么时候出现的,这些软件是怎么说服你(陌生人)成为它们的用户的?他们的目标都是盈利的么?他们的目标都是赚取用户的现金的么?还是别的? A1 ...
- 第一个Sprint
项目名字:四则运算APP 开发环境:java 团队名称:会飞的小鸟 团队成员:陈志棚 李炫宗 刘芮熔 徐侃 罗伟业 一.经过宿舍世纪讨论后我们剔除了一些不合理的设计,比如网站管理员这一部分在 ...
- 递归拼装Tree结构数据
@Override public List<Map<String, Object>> queryListTree() { List<Map<String,Objec ...
- Dynamic Routing Based On Redis
Dynamic Routing Based On Redis Ngnix技术研究系列2-基于Redis实现动态路由 上篇博文我们写了个引子: Ngnix技术研究系列1-通过应用场景看Nginx的反 ...
- NullPointerException-----开发中遇到的空指针异常
1.使用CollectionUtils.isEmpty判断空集合 public class TestIsEmpty { static class Person{} static class Girl ...
- mysql 记录根据日期字段倒序输出
我们知道倒序输出是很简单的 select * from table order by id desc 直接这样就可以 那么现在的问题在于日期字段怎么来倒序输出 这里我们用到cast()来将指定的字段转 ...
- Java和Android的Lru缓存,及其实现原理
一.概述 Android提供了LRUCache类,可以方便的使用它来实现LRU算法的缓存.Java提供了LinkedHashMap,可以用该类很方便的实现LRU算法,Java的LRULinkedHas ...
- linux学习之centos(四):git的安装
整个流程如下:(参考文章:linux安装git方法) [carsonzhu@localhost 桌面]$ wget https://github.com/git/git/archive/v2.8.3. ...
- pandas聚合aggregate
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2018/5/24 15:03 # @Author : zhang chao # @Fi ...