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. IDEA小插件之快速修改Maven多模块的工程版本

    Github:https://github.com/zwjlpeng/versions 问题在Maven构建的多模块块程中,如果我们需要修改工程的版本号,会怎么操作呢example例如工程A包括了A- ...

  2. 在Delphi中通过OLE方式写Excel文件

    报表的打印是每个项目都会遇到的问题.由于报表格式要求五花八门,往往又同时要求打印格式可方便调整.作为一种替代方法,可以将需要打印的报表导出到Excel/Word,打印交给Office去吧.由于Offi ...

  3. 微信小程序入门一: 简易form、本地存储

    实例内容 登陆界面 处理登陆表单数据 处理登陆表单数据(异步) 清除本地数据 实例一: 登陆界面 在app.json中添加登陆页面pages/login/login,并设置为入口. 保存后,自动生成相 ...

  4. httpstat的简单使用

    httpstat 应该是一个 python 封装后的 curl 工具能够展现 一些客户端连接网站的时间消耗,最近在看tls 感觉挺有用处的 简单学习一下 1. centos7 安装python 和 p ...

  5. 记录下log4j的两种配置方式

    XML文件配置 <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE log4j:configura ...

  6. Java:JUnit4使用详解

    对于Junit的总是一知半解不太懂,现在认真梳理一下: 此次针对的是Junit4版本,注解也是在Junit4版本才有的,之前的版本并无注解功能.而注解开发基本上被认为是一种优秀的设计,所以我们写单元测 ...

  7. 利用userData实现客户端保存表单数据

    对于多数网页制作的朋友,实现在客户端保存在网页表单上的信息,比较多的是采用Cookie技术来实现,这些功能例如:下拉列表框选择的选项,文本框输入的数据等.事实上,我们可以利用微软DHTML默认行为中的 ...

  8. Hibernate Validation,Spring mvc 数据验证框架注解

    1.@NotNull:不能为 Null,但是可以为Empty:用在基本数据类型上. @NotNull(message="{state.notnull.valid}", groups ...

  9. zabbix短信(阿里云短信平台)与邮件报警

    环境说明 操作系统 centos7 zabbix_server zabbix 4.0.3 python 3.6.5 短信平台 阿里云短信 zabbix_server配置信息 1 [root@cp-hb ...

  10. BZOJ5324 JXOI2018守卫(区间dp)

    对于每个区间[l,r],显然右端点r是必须放置守卫的.考虑其不能监视到的点,构成一段段区间.一个非常显然但我就是想不到的性质是,对于这样的某个区间[x,y],在(y+1,r)内的点都是不能监视到这个区 ...