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=;
#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());
}
}

Codeforces Gym 100463B Music Mess Hash 逻辑题的更多相关文章

  1. Codeforces Gym 100269B Ballot Analyzing Device 模拟题

    Ballot Analyzing Device 题目连接: http://codeforces.com/gym/100269/attachments Description Election comm ...

  2. Codeforces Gym 100269A Arrangement of Contest 水题

    Problem A. Arrangement of Contest 题目连接: http://codeforces.com/gym/100269/attachments Description Lit ...

  3. codeforces Gym 100187H H. Mysterious Photos 水题

    H. Mysterious Photos Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...

  4. codeforces Gym 100500H H. ICPC Quest 水题

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  5. Codeforces Gym 100513F F. Ilya Muromets 水题

    F. Ilya Muromets Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/probl ...

  6. CF Gym 100463B Music Mess (思路)

    好题,当时想了半个小时,我往图论方面去想了,把出现过的字符串当场点,然后相互连边,那么就构成了一个三角形,一个大于三个点的连通分量里有以下结论:度为二的点可能是track,度为大于二的点一定不是tra ...

  7. Codeforces Gym 101252D&&floyd判圈算法学习笔记

    一句话题意:x0=1,xi+1=(Axi+xi%B)%C,如果x序列中存在最早的两个相同的元素,输出第二次出现的位置,若在2e7内无解则输出-1. 题解:都不到100天就AFO了才来学这floyd判圈 ...

  8. Codeforces gym 101343 J.Husam and the Broken Present 2【状压dp】

     2017 JUST Programming Contest 2.0 题目链接:Codeforces gym 101343 J.Husam and the Broken Present 2 J. Hu ...

  9. 2014百度之星资格赛 1001:Energy Conversion(水题,逻辑题)

    Energy Conversion Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

随机推荐

  1. Dyslexic Gollum

    题意: 求长度是n的二进制串中,不含长度大于等于k的回文串的个数 分析: dp[i][j][k]表示长度i,后11位状态是j不含长度大于等于k的回文串的个数(因为k最大是10,所把后11位状态压缩,d ...

  2. Drupal 7.23:函数drupal_alter()注释

    /** * Passes alterable variables to specific hook_TYPE_alter() implementations. * * This dispatch fu ...

  3. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  4. Name-based virtual servers 给予名称的虚拟服务

    nginx first decides which server should process the request. Let’s start with a simple configuration ...

  5. Metasploit启动

    一.启动Kali的PostgreSQL服务 由于使用PostgreSQL作为数据库,因此,必须先运行它. root@kali:~# service postgresql start 使用ss -ant ...

  6. 使用iphone5修剪视频的方法

    iphone5有很高的视频拍摄质量,这人很多业余爱好者也加入了视频短片的拍摄当中.在拍摄视频的过程中,为了能够捕捉到精彩瞬间,常常会提前拍摄,并延迟结束拍摄,这样就给视频增加了很多无意义的片段.这时, ...

  7. U盘安装RedHat 5.3

    转载自http://www.cnblogs.com/totozlj/archive/2012/06/03/2532757.html 1.下载rhel-5.3-server-i386-dvd.iso文件 ...

  8. 一行 Python 实现并行化 -- 日常多线程操作的新思路

    春节坐在回家的火车上百无聊赖,偶然看到 Parallelism in one line 这篇在 Hacker News 和 reddit 上都评论过百的文章,顺手译出,enjoy:-) http:// ...

  9. Home vs2013

        Microsoft Visual Studio Ultimate 2013 版本 12.0.30110.00 Update 1 Microsoft .NET Framework 版本 4.5. ...

  10. 无法debug断点跟踪JDK源代码——missing line number attributes的解决方法

    在项目工程->Properties->Java Build Path->Libraries中导入的JRE System Library库里,给jar包添加JDK源代码包后,能够直接打 ...