4997: Waiting for Change

时间限制(普通/Java):1000MS/3000MS     内存限制:65536KByte

描述

Each student in a certain high school Calculus class must pay $15 for the latest review book. The problem is that not all of the students have exact change and the teacher, of course, has no money at all. Every student has the money to pay but some do not have exact change. To keep it simple, each student has exactly one $5 bill and one $10 bill or has exactly one $20 bill. Eager to begin their review, the students line up to purchase their new review books. This line will be called line A. The teacher forms a second line as needed for students who will have to wait for the teacher to make change. The second line is line B and will start out empty.

Review books will be purchased as follows. If the teacher is able to give the correct change, s/he will sell a review book to the first student in line B, if there is one, and give back the correct change. Otherwise, if the first student in line A has exact change, the teacher will sell that student a review book. However, if the first student in line A does not have exact change, then that student will go to the back of line B. Sadly, it is possible that not every student will be able to get a review book because there might not be enough $5 bills in the room.

Your program must print out the names of the students in line B when line B is at its longest.

输入

The input consists of several test cases. The input starts with the number of test cases.

Each test case starts with the number of students followed by a list of students names and the amount that they can use to pay for the book (either 15 or 20). Fortunately, there are never two students by the same name.

There has one blank line before each test case.

输出

For each test case, your output should be a list of the names of the students waiting in line B when it is at its longest, from the front of the line to the back. If there is a tie, it should print the state of the line the first time it reached its maximum length. If no students ever get in line B, your output should print “Line B stayed empty.”

There will be at most 100 students in line A.

样例输入

3

7
Alfred 15
Beth 15
Calista 20
Desdemona 20
Ezekiel 15
Fred 20
Georgina 15

11
Hazel 20
Izzy 15
James 15
Karl 20
Lucinda 20
Malia 20
Nicholas 15
Oscar 20
Petra 20
Quantasia 20
Redd 15

8
Sasha 20
Tabitha 20
Ursula 20
Victor 15
Wanda 15
Xavier 20
Yolanda 20
Zane 15

样例输出

Line B stayed empty.
Malia Oscar Petra Quantasia
Sasha Tabitha Ursula

题目来源

Cornell University High School Programming Contest 2015

题目链接:http://tzcoder.cn/acmhome/problemdetail.do?&method=showdetail&id=4997

题目大意:一群人排队买书,他们带的钱15美元(10美元和5美元构成)和20美元,因为卖书的人美元零钱了,所以后面一位的人发现前面没有零钱会和他一起买,否则他就会因为没有零钱而不能买书了,全部人都可以买书输出“Line B stayed empty.”,否则输出不能买书的人名。

模拟题,按照题目意思模拟就可以了,判断一下这个20美元的人前面和后一个是否存在15美元的人即可

​
#include<stdio.h>
struct ren
{char name[100];int s;
};
int main()
{ren a[110];int m[100];int t,n,i,j;scanf("%d",&t);while(t--){j=0;int q=0,p=0,s=0;scanf("%d",&n);for(i=0;i<n;i++){getchar();scanf("%s %d",a[i].name,&a[i].s);}int max=0,l;for(i=0;i<n;i++){if(a[i].s==20)j++;else if(a[i].s==15)j--;if(j>max){max=j;l=i;}}if(max==0)printf("Line B stayed empty.\n");else{s=max;for(i=l;i>=0;i--){if(a[i].s==20)s--;if(!s)break;}int o=0;for(;i<n;i++){if(max==0)break;if(a[i].s==20){if(o==1)printf(" ");printf("%s",a[i].name);o=1;max--;}}printf("\n");}}return 0;
}

  

转载于:https://www.cnblogs.com/Anidlebrain/p/10055530.html

