Codeforces VK Cup 2015 Wild Card Round 1 (AB)

2024-03-20 14:18

本文主要是介绍Codeforces VK Cup 2015 Wild Card Round 1 (AB),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

比赛链接:http://codeforces.com/contest/522


A. Reposts
time limit per test:1 second
memory limit per test:256 megabytes

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 "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted 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.

Input

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 "name1 reposted 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.

Output

Print a single integer — the maximum length of a repost chain.

Sample test(s)
Input
5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya
Output
6
Input
6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp
Output
2
Input
1
SoMeStRaNgEgUe reposted PoLyCaRp
Output
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);
}



B. Photo to Remember
time limit per test:2 seconds
memory limit per test:256 megabytes

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: the i-th of them occupies the rectangle of width wi pixels and height hi pixels. On the group photo everybody stands in a line, thus the minimum pixel size of the photo including all the photographed friends, is W × 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 the j-th friend as he was the photographer.

Print the minimum size of each made photo in pixels.

Input

The first line contains integer n (2 ≤ n ≤ 200 000) — the number of friends.

Then n lines follow: the i-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.

Output

Print n space-separated numbers b1, b2, ..., bn, where bi — the total number of pixels on the minimum photo containing all friends expect for the i-th one.

Sample test(s)
Input
3
1 10
5 5
10 1
Output
75 110 60 
Input
3
2 1
1 2
2 1
Output
6 4 6 


题目大意:给n个wi和hi,去删去第i个wi和hi后剩下的wi的和与hi的最大值的积

题目分析:直接模拟出最大和次大值,如果最大值不止一个标记一下,然后就没什么东西了。。。

#include <cstdio>
#include <algorithm>
#define ll long long
using 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);elseprintf("%I64d ", (sum - w[i]) * ma2);}   elseprintf("%I64d ", (sum - w[i]) * ma1);}printf("\n");
}


这篇关于Codeforces VK Cup 2015 Wild Card Round 1 (AB)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/829731

相关文章

Codeforces 158B

很久没有刷题了,刚刚有小学弟问了这道题,AC之后贴上来吧。水~~~ #include <cstdio>#include <cmath>int main() {int n;while(scanf("%d", &n) != EOF) {int a = 0, b = 0, c = 0, d = 0;int arr[100001];for (int i = 0; i < n; ++

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee

Codeforces April Fools Day Contest 2013

2013年愚人节的坑题。。。 A. Mysterious strings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Input The input contains a sin

QT 5.8.0 msvc_2015 64bit版本编译错误:-1: error: LNK1158: 无法运行“rc.exe”

一开始安装的时候我出现了另一种错误,换着D盘E盘装了几遍之后,出现了:-1: error: LNK1158: 无法运行“rc.exe”这个错误。 首先,我的系统是Windows10 1903版 64bit QT版本是 5.8.0  msvc_2015 64版 解决方法是将 C:\Program Files (x86)\Windows Kits\8.1\bin\x86\rc.exe, C:

修复漏洞Windows 2012 Server R2(CVE-2016-2183)、(CVE-2015-2808)、(CVE-2013-2566)

修复漏洞 漏洞风险等级评定标准主机风险等级评定标准漏洞概括利用注册表修复漏洞查看修复后的漏洞 漏洞风险等级评定标准 危险程度危险值区域危险程度说明高7 <=漏洞风险值<= 10攻击者可以远程执行任意命令或者代码,或对系统进行远程拒绝服务攻击。中4 <=漏洞风险值< 7攻击者可以远程创建、修改、删除文件或数据,或对普通服务进行拒绝服务攻击。低0 <=漏洞风险值< 4攻击者可以获取

2015百度

本文是一份2015百度校园招聘研发工程师岗位面试题(深圳站),感兴趣的同学参考下。 一面: 1、C++有哪些数据类型?为什么long和int都是4字节? 2、JAVA和C++的区别是什么?分别用在什么情景比较好? 3、编程题:给定一个文件每一行是字符串,找出所有的逆序对,比如abc和cba是逆序的对。 4、编程题:给定一个数字n,比如n=3,生成1到n平方的数,如1到9,填入九宫格,使得

Apache HTTP server benchmarking tool(ab)-服务器基准测试工具一文上手

这是一个非常简单的工具,用途比较有限,只能针对单个URL进行尽可能快的压力测试。 ​ Windows下如何下载安装(Linux安装十分简单) Apache HTTP server benchmarking tool(ab)下载地址 ​ 资源 2.4版本 httpd-2.4.48-o111k-x64-vc15.zip 解压移动至C盘 管理员身份运行CMD,进入bin目录,执行

【文献及模型、制图分享】1985-2015年美国坦帕湾流域土地开发利用强度时空变化分析

公众号新功能 目前公众号新增以下等功能 1、处理GIS出图、Python制图、区位图、土地利用现状图、土地利用动态度和重心迁移图等等 2、核密度分析、网络od分析、地形分析、空间分析等等 3、地理加权回归、地理探测器、生态环境质量指数、地理加权回归模型影响因素分析、计算土地利用动态度等等 4、加权求和模型、改进TOPSIS模型、耦合协调度模型、相对发展度模型协调影响力模型、标准椭圆模型等

力扣SQL50 项目员工 I ROUND AVG

Problem: 1075. 项目员工 I 👨‍🏫 参考题解 Code select project_id,ROUND(AVG(e.experience_years),2) as average_yearsFROMproject as pLEFT JOINemployee as eONp.employee_id = e.employee_idGROUP BYp.proje

[Codeforces 451B] Sort the Array (实现)

Codeforces - 451B 给定一个序列,其中每个数都不相同 问是否能在翻转其中一段后,整个序列变得单调递增 实现题 首先设一个 B B数组为 AA数组排序后的结果 由于只能翻转一个区间,那么我假装 A是满足要求的 找到最小的 A[l]≠B[l] A[l] \ne B[l],最大的 A[r]≠B[r] A[r] \ne B[r], 翻转的区间将会是 [l,r