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. 【转】linux之e2label命令

    转自:http://www.th7.cn/system/lin/201311/46743.shtml 前言 e2label命令,用于获取或设置ext2.ext3文件系统对应的分区的卷标. 卷标:简单来 ...

  2. php sortable 动态排序

    php sortable 动态排序未分页版.php 预览图: <?php mysql_connect("localhost","root","r ...

  3. Cocos2d-android (01) 创建一个简单的cocos2d应用程序

    下载Cocos2d-android的源代码:cocos2d-android-1 git@github.com:ZhouWeikuan/cocos2d.git 将项目导入到eclipse中.运行实例: ...

  4. 使用FTP搭建YUM

    VSFTP搭建YUM源 1.安装FTP [root@FTP kel]# rpm -qa |grep vsftp vsftpd-2.2.2-6.el6_0.1.x86_64 首先需要安装的ftp软件为v ...

  5. WebGoat学习——跨站请求伪造(Cross Site Request Forgery (CSRF))

    跨站请求伪造(Cross Site Request Forgery (CSRF)) 跨站请求伪造(Cross Site Request Forgery (CSRF))也被称为:one click at ...

  6. 实例化spring容器

    方法一:在类路径下寻找配置来实例化容器 ApplicationContext ctx = new String[]{"beans.xml"}); 方法二:在文件系统路径下寻找配置文 ...

  7. spring的annotation-driven配置事务管理器详解

    http://blog.sina.com.cn/s/blog_8f61307b0100ynfb.html ——————————————————————————————————————————————— ...

  8. MYSQL数据库性能调优之三:explain分析慢查询

    explain显示了mysql如何使用索引来处理select语句以及连接表.可以帮助选择更好的索引和写出更优化的查询语句.使用方法,在select语句前加上explain就可以了. 一.explain ...

  9. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  10. HDU 2196 Computer (树dp)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2196 给你n个点,n-1条边,然后给你每条边的权值.输出每个点能对应其他点的最远距离是多少 ...