Codeforces Gym 100463B Music Mess Hash 逻辑题

Music Mess

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/gym/100463/attachments

Description

Francis really likes his music. He especially likes that song ’Zombie Nation’. Or was that the album? Or maybe the album was ’Kernkraft 400’. Would anybody really name an album that though? Francis doesn’t know and he can’t be expected to remember such matters. He’s a humble guy and won’t be offended if you correct him. Not all is lost though. Francis does remember the names of the artist, album, and track for some of the songs in his music collection. The only problem is he can’t seem to remember which names correspond to what. Luckily for you he does remember that there are no duplicates in the set of all artist, album, and track names. Additionally Francis’ music collection is hierarchical. At the top level he has one or more artists. Each artist then may have one or more albums. Each album then may have one or more tracks. Therefore each track appears on exactly one album and each album was authored by exactly one artist. Help him out by figuring out which names could be artists, which could be albums, and which could be songs.

Input

There are several test cases in the input file. Each test case starts with a single line containing N (1 ≤ N ≤ 10, 000), the number of tracks in Francis’ collection. The following N lines contain 3 names composed only of characters (a-z, A-Z, 0-9) indicating the artist, album, and track of a single song provided in an unknown order. Each string will contain between 1 and 20 characters. The input is terminated with a line containing 0. The input for each test case will always correspond to at least one legal music library obeying the rules above.

Output

For each case of the input print out the case number followed by three numbers separated by a space. The first indicating how many names could correspond to artists, the second to albums, and the third to tracks. Follow the format shown below.

Sample Input

2 ZombieNation Kernkraft400 Leichenschmaus Zombielicious ZombieNation Supercake53 2 Doolittle Silver Pixies Pixies Doolittle Tame 0

Sample Output

Case 1: 1 4 4 Case 2: 2 2 2

HINT

 

题意

有一堆名字,告诉你其中每一排名字有一个是作者,有一个是专辑,有一个是歌曲名,然后让你说出,有多少个名字可以当作者,多少个可以当专辑,多少个可以当歌曲

其中歌曲有一个专辑,专辑会有一个歌手

题解:

其实就是处理各种关系啦

出现一次的肯定是歌曲啦

然后剪不断,理还乱,看注释吧~

代码

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
const int maxn=102501;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//**************************************************************************************

map<string,int> m,p[3];
string s[maxn][3];
char t[3][30];
bool cmp(string x,string y)
{
    return m[x]>m[y];
}
int main()
{
    int t=1;
    int n;
    while(cin>>n)
    {
        if(n==0)
            break;
        m.clear();
        for(int i=0;i<3;i++)p[i].clear();
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<3;j++)
            {
                cin>>s[i][j];
                m[s[i][j]]++;
            }
        }
        for(int i=0;i<n;i++)
        {
            sort(s[i],s[i]+3,cmp);
            int a=m[s[i][0]];
            int b=m[s[i][1]];
            int c=m[s[i][2]];
            if(a==1)//当都出现一次的时候,所有东西都可以混着用
            {
                for(int j=0;j<3;j++)
                {
                    p[j][s[i][0]]=p[j][s[i][1]]=p[j][s[i][2]]=0;
                }
            }
            else if(b==1)//当有俩只出现1次的时候,这两个很显然可以混着用,第一个必然为歌唱家
            {
                p[0][s[i][0]]=0;
                for(int j=1;j<3;j++)
                    p[j][s[i][1]]=p[j][s[i][2]]=0;
            }
            else if(a==b)//歌唱家和专辑可以混着用
            {
                p[2][s[i][2]]=0;
                for(int j=0;j<2;j++)
                    p[j][s[i][0]]=p[j][s[i][1]]=0;
            }
            else//各用个的
            {
                for(int j=0;j<3;j++)
                    p[j][s[i][j]]=0;
            }
        }
        printf("Case %d: %d %d %d\n",t++,p[0].size(),p[1].size(),p[2].size());
    }
}

 

posted @ 2015-07-21 21:12  qscqesze  阅读(322)  评论(0编辑  收藏  举报