TZOJ--4997: Waiting for Change (模拟)相关推荐

  1. TZOJ 4865 统计单词数(模拟字符串)

    描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给定的 ...

  2. PAT (Advanced Level) 1014 Waiting in Line(模拟)

    题目链接:点击查看 题目大意:给出规则,要求模拟客户到银行办理手续的过程:为了方便描述,下面将分为等待区和服务区来称呼 银行共有n个窗口,每个窗口最多可以有m个人排队,这里我们称为服务区 若窗口排队人 ...

  3. Db2应用状态为uow waiting,但快照显示却在不停地Fetch

    问题: 最近遇到一个问题,Db2应用状态是UOW Waiting,但Most recent operation是Fetch,并且Rows fetched在不断增加,于是模拟了这一现象. 完整的应用快照 ...

  4. jQuery使用():Deferred有状态的回调列表(含源码)

    deferred的功能及其使用 deferred的实现原理及模拟源码 一.deferred的功能及其使用 deferred的底层是基于callbacks实现的,建议再熟悉callbacks的内部机制前 ...

  5. Spoken English Practice (I'm having whatever you're having)

    绿色:连读:                  红色:略读:               蓝色:浊化:               橙色:弱读     下划线_为浊化 口语蜕变(2017/7/4) 英 ...

  6. UERANSIM 配置和使用

    目录 1. 配置 2. 使用 2.1 基础用法-多用户接入 2.2 命令行界面的使用 2.3 数据平面的使用 2.4 TUN接口的使用 2.4.1 通过./nr-binder工具使用TUN接口 3. ...

  7. DB2查看执行过长的SQL

    朋友遇到一个DB2问题,DB2占用了大量的临时表空间,db2pd -d testdb -act发现有大量的SQL长时间运行,为了测试该问题,写了一个简单的处理问题的流程. 1.创建测试表 https: ...

  8. DB2活动日志满的原因及解决与避免方案

    下图显示了并发事务条件下,日志使用的示意 有3个并发的程序Process 1.Process 2.Process 3.每一个程序都有两个事务.蓝块代表SQL语句,红块代表commit操作,绿块代表ro ...

  9. DB2活动日志满的原因、分析、处理与规避

    日志使用 下图显示了并发事务条件下,日志使用的示意 有3个并发的程序Process 1.Process 2.Process 3.每一个程序都有两个事务.蓝块代表SQL语句,红块代表commit操作,绿 ...

最新文章

  1. 前端(jQuery)(5)-- jQuery AJAX异步访问和加载片段
  2. js中的一个方法怎么将数据主动传给另一个方法
  3. GeoRSS 应用方案
  4. XDOJ-1002-小W的塔防(dp)
  5. 杭电5256 序列变换(LIS)
  6. 实验4 C++程序的结构(4学时)
  7. springboot-aop
  8. 微信小程序云开发教程-WXML入门-数据绑定
  9. pytorch cpu版本安装_小白学pytorch 01-安装C++/Python版本pytorch
  10. bat脚本中怎么注释命令行
  11. 敏捷测试的思考和新发展
  12. Spring boot 2.0 Actuator 的健康检查
  13. 网上赚钱怎么赚?锁定一个项目,才是赚钱的王道!
  14. 软件测试精华总结,入门到精通全流程(必看,知识点很全)
  15. SQL零基础入门学习(一)
  16. 企业微信爆粉方式有哪些
  17. ios视频直播没有音频问题
  18. 在线音乐播放项目——BY音乐
  19. 数分笔记整理25 - 数据处理项目 - 中国城市资本流动问题探索
  20. unicloud操作数据库(一)——clientDb

热门文章

  1. Mutiselect下拉复选框(保存和设置默认选中项)
  2. 【代码审计】LaySNS_v2.2.0 前台XSS跨站脚本漏洞
  3. kafka常用命令整理
  4. 百度前端实战训练营第一天:HTML基础
  5. 远离单词记忆误区,考研单词就该这么背
  6. c语言eof不起作用,c语言程序设计 怎么以输入EOF结束
  7. matlab画图格式
  8. 《虚拟化与云计算技术》实训
  9. 从零开始学习Linux运维,成为IT领域翘楚(七)
  10. CactiFans v1.0中文版特性