Codeforces VK Cup 2015 Wild Card Round 1 (AB)
来源:互联网 发布:跳跃表 java 编辑:程序博客网 时间:2024/04/28 10:05
比赛链接:http://codeforces.com/contest/522
One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.
These events are given as a sequence of strings "name1reposted name2", wherename1 is the name of the person who reposted the joke, andname2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.
Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer n (1 ≤ n ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.
We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
Print a single integer — the maximum length of a repost chain.
5tourist reposted PolycarpPetr reposted TouristWJMZBMR reposted Petrsdya reposted wjmzbmrvepifanov reposted sdya
6
6Mike reposted PolycarpMax reposted PolycarpEveryOne reposted Polycarp111 reposted PolycarpVkCup reposted PolycarpCodeforces reposted Polycarp
2
1SoMeStRaNgEgUe reposted PoLyCaRp
2
题目大意:求最长链的节点数
题目分析:用map 字符串hash一下,然后跑下floyd,代码写的丑
#include <cstdio>#include <map>#include <string>#include <algorithm>#include <iostream>using namespace std;map <string, int> mp;map <string, int> :: iterator it;int const MAX = 505;int g[MAX][MAX], cnt;int Floyd(){ int ans = 1; for(int k = 0; k < cnt; k++) { for(int i = 0; i < cnt; i++) { for(int j = 0; j < cnt; j++) { if(g[i][k] && g[k][j]) { g[i][j] = g[i][k] + g[k][j]; ans = max(ans, g[i][j]); } } } } return ans;}void trans(string a){ int i = 0; while(a[i]) { if(a[i] >= 'A' && a[i] <= 'Z') a[i] += 'a' - 'A'; i++; }}int main(){ int n; cnt = 0; scanf("%d", &n); while(n--) { string a, tmp, b; cin >> a >> tmp >> b; int i = 0; while(a[i]) { if(a[i] >= 'A' && a[i] <= 'Z') a[i] += 'a' - 'A'; i++; } i = 0; while(b[i]) { if(b[i] >= 'A' && b[i] <= 'Z') b[i] += 'a' - 'A'; i++; } mp[a] = cnt++; it = mp.find(a); if(it == mp.end()) mp[a] = cnt++; it = mp.find(b); if(it == mp.end()) mp[b] = cnt++; g[mp[a]][mp[b]] = 1; } int ans = Floyd(); printf("%d\n", ans + 1);}
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: thei-th of them occupies the rectangle of widthwi pixels and heighthi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, isW × H, where W is the total sum of all widths and H is the maximum height of all the photographed friends.
As is usually the case, the friends made n photos — the j-th (1 ≤ j ≤ n) photo had everybody except for thej-th friend as he was the photographer.
Print the minimum size of each made photo in pixels.
The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.
Then n lines follow: thei-th line contains information about the i-th friend. The line contains a pair of integers wi, hi (1 ≤ wi ≤ 10, 1 ≤ hi ≤ 1000) — the width and height in pixels of the corresponding rectangle.
Print n space-separated numbersb1, b2, ..., bn, wherebi — the total number of pixels on the minimum photo containing all friends expect for thei-th one.
31 105 510 1
75 110 60
32 11 22 1
6 4 6
题目大意:给n个wi和hi,去删去第i个wi和hi后剩下的wi的和与hi的最大值的积
题目分析:直接模拟出最大和次大值,如果最大值不止一个标记一下,然后就没什么东西了。。。
#include <cstdio>#include <algorithm>#define ll long longusing namespace std;int const MAX = 2 * 1e6 + 5;ll w[MAX], h[MAX];int main(){ int n; ll sum = 0, ma1 = 0, ma2 = 0, pos = 0; bool flag = false; scanf("%d", &n); for(int i = 0; i < n; i++) { scanf("%I64d %I64d", &w[i], &h[i]); sum += w[i]; if(ma1 < h[i]) { ma1 = h[i]; pos = i; } } for(int i = 0; i < n; i++) { if(i == pos) continue; if(h[i] == ma1) { flag = true; continue; } ma2 = max(ma2, h[i]); } for(int i = 0; i < n; i++) { if(h[i] == ma1) { if(flag) printf("%I64d ", (sum - w[i]) * ma1); else printf("%I64d ", (sum - w[i]) * ma2); } else printf("%I64d ", (sum - w[i]) * ma1); } printf("\n");}
- Codeforces VK Cup 2015 Wild Card Round 1 (AB)
- Codeforces VK Cup 2015 - Round 1 (Div.1 A~E)
- 【codeforces VK Cup Round 1】BDE题解
- Codeforces VK Cup 2015
- [VK Cup 2015 - Round 1]简要题解
- 【树形DP】 codeforces VK Cup 2012 Round 1 D
- Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)
- VK Cup 2012 Round 1
- VK Cup 2015 - Qualification Round 1 B. Photo to Remember
- Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) 题解(待续)
- Codeforces VK Cup 2012 Qualification Round 1 / 158A Next Round(模拟)
- Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition)
- Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition)
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)
- 【解题报告】Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)
- VK Cup 2012 Qualification Round 1 E
- 数据库MySQL、Oracle、SQLServer、db2分页查询语句
- centos6.2更新yum源
- laravel5 安装 genarators
- 联想M490预装的win8系统如何降为win7
- Android锁屏广播只能在代码中注册,无法再AndroidManifest整注册
- Codeforces VK Cup 2015 Wild Card Round 1 (AB)
- iOS帐号证书之漫谈(二)—— 申请邓白氏码
- BIRT 中的indexOf函数
- hdu Quoit Design(最近相邻点对)
- CentOS7下安装Redis3.0及安装时遇到的问题
- ZOJ 3204 Connect them(最小生成树之Krusal 输出字典序最小的)
- echo命令控制gpio
- 汇编中的算术运算类指令
- mfc简介