1022. Poor contestant Prob

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

As everybody known, “BG meeting” is very very popular in the ACM training team of ZSU. 
After each online contest, they will go out for “smoking”. Who will be the poor ones that have to BG the others? Of course, the half who solve less problems. 
The rule runs well when the number of the contestants is even. But if the number is odd, it is impossible to divide them into two equal parts. It gives a dilemma to the BG meeting committee. After a careful discussion with Mr. Guo, a new rule emerged: if the number of the contestant is odd, the committee will first sort the contestants according to the number of problems they solved, and then they will pick out the middle one. This poor boy or girl will have no chance to attend the BG meeting. 
Strange rule, isn`t it?
As the number of the contestants is becoming more and more large, the committee need to write a program which will pick out the poor one efficiently.
Note that: Every contestant solves different number of problems. The total number of the contestants will not exceed 10^5.

Input

There are several cases in the input. The first line of the input will be an integer M, the number of the cases.
Each case is consisted of a list of commands. There are 3 types of commands.
1. Add xxx n : add a record to the data base, where xxx is the name of the contestant, which is only consisted of at most 10 letters or digits, n is the number of problems he/she solved. (Each name will appear in Add commands only once).
2.Query :
3.End :End of the case.

Output

1.For the Query command: If the current number of contestants is odd, the program should output the poor contestant’s name currently even if there is only one contestants, otherwise, just out put “No one!” (without quotes).
2.For the End command: 
   If the total number of contestants in the data base is even, you should out put “Happy BG meeting!!”(without quotes),otherwise, you should out put the “xxx is so poor. ”(without quotes) where xxx is the name of the poor one.
3.Each case should be separated by a blank line.

Sample Input

2
Add Magicpig 100
Add Radium 600
Add Kingfkong 300
Add Dynamic 700
Query
Add Axing 400
Query
Add Inkfish 1000
Add Carp 800
End Add Radium 100
Add Magicpig 200
End

Sample Output

No one!
Axing
Radium is so poor. Happy BG meeting!!

Problem Source

ZSUACM Team Member

这个题目思路并不复杂,就是建两个优先队列,一个最大堆,一个最小堆,在插入过程不断维护,使得两个堆size尽可能相同。

问题就是,做完之后会超时,百度了一下,发现是那个scanf和printf能更省时(蛋疼,我真不爱用这个)。然后还得把所有的string都变成char[]

终于给过了。。。。。。

#include <iostream>
#include <queue>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
using namespace std; struct contestant
{
string name;
int num;
};
//建立一个最大堆和最小堆(优先队列实现)
struct Greater
{
bool operator()(const contestant &a,const contestant &b)
{
return a.num < b.num;
}
}; struct Less
{
bool operator()(const contestant &a,const contestant &b)
{
return a.num > b.num;
}
}; int main()
{
int M;
scanf("%d",&M);
while(M--)
{
priority_queue<contestant,vector<contestant>,Less> MIN;
priority_queue<contestant,vector<contestant>,Greater> MAX;
//string command;
char command[20];
while(scanf("%s",command))
{
if(strcmp(command,"Add")==0)
{
char name1[20];
scanf("%s",name1);
string name(name1);
int number;
scanf("%d",&number);
const contestant tmp={name,number};
if(MAX.size()==MIN.size())
{
if(MAX.empty() || tmp.num < MIN.top().num)
MAX.push(tmp);
else if(tmp.num > MIN.top().num)
{
MAX.push(MIN.top());
MIN.pop();
MIN.push(tmp);
}
}
else if(MAX.size() > MIN.size())
{
if(tmp.num > MAX.top().num)
MIN.push(tmp);
else if(tmp.num < MAX.top().num)
{
MIN.push(MAX.top());
MAX.pop();
MAX.push(tmp);
}
}
}
else if(strcmp(command,"Query")==0)
{
if(MAX.size() == MIN.size())
printf("No one!\n");
else
{
printf("%s\n",MAX.top().name.c_str());
}
}
else if(strcmp(command,"End")==0)
{
if(MAX.size() == MIN.size())
printf("Happy BG meeting!!\n");
else printf("%s is so poor.\n",MAX.top().name.c_str());
break;
}
}
if(M != 0)
printf("\n");
}
return 0;
}

soj1022. Poor contestant Prob的更多相关文章

  1. 关于过拟合、局部最小值、以及Poor Generalization的思考

    Poor Generalization 这可能是实际中遇到的最多问题. 比如FC网络为什么效果比CNN差那么多啊,是不是陷入局部最小值啊?是不是过拟合啊?是不是欠拟合啊? 在操场跑步的时候,又从SVM ...

  2. vmware mysql报kernel: EXT4-fs (dm-0): Unaligned AIO/DIO on inode 1055943 by mysqld; performance will be poor

    kernel: EXT4-fs (dm-0): Unaligned AIO/DIO on inode 1055943 by mysqld; performance will be poor

  3. PSD 学位涵义   Poor, Smart and Deep desire to become rich 的缩写,不是真正的学位认证,是对一种心理状态的形容,所谓PSD学位是形容那些贫穷,但是很聪明,很深…_●.×

    PSD 学位涵义 Poor, Smart and Deep desire to become rich 的缩写,不是真正的学位认证,是对一种心理状态的形容,所谓PSD学位是形容那些贫穷,但是很聪明,很 ...

  4. 金句: "對比MBA學位,我們更需要PSD學位的人!" Poor, Smart and Deep Desire to… | consilient_lollapalooza on Xanga

    金句: "對比MBA學位,我們更需要PSD學位的人!" Poor, Smart and Deep Desire to… | consilient_lollapalooza on X ...

  5. 1228.Poor Pigs 可怜的猪

    转自[LeetCode] Poor Pigs 可怜的猪 There are 1000 buckets, one and only one of them contains poison, the re ...

  6. Could not autowire. No beans of 'TbItemMapper' type found. less... (Ctrl+F1) Checks autowiring prob

    Intellij Idea开发工具在@Autowired或者@Resource注入XxxMapper接口时报如下错误: Could not autowire. No beans of 'TbItemM ...

  7. PL/SQL Developer登录出现——Using a filter for all users can lead to poor performance!

    用PL/SQL  Developer登录Oracle时提示:Using a filter for all users can lead to poor performance! 分析:与Oracle的 ...

  8. Poor Warehouse Keeper

    Poor Warehouse Keeper http://acm.hdu.edu.cn/showproblem.php?pid=4803 Jenny is a warehouse keeper. He ...

  9. SOJ1022 Uniform Generator

    Computer simulations often require random numbers. One way to generate pseudo-random numbers is via ...

随机推荐

  1. CANopen 基础

    1. TPDO和RPDO都是针对从站来说的,协议上没有有讲任何一个关于主站的概念,协议就只是定义从站,没有定义主站任何东西.TPDO:从站->主站RPDO:主站->从站 2. PDO的CO ...

  2. Centos7 Zookeeper 集群安装

    1:安装java 环境 -openjdk* 2:zookeeper 安装 (官网 http://www.apache.org/dyn/closer.cgi/zookeeper/) 2.1 目录创建 自 ...

  3. 联想本win10 virtualbox 安装centos

    (1)必须开发操作系统虚拟化功能,参考该百度经验 https://jingyan.baidu.com/article/8275fc864d423e46a03cf638.html (2)调整虚拟机硬盘和 ...

  4. ACM数论之旅8---组合数(组合大法好(,,• ₃ •,,) )

    组合数并不陌生(´・ω・`) 我们都学过组合数 会求组合数吗 一般我们用杨辉三角性质 杨辉三角上的每一个数字都等于它的左上方和右上方的和(除了边界) 第n行,第m个就是,就是C(n, m) (从0开始 ...

  5. SpringBoot(十二)_springboot整合PageHelper

    我之所以会发现这个PageHelper这个东东 是因为公司在使用 ,刚开始我也没太注意这个插件,感觉不就是个分页插件吗?也就那样,直到一天,我在网上找了个代码生成器,用来构建代码,因为它是针对mysq ...

  6. Spring学习13-中IOC(工厂模式)和AOP(代理模式)的详细解释

    我们是在使用Spring框架的过程中,其实就是为了使用IOC,依赖注入,和AOP,面向切面编程,这两个是Spring的灵魂. 主要用到的设计模式有工厂模式和代理模式. IOC是工厂模式参考:设计模式- ...

  7. 数据库性能优化之SQL语句优化(下)

    (1) 选择最有效率的表名顺序(只在基于规则的优化器中有效): ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving table)将被最 ...

  8. Python学习---日期时间

    在Python里面日期时间的功能主要由几个模块提供:time,calendar,datetime,date等 time主要用到的功能函数: #!/usr/bin/python3 # coding:ut ...

  9. 虚拟主机、ECS云服务器、VPS区别汇总

    想做一个网站,但是在各种类型的服务器琳琅满目,现在总结一下市场上常见的几种服务器. 1.虚拟主机 虚拟主机就是利用虚拟化的技术,将一台服务器划分出一定大小的空间,每个空间都给予单独的 FTP 权限和 ...

  10. Ubuntu实用软件安装[转]

    Gedit编辑器配置 Ubuntu14.04从安装软件到卸载软件,删除安装包 linux wget 命令用法详解(附实例说明) ==================================== ...