shunfurh 于 2017.01.05 15:31 提问

In Card Captor Sakura, Sakura is a lovely girl. One day, she opens a magic box containing many cards. Every card has a respective natural force in the real world, such as wind, water, YY, LMY, and so on. Suddenly a gust of wind blows away these cards. Sakura only has a card called “THE_WINDY” in her hand. Sakura knows if any card is not found, disaster comes. So she must collect all the cards. Cards can only be collected one by one. Suppose there are N cards to be collected. It takes Ti to collect the ith card, 1≤i≤N. For the ith card, there is a corresponding card Pi. If card Pi has been collected, it only takes time ti to collect the ith card, where ti<Ti.

Your task is to help Sakura design a schedule that takes the shortest time to collect all cards.

The input consists of several test cases. Each test case starts with a line giving the number N of cards (1≤N≤100). Each of the next N lines describes a card.

Every card has the format: Name1 Ti Name2 ti, where Name1 and Name2 are cards’ names, consisting of uppercase letters and underlines. The length of cards’ names is no more than 20 characters. Card Name1 is a card to be collected. It takes Ti to collect Card Name1 without Card Name2. And it takes ti to collect Card Name1 with Card Name2, where ti<Ti.

End of input is indicated by a line consisting of a single 0.

The input consists of several test cases. Each test case starts with a line giving the number N of cards (1≤N≤100). Each of the next N lines describes a card.

Every card has the format: Name1 Ti Name2 ti, where Name1 and Name2 are cards’ names, consisting of uppercase letters and underlines. The length of cards’ names is no more than 20 characters. Card Name1 is a card to be collected. It takes Ti to collect Card Name1 without Card Name2. And it takes ti to collect Card Name1 with Card Name2, where ti<Ti.

End of input is indicated by a line consisting of a single 0.

5
THE_FLY 67 THE_WINDY 39
THE_WATER 139 THE_FLY 69
THE_RAIN 37 THE_WATER 18
THE_WOOD 5 THE_RAIN 1
1
THE_LOOP 35 THE_LOOP 25
0

176
35

1个回答

caozhy      2017.01.12 00:47

D 1045: [HAOI2008] 糖果传递 （环状的均分纸牌）
Description 有n个小朋友坐成一圈，每人有ai个糖果。每人只能给左右两人传递糖果。每人每次传递一个糖果代价为1。 Input 小朋友个数n 下面n行 ai Output 求使所有人获得均等糖果的最小代价。 Sample Input 4 1 2 5 4 Sample Output 4 HINT 数据规模 30% n
C++贪心算法之均分纸牌

Java集合框架的一个扑克牌小程序
* Game 类 * 功能：整个游戏：开始游戏 -> 初始牌 -> 洗牌 -> 发牌 -> 排序 -> 比较大小 -> 游戏结果 * 游戏说明： * 1.创建一副扑克牌，不考虑大小王 * 2.创建两名玩家，玩家至少要有ID、姓名、手牌等属性，手牌为扑克牌的集合 * 3.洗牌，将之前创建的扑克牌顺序打乱 * 4.发牌，将洗牌之后的扑克牌集合，从第一张开始，发给两名玩家，按照一人一张的方式，每人发两张 * 5.开始游戏，比大小，大小相同比花色 * * PockerCard 类 * 功能：扑克牌的核心类 包括创建角色、创建牌、显示牌、洗牌、比较牌、排序牌等 * 属性：List cards 整幅扑克牌的集合 、 People[] peoples 角色 * 方法： public PockerCard() //无参构造函数： 创建牌的集合、创建两个角色对象 * public void initializeCard() //创建整幅扑克牌 * public void showCard() //显示单支牌的花色和点数 * public void refreshCard() //洗牌 从第一支牌开始从所有牌中随机取一只与之交换 * public void addPeopleInfo() //添加玩家的基本信息 * public void dealCard() //发牌 从开始分别给A B发牌 每人两支 * public void showPeopleCard() //显示两个角色自己获得的牌 * public void sortCard() //将每个角色自己的牌按从小到大排序 * public void comparePeopleCard() //比较角色的牌 * * SingleCard类 实现Comparable接口 * 功能：产生单支牌 * 属性：ID、color、keyID数组、keyColor数组 * 方法：public SingleCard(){} //无参构造函数 * public SingleCard(String ID,String color) //有参构造函数 * @Override public int compareTo(SingleCard o) //比较当前牌与SingleCard o的牌的大小 * * People类 * 功能：产生一个角色 * 属性：ID、Name、和、存储牌的List集合。 * 方法： public People() //初始化存储牌的List集合； *
[编程题]纸牌博弈

Java集合类相关面试题
ArrayList LinkedList Vector Set TreeSet Map HashMap HashTable面试中经常碰到的一些集合类