查看: 2385| 回复: 10
跳转到指定楼层
上一主题 下一主题
收起左侧

[CareerCup] [第二轮] 3/11-3/17 CareerCup 3.7

全局:

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看附件。没有帐号?注册账号

x
An animal shelter holds only dogs and cats, and operates ona strictly “first in, first out” basis. People must adopt either the “oldest”(based on arrival time) of all animals at the shelter, or they can selectwhether they could prefer a dog or a cat (and will receive the oldest animal ofthat type). They cannot select which specific animal they would like. Createthe data structures to maintain this system and implement operations such asenqueue, dequeueAny, dequeueDog and dequeueCat. You may use the built-inLinkedList data structure.

发帖规范:
http://www.1point3acres.com/bbs/thread-48094-1-1.html


上一篇:【七类排序】之第六种:归并排序
下一篇:[第二轮] 3/11-3/17 CareerCup 4.1
🔗
zuohr 2013-3-10 19:16:22 | 只看该作者
全局:
We will use an uni-directional linked list as the underlying data structure, find and dequeue the first node that matches the target type (dog or cat) while iteratiing the list. dequeue methods retruns null if no element could be dequeued.
enqueue : O(1)
dequeueAny : O(1)
dequeueDog : O(N)
dequeueCat : O(N)

https://gist.github.com/Zuohr/5128157
回复

使用道具 举报

🔗
ThunderXu 2013-3-10 19:18:06 | 只看该作者
全局:
https://gist.github.com/ThunderXu/5128203
use a list<Animal> in C++
回复

使用道具 举报

🔗
moophis 2013-3-10 20:33:16 | 只看该作者
回复

使用道具 举报

🔗
EchoMemory 2013-3-11 16:22:08 | 只看该作者
全局:
One Data structure consisted of two queues built by LinkedList within time_tag. one is for the cat, the other is for the dog.
enqueue : O(1)
dequeueAny : O(1)
dequeueDog : O(1)
dequeueCat : O(1)
回复

使用道具 举报

全局:
题目不是很难。。。但是用到了oo的思想,J2SE不熟的情况去学j2ee真是纯傻逼的行为,白白浪费了一周时间。。。。。
* 包里别的文件是自己写的队列的实现。。。

https://github.com/1094401996/Ca ... /AnimalShelter.java
回复

使用道具 举报

🔗
宋小宝Dani 2013-3-19 13:24:23 | 只看该作者
全局:
moophis 发表于 2013-3-10 20:33
Same as ls...
https://github.com/moophis/careercup/blob/master/3.7.cpp

I've got a problem: when there is no dog in the shelter, and I call dequeueDog(), VS2010 shows "Debug Assertion Failed". Expression: list iterator not dereferencable.

I've copied yours to test, same problem occured. How to solve?
回复

使用道具 举报

🔗
moophis 2013-3-19 14:44:42 | 只看该作者
全局:
宋小宝Dani 发表于 2013-3-19 13:24
I've got a problem: when there is no dog in the shelter, and I call dequeueDog(), VS2010 shows "De ...

I put a special enumeration invariable called "None". If there is no such kind of animal to pop, you will get a "None", which prints 2 on your console. I use g++ to compile my code and it should be fine, I do not know what is like on your VS2010 environment. Sorry.
回复

使用道具 举报

🔗
Fanyare 2013-3-20 01:44:29 | 只看该作者
回复

使用道具 举报

🔗
flabby 2013-5-15 17:11:24 | 只看该作者
全局:
类似EchoMemory
用了两个队列 dog cat 每个节点增加序号
复杂度都是O(1)
https://github.com/flabby/CareerCup/blob/master/3.7.cpp
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表