CF Gym 100463B Music Mess (思路)
好题,当时想了半个小时,我往图论方面去想了,把出现过的字符串当场点,然后相互连边,那么就构成了一个三角形,一个大于三个点的连通分量里有以下结论:度为二的点可能是track,度为大于二的点一定不是track,当一个点连接一个可能是track的点和一个可能是artist的点,那么这个点就可能是ablum。然后我就卡在这里了,怎么求连通分量,怎么判断一个点一定是artist。还有形成的树的深度不能超过三,等等问题。
其实这样想不对,借助之前做A Lot of Joy 的思想,改下一思路,判断连通改成统计以下它在出现的次数。然后一个三元组一个三元组的考虑。考虑他们出现的次数,
有个结论:出现次数:artist>=album>=track
如果三个相等,那么就他们三个是可以相互替换的。如果两个出现次数多的结点次数相等,那么次数少的那个一定是作为track,剩下两个既可以当成track也可以当成artist;如果出现次数少的两个结点次数相等,那个次数多那个一定是artist,剩下两个既可以当成album也可以当成track。
#include<cstdio>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
//#include<iostream>
#include<string>
#include<cstring> using namespace std; //#define local
const int maxn = ; map<string,int> mp;
int vcnt;
int ID(const string & x)
{
if(mp.count(x) == ){
mp.insert(make_pair(x,vcnt));
return vcnt++;
}
else return mp[x];
} int cnt[maxn*];
int smp[maxn][];
int vec[][maxn*],sz[]; void init(){
vcnt = ;
memset(cnt,,sizeof(cnt));
ans[].clear();
ans[].clear();
ans[].clear();
} bool cmp(int a,int b) { return cnt[a]<cnt[b]; } int main()
{
#ifdef local
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // local
char buf[];
int N;
int cas = ;
while(~scanf("%d",&N)&&N){
init();
for(int i = ; i < N; i++){
for(int j = ; j < ; j++){
scanf("%s",buf);
smp[i][j] = ID(buf);
cnt[smp[i][j]]++;
}
}
mp.clear();
for(int i = ; i < N; i++){
sort(smp[i],smp[i]+,cmp);
int tmp[] = { cnt[smp[i][]],cnt[smp[i][]],cnt[smp[i][]] };
if(tmp[] == tmp[]){
for(int k = ; k < ; k++)
for(int j = ; j < ;j++ ) {
ans[k].insert(smp[i][j]);
}
}else {
if(tmp[] == tmp[]){
ans[].insert(smp[i][]);
ans[].insert(smp[i][]); ans[].insert(smp[i][]);
ans[].insert(smp[i][]); ans[].insert(smp[i][]);
} else if(tmp[] == tmp[]) {
ans[].insert(smp[i][]);
ans[].insert(smp[i][]); ans[].insert(smp[i][]);
ans[].insert(smp[i][]); ans[].insert(smp[i][]);
} else {
ans[].insert(smp[i][]);
ans[].insert(smp[i][]);
ans[].insert(smp[i][]);
}
}
} printf("Case %d: %d %d %d\n",++cas,ans[].size(),ans[].size(),ans[].size());
}
return ;
}
CF Gym 100463B Music Mess (思路)的更多相关文章
- Codeforces Gym 100463B Music Mess Hash 逻辑题
Music Mess Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments ...
- CF Gym 102028G Shortest Paths on Random Forests
CF Gym 102028G Shortest Paths on Random Forests 抄题解×1 蒯板子真jir舒服. 构造生成函数,\(F(n)\)表示\(n\)个点的森林数量(本题都用E ...
- CF Gym 100187A Potion of Immortality (思路,最坏情况的最小损失)
根据兔子试药情况可以缩小范围,如果死了,不在试过的药里面,如果活着,在试过的药里. 最糟的情况: 两个原则 1.能确定魔药所在的范围的尽量大,2.死得兔子尽量多. 如果当前不知道情况的药n为k的二倍以 ...
- codeforces gym 100971 K Palindromization 思路
题目链接:http://codeforces.com/gym/100971/problem/K K. Palindromization time limit per test 2.0 s memory ...
- CF gym 101933 K King's Colors —— 二项式反演
题目:http://codeforces.com/gym/101933/problem/K 其实每个点的颜色只要和父亲不一样即可: 所以至多 i 种颜色就是 \( i * (i-1)^{n-1} \) ...
- CF gym 100962D Deep Purple [后缀树,树链剖分,线段树]
Codeforces 思路 感觉这个离线的思路好神仙啊qwq 对于每个询问\([l,r]\)其实就是要求\(p_{max}\),使得\(lcs(s[1,p],s[1,r])>p-l\),也就是\ ...
- CF gym 101933 K. King's Colors(二项式反演)
传送门 解题思路 首先给出的树形态没用,因为除根结点外每个点只有一个父亲,它只需要保证和父亲颜色不同即可.设\(f(k)\)表示至多染了\(k\)种颜色的方案,那么\(f(k)=(k-1)^{(n-1 ...
- cf Gym 101086M ACPC Headquarters : AASTMT (Stairway to Heaven)
题目: Description standard input/output As most of you know, the Arab Academy for Science and Technolo ...
- CF Gym 100685A Ariel
传送门 A. Ariel time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
随机推荐
- MapReduce编程模型
# 文本前期处理 strl_ist = str.replace('\n', '').lower().split(' ') count_dict = {} # 如果字典里有该单词则加 1,否则添加入字典 ...
- Unity中的Lod
http://blog.csdn.net/bigpaolee/article/details/48521371 LOD是( Level of Detail)的缩写,表示细节级别. 这里注意下,Lodg ...
- scikit-learn使用fetch_mldata无法下载MNIST数据集的问题
scikit-learn使用fetch_mldata无法下载MNIST数据集的问题 0. 写在前面 参考书 <Python数据科学手册> 工具 python3.5.1,Jupyter La ...
- Eclipse中各图标含义
Eclipse中定义很多小图标,在平时的开发工作中,熟悉这些小图标还是很有意义的.那具体意义大家又知道多少呢? 首先,通过在搜索“eclipse icon meaning”,找到了一个比较有用的链接, ...
- LeetCode:灯泡开关2
题目 现有一个房间,墙上挂有 n 只已经打开的灯泡和 4 个按钮.在进行了 m 次未知操作后,你需要返回这 n 只灯泡可能有多少种不同的状态. 假设这 n 只灯泡被编号为 [1, 2, 3 ..., ...
- Python模块介绍
模块 1.模块定义 用来从逻辑上组织python代码(变量,函数,类,逻辑:实现一个功能),本质上就是.py结尾python文件 分类:内置模块(又称标准库)执行 help('modules')查看所 ...
- Python多继承C3算法
Python3 多继承的MRO算法选择.MRO(Method Resolution Order):方法解析顺序. Python3 只保留了C3算法! C3算法解析: 1.C3算法解析 C3算法:MRO ...
- 牛客假日团队赛2 G.CountyFairEvents
链接: https://ac.nowcoder.com/acm/contest/924/G 题意: Farmer John has returned to the County Fair so he ...
- Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) B
Arpa is taking a geometry exam. Here is the last problem of the exam. You are given three points a, ...
- python的入门1(补发)
一.python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆(中文名字:龟叔)为了在阿姆斯特丹打发时间,决心开发一个新的脚本解 ...