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 集合竞价 解题报告的更多相关文章

  1. CH Round #56 - 国庆节欢乐赛解题报告

    最近CH上的比赛很多,在此会全部写出解题报告,与大家交流一下解题方法与技巧. T1 魔幻森林 描述 Cortana来到了一片魔幻森林,这片森林可以被视作一个N*M的矩阵,矩阵中的每个位置上都长着一棵树 ...

  2. 二模13day1解题报告

    二模13day1解题报告 T1.发射站(station) N个发射站,每个发射站有高度hi,发射信号强度vi,每个发射站的信号只会被左和右第一个比他高的收到.现在求收到信号最强的发射站. 我用了时间复 ...

  3. BZOJ 1051 最受欢迎的牛 解题报告

    题目直接摆在这里! 1051: [HAOI2006]受欢迎的牛 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4438  Solved: 2353[S ...

  4. 习题:codevs 2822 爱在心中 解题报告

    这次的解题报告是有关tarjan算法的一道思维量比较大的题目(真的是原创文章,希望管理员不要再把文章移出首页). 这道题蒟蒻以前做过,但是今天由于要复习tarjan算法,于是就看到codevs分类强联 ...

  5. 习题:codevs 1035 火车停留解题报告

    本蒟蒻又来写解题报告了.这次的题目是codevs 1035 火车停留. 题目大意就是给m个火车的到达时间.停留时间和车载货物的价值,车站有n个车道,而火车停留一次车站就会从车载货物价值中获得1%的利润 ...

  6. 习题: codevs 2492 上帝造题的七分钟2 解题报告

    这道题是受到大犇MagHSK的启发我才得以想出来的,蒟蒻觉得自己的代码跟MagHSK大犇的代码完全比不上,所以这里蒟蒻就套用了MagHSK大犇的代码(大家可以关注下我的博客,友情链接就是大犇MagHS ...

  7. 习题:codevs 1519 过路费 解题报告

    今天拿了这道题目练练手,感觉自己代码能力又增强了不少: 我的思路跟别人可能不一样. 首先我们很容易就能看出,我们需要的边就是最小生成树算法kruskal算法求出来的边,其余的边都可以删掉,于是就有了这 ...

  8. NOIP2016提高组解题报告

    NOIP2016提高组解题报告 更正:NOIP day1 T2天天爱跑步 解题思路见代码. NOIP2016代码整合

  9. LeetCode 解题报告索引

    最近在准备找工作的算法题,刷刷LeetCode,以下是我的解题报告索引,每一题几乎都有详细的说明,供各位码农参考.根据我自己做的进度持续更新中......                        ...

随机推荐

  1. git push上传代码到gitlab上,报错401/403(或需要输入用户名和密码)

    之前部署的gitlab,采用ssh方式连接gitlab,在客户机上产生公钥上传到gitlab的SSH-Keys里,git clone下载和git push上传都没问题,这种方式很安全. 后来应开发同事 ...

  2. kvm虚拟化管理平台WebVirtMgr部署-完整记录(0)

    打算部署kvm虚拟机环境,下面是虚拟化部署前的一些准备工作: 操作系统环境安装1)修改内核模式为兼容内核启动[root@ops ~]# uname -aLinux openstack 2.6.32-4 ...

  3. js实现随机的四则运算题目(2)-更新界面

    上次的代码提交完成后,有很多bug.比如函数会重复调用执行,每点击一次按钮都会在生成题目的下方直接生成新的题目,于是我在代码前面添加了如下的代码: function play_allE() { doc ...

  4. M2阶段团队贡献分

    根据任务完成情况与之前的评分标准,我们给组员分数如下: 团队成员 最终得分 程刚 51 李睿琦 53 刘丽萍 50 刘宇帆 48 王力民 47 马佐霖 49 左少辉 52

  5. 团队作业Week14——源代码管理

    0. 在吹牛之前,先回答这个问题: 如果你的团队来了一个新队员,有一台全新的机器, 你们是否有一个文档,只要设置了相应的权限,她就可以根据文档,从头开始搭建环境,并成功地把最新.最稳定版本的软件编译出 ...

  6. 《linux内核设计与实现》第四章

    调度程序负责决定哪个进程投入运行,何时运行以及运行多长时间.只有通过调度程序合理调度,系统资源才能最大限度发挥作用,多进程才会有并发执行的效果. 最大限度地利用处理器时间的原则是,只要有可以执行的进程 ...

  7. [ERROR] Failed to execute goal org.codehaus.mojo:gwt-maven-plugin:2.5.0-rc1:compile (default) on project zeus-web: Command 解决

    在编译maven项目,打包maven packeage -Dmaven.test.skip=TRUE时,报错“[ERROR] Failed to execute goal org.codehaus.m ...

  8. Tomcat & Servlet

    javaWeb javaWeb是指使用java技术实现所有web程序的技术的总称.我们称之为javaWeb. 1.请求和响应(成对出现) 2.Web资源的分类 web资源分为两大类,分别是静态资源和动 ...

  9. Maven -Maven配置tomcat插件 两种

    Maven Tomcat插件现在主要有两个版本,tomcat-maven-plugin和tomcat7-maven-plugin,使用方式基本相同. tomcat-maven-plugin 插件官网: ...

  10. ERROR 2003: Can't connect to MySQL server on 'host ip'(10060)

    https://forums.mysql.com/read.php?51,99347,99358 https://dev.mysql.com/doc/refman/5.7/en/can-not-con ...