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. 初级Java工程师面试所遇面试题

    1.servlet的生命周期 : 一.百度百科 : 1.客户端请求servlet: 2.加载servlet类到内存: 3.实例化并调用init()方法初始化servlet: 4.调用service() ...

  2. Iptables防火墙规则使用梳理

    iptables是组成Linux平台下的包过滤防火墙,与大多数的Linux软件一样,这个包过滤防火墙是免费的,它可以代替昂贵的商业防火墙解决方案,完成封包过滤.封包重定向和网络地址转换(NAT)等功能 ...

  3. C. Ehab and a 2-operation task

    链接 [https://codeforces.com/contest/1088/problem/C] 题意 n个数,最多n+1操作,要么前i个数加x,要么前i个数对x取余,最后使得严格递增 分析 直接 ...

  4. M1事后分析汇报以及总结

    一.设想和目标 1. 们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 我们的软件主要是为了提供周边美食和菜谱查询功能,为“吃货”们提供便利.对典型用户和场景有清晰的描 ...

  5. [北航矩阵理论A]课程笔记

    [北航矩阵理论A]课程笔记 一.特征值 特征根相关: 设任一方阵 \(A = (a_{ij})_{n\times n} \in C^{n\times n}\) 特征多项式 \(T(\lambda)=| ...

  6. mooc linux学习总结

    通过八周的学习获得了很多知识.       首先,通过网课老师形象生动的讲述和描述一些专业词汇,使我更加深刻的记住并掌握了这些内容:动态的展示堆栈的变化,更容易理解一段汇编代码:分析操作系统的工作,记 ...

  7. ACL访问控制

    /etc/squid/squid.conf 定义语法: acl aclname  acltype   string acl  aclname  acltype   "file" s ...

  8. 量产救U盘

    同事U盘不能格式化,快速格式化失败,非快速格式化也失败.就问谁有360安全软件,试试能不能格式化. 我说我有火绒,但是不知道火绒并没有格式化U盘的功能(应该没有吧,反正我找了以后没找到) 那怎么办呢? ...

  9. Docker查看容器IP

    https://segmentfault.com/q/1010000001637726 https://blog.csdn.net/sannerlittle/article/details/77063 ...

  10. Using Android Phone to recover SD card formatted with DD command under linux

    Using Android Phone to recover SD card formatted with DD command under linux 1. Formatted a sd card ...