【Codeforces 522A】Reposts
【链接】 我是链接,点我呀:)
【题意】
有人转载官方号的动态。
又有其他人转载其他人转载的动态.
问你最长的一条转载动态的链有多长.
【题解】
用map把每个人的英文都转成小写的
然后从map中获取单词的标号
转换成图。
然后从根节点开始dfs即可
【代码】
import java.io.*;
import java.util.*;
public class Main {
static InputReader in;
static PrintWriter out;
public static void main(String[] args) throws IOException{
//InputStream ins = new FileInputStream("E:\\rush.txt");
InputStream ins = System.in;
in = new InputReader(ins);
out = new PrintWriter(System.out);
//code start from here
new Task().solve(in, out);
out.close();
}
static int N = (int)400;
static class Task{
int n,cnt,ans = 0;
ArrayList []g;
void dfs(int x,int dep) {
ans = Math.max(ans,dep);
for (int i = 0;i < (int)g[x].size();i++) {
int y = (int)g[x].get(i);
dfs(y,dep+1);
}
}
public void solve(InputReader in,PrintWriter out) {
g = new ArrayList[N+10];
HashMap<String,Integer> dic = new HashMap<String,Integer>();
for(int i = 1;i <= N;i++)g[i] = new ArrayList();
n = in.nextInt();
for (int i = 0;i < n;i++) {
StringBuilder sb1 = new StringBuilder();
StringBuilder sb2 = new StringBuilder();
String s1,s2;
s1 = in.next();s2 = in.next();s2 = in.next();
char key;
for (int j = 0;j < (int)s1.length();j++) {
if (s1.charAt(j)>='A' && s1.charAt(j)<='Z') {
key = (char)(s1.charAt(j)-'A'+'a');
sb1.append(key);
}else {
key =(char)s1.charAt(j);
sb1.append(s1.charAt(j));
}
}
s1 = sb1.toString();
for (int j = 0;j < (int)s2.length();j++) {
if (s2.charAt(j)>='A' && s2.charAt(j)<='Z') {
key = (char)(s2.charAt(j)-'A'+'a');
sb2.append(key);
}else {
key =(char)s2.charAt(j);
sb2.append(key);
}
}
s2 = sb2.toString();
if (!dic.containsKey(s1)) {
dic.put(s1, ++cnt);
}
if (!dic.containsKey(s2)) {
dic.put(s2, ++cnt);
}
int x = dic.get(s1),y = dic.get(s2);
g[y].add(x);
}
dfs(dic.get("polycarp"),1);
out.println(ans);
}
}
static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer;
public InputReader(InputStream ins) {
br = new BufferedReader(new InputStreamReader(ins));
tokenizer = null;
}
public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
}
【Codeforces 522A】Reposts的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- https://github.com/Boris-Em/BEMCheckBox
https://github.com/Boris-Em/BEMCheckBox BEMCheckBox BEMCheckBox is an open source library making it ...
- 【SWUST626】分数分解
Position: * http://acm.swust.edu.cn/problem/0626/ * List SWUST626 分数分解 List Description Input Output ...
- luogu 3383【模板】线性筛素数
我太菜了 %韩神 #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib&g ...
- 湖南集训day3
难度:☆☆☆☆☆☆☆ 此时相望不相闻,愿逐月华流照君 /* 23 233 223 啦啦啦德玛西亚 */ #include<iostream> #include<cstdio> ...
- 在JavaScript中"+"什么时候是链接符号,什么时候是加法运算?
二元加法运算符“+”在两个操作数都是数字或都是字符串时,计算结果是显而易见的.加号“+”的转换规则优先考虑字符串连接,如果其中一个操作数是字符串或者转换为字符串的对象,另外一个操作数会转换为字符串,加 ...
- jq-文本框只能输入数字
<input type="text" onKeyUp="value=value.replace(/\D/g,'')" /> onKeyUp: 当输 ...
- 使用A*寻路小记
前几天做另一个DEMO 要用实现自动寻路功能,看到普遍都是A* 学习了下 我的主循环代码: isFindEndPoint = false; //主循环 do { CreateOutSkirtsNode ...
- [ NOIP 1998 ] TG
\(\\\) \(\#A\) 车站 火车从第\(1\)站开出,上车的人数为\(a\),然后到达第\(2\)站,在第\(2\)站有人上.下车,但上.下车的人数相同,因此在第\(2\)站开出时(即在到达第 ...
- 将电脑浏览器User-Agent识别改成手机浏览器UA几种简单方法
第一种方法:修改浏览器的快捷方式 右击桌面上的Chrome浏览器图标,在弹出的右键菜单中选择“复制”,复制一个图标副本到桌面.右击该副本,选择“属性”,打开相应的对话框,在“目标”文本框的字符后面添加 ...
- 笔记《精通css》第4章 背景图像,平铺方式,背景定位,圆角框,投影,不透明
第4章 背景图像,平铺方式,背景定位,圆角框,投影,不透明 1.背景图像 background-image:url() 2.平铺方式 background-repeat:repeat-x repea ...