acdream 1146 Moist

原创 2015年07月07日 13:42:04

Problem Description

Moist has a hobby -- collecting figure skating trading cards. His card collection has been growing, and it is now too large to keep in one disorganized pile. Moist needs to sort the cards in alphabetical order, so that he can find the cards that he wants on short notice whenever it is necessary.

The problem is -- Moist can't actually pick up the cards because they keep sliding out his hands, and the sweat causes permanent damage. Some of the cards are rather expensive, mind you. To facilitate the sorting, Moist has convinced Dr. Horrible to build him a sorting robot. However, in his rather horrible style, Dr. Horrible has decided to make the sorting robot charge Moist a fee of $1 whenever it has to move a trading card during the sorting process.

Moist has figured out that the robot's sorting mechanism is very primitive. It scans the deck of cards from top to bottom. Whenever it finds a card that is lexicographically smaller than the previous card, it moves that card to its correct place in the stack above. This operation costs $1, and the robot resumes scanning down towards the bottom of the deck, moving cards one by one until the entire deck is sorted in lexicographical order from top to bottom.

As wet luck would have it, Moist is almost broke, but keeping his trading cards in order is the only remaining joy in his miserable life. He needs to know how much it would cost him to use the robot to sort his deck of cards.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 100).

T test cases follow.

Each one starts with a line containing a single integer, N(1 ≤ N ≤ 100).

The next N lines each contain the name of a figure skater, in order from the top of the deck to the bottom.

Each name will consist of only letters and the space character.
Each name will contain at most 100 characters.
No name with start or end with a space.
No name will appear more than once in the same test case.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of dollars it would cost Moist to use the robot to sort his deck of trading cards.

Sample Input

3
2
Oksana Baiul
Michelle Kwan
3
Elvis Stojko
Evgeni Plushenko
Kristi Yamaguchi
4
Evgeni Plushenko
Kristi Yamaguchi
Elvis Stojko
Aksana Baiul

Sample Output

Case #1: 1
Case #2: 0
Case #3: 2

类似插入排序,统计插入的次数。

/*
* this code is made by yuexunjiang
* Problem: 1146
* Verdict: Accepted
* Submission Date: 2015-07-07 13:37:24
* Time: 4MS
* Memory: 1692KB
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int MAXN = 100 + 5;
 
char ch[MAXN][MAXN];
vector<char*> v;
 
int main(){
#if 0
    freopen("A.in","rt",stdin);
#endif
    int t,n,num = 1;
    cin >>t;
    while(t--){
        cin >>n;
        getchar();
        v.clear();
        for(int i = 0;i < n;i++){
            fgets(ch[i],MAXN,stdin);
            v.push_back(ch[i]);
        }
        int cnt = 0;
        for(vector<char *>::iterator it=v.begin()+1; it!=v.end(); ++it){
            if(strcmp(*it, *(it-1)) < 0){
                v.erase(it);
                --it;
                cnt++;
            }
        }
        cout <<"Case #" <<num++ <<": "<<cnt <<endl;
    }
    return 0;
}




版权声明:本文为博主原创文章,未经博主允许不得转载。

[BZOJ1146]CTSC2008网络管理|树上带修改K大

树上带修改K大,太可怕。。写了树链剖分+线段树套平衡树+二分和dfs序+主席树两种,每种都是写+调试花了将近5个小时!!我实在是太弱了。。 1.   树链剖分+线段树套平衡树+二分 最显然的做法了...
  • Tag_king
  • Tag_king
  • 2015年05月04日 20:43
  • 511

【BZOJ1146】网络管理,整体二分

.
  • xym_CSDN
  • xym_CSDN
  • 2017年06月03日 21:42
  • 303

【BZOJ2809】【codevs1763】派遣,主席树记录前缀和

你的笑容就像蝴蝶拍翅,如果可以,我想永远收藏。
  • xym_CSDN
  • xym_CSDN
  • 2016年05月06日 07:35
  • 269

玲珑杯 1146(dp)

今天HH在操场上跑步,HH作为一个爱运动的人,肯定会想方设法把跑步所消耗的能量减到最少.现在这个操场上有n个可以休息的点,他们的坐标分别是x1,x2…xn(xi≤xi+1),HH刚开始在x1 ,并且他...
  • feizaoSYUACM
  • feizaoSYUACM
  • 2017年07月17日 14:11
  • 138

1146: 吃糖果

1146: 吃糖果 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 2154  Solved: 997 SubmitStatusWeb B...
  • sd_DENG
  • sd_DENG
  • 2017年06月27日 14:03
  • 186

1146: 吃糖果

Description HOHO,终于从Speakless手上赢走了所有的糖果,是Gardon吃糖果时有个特殊的癖好,就是不喜欢连续两次吃一样的糖果,喜欢先吃一颗A种类的糖果,下一次换一种口味,...
  • lvhaoye
  • lvhaoye
  • 2017年07月27日 18:13
  • 70

ACDREAM 03E ACdream王国的士兵(贪心专场)

ACDREAM 03E ACdream王国的士兵Problem Description 所谓弱国无外交,ACdream王国想守住这一片土地,自然离不开王国的士兵们,你作为王国的骠骑大将军,自然有训练...
  • llx523113241
  • llx523113241
  • 2015年05月10日 20:21
  • 588

ACDREAM 03G ACdream的高速公路(贪心专场)

ACDREAM 03G ACdream的高速公路Problem DescriptionACdream王国有一条贯穿整个王国的高速公路,一天,你要驾驶着一辆油箱容量为P的车从高速公路的一头驶向另一头,总...
  • llx523113241
  • llx523113241
  • 2015年05月11日 19:04
  • 1055

ACdream的高速公路

ACdream的高速公路 Time Limit: 2000/1000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others)   ...
  • Techay
  • Techay
  • 2015年06月07日 09:52
  • 414

ACDREAM 03D ACdream王国的花店(贪心专场)

ACDREAM 03D ACdream王国的花店Problem DescriptionACdream王国的花店只有一家,所以大家想买花来装饰,店主为了防止有人恶意囤积鲜花来抬高物价(就是黄牛党啦~),...
  • llx523113241
  • llx523113241
  • 2015年05月10日 20:14
  • 325
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:acdream 1146 Moist
举报原因:
原因补充:

(最多只允许输入30个字)