Music Mess
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/gym/100463/attachments
Description
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=;
#define mod 1000000007
#define eps 1e-9
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** map<string,int> m,p[];
string s[maxn][];
char t[][];
bool cmp(string x,string y)
{
return m[x]>m[y];
}
int main()
{
int t=;
int n;
while(cin>>n)
{
if(n==)
break;
m.clear();
for(int i=;i<;i++)p[i].clear();
for(int i=;i<n;i++)
{
for(int j=;j<;j++)
{
cin>>s[i][j];
m[s[i][j]]++;
}
}
for(int i=;i<n;i++)
{
sort(s[i],s[i]+,cmp);
int a=m[s[i][]];
int b=m[s[i][]];
int c=m[s[i][]];
if(a==)//当都出现一次的时候,所有东西都可以混着用
{
for(int j=;j<;j++)
{
p[j][s[i][]]=p[j][s[i][]]=p[j][s[i][]]=;
}
}
else if(b==)//当有俩只出现1次的时候,这两个很显然可以混着用,第一个必然为歌唱家
{
p[][s[i][]]=;
for(int j=;j<;j++)
p[j][s[i][]]=p[j][s[i][]]=;
}
else if(a==b)//歌唱家和专辑可以混着用
{
p[][s[i][]]=;
for(int j=;j<;j++)
p[j][s[i][]]=p[j][s[i][]]=;
}
else//各用个的
{
for(int j=;j<;j++)
p[j][s[i][j]]=;
}
}
printf("Case %d: %d %d %d\n",t++,p[].size(),p[].size(),p[].size());
}
}