Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)
A. Anton and Polyhedrons
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces.
- Cube. Cube has 6 square faces.
- Octahedron. Octahedron has 8 triangular faces.
- Dodecahedron. Dodecahedron has 12 pentagonal faces.
- Icosahedron. Icosahedron has 20 triangular faces.
All five kinds of polyhedrons are shown on the picture below:
Anton has a collection of n polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number!
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of polyhedrons in Anton's collection.
Each of the following n lines of the input contains a string si — the name of the i-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (without quotes), if the i-th polyhedron in Anton's collection is a tetrahedron.
- "Cube" (without quotes), if the i-th polyhedron in Anton's collection is a cube.
- "Octahedron" (without quotes), if the i-th polyhedron in Anton's collection is an octahedron.
- "Dodecahedron" (without quotes), if the i-th polyhedron in Anton's collection is a dodecahedron.
- "Icosahedron" (without quotes), if the i-th polyhedron in Anton's collection is an icosahedron.
Output one number — the total number of faces in all the polyhedrons in Anton's collection.
4
Icosahedron
Cube
Tetrahedron
Dodecahedron
42
3
Dodecahedron
Octahedron
Octahedron
28
In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20 + 6 + 4 + 12 = 42 faces.
题目链接:http://codeforces.com/contest/785/problem/A
分析:
每种情况用数组去记,就五种情况,直接暴力求解!
下面给出AC代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
char s[];
int n;
while(scanf("%d",&n)!=EOF)
{
int ans=;
while(n--)
{
scanf("%s",s);
if(s[]=='I'&&s[]=='c'&&s[]=='o'&&s[]=='s'&&s[]=='a'&&s[]=='h'&&s[]=='e'&&s[]=='d'&&s[]=='r'&&s[]=='o'&&s[]=='n')
ans+=;
else if(s[]=='C'&&s[]=='u'&&s[]=='b'&&s[]=='e')
ans+=;
else if(s[]=='T'&&s[]=='e'&&s[]=='t'&&s[]=='r'&&s[]=='a'&&s[]=='h'&&s[]=='e'&&s[]=='d'&&s[]=='r'&&s[]=='o'&&s[]=='n')
ans+=;
else if(s[]=='D'&&s[]=='o'&&s[]=='d'&&s[]=='e'&&s[]=='c'&&s[]=='a'&&s[]=='h'&&s[]=='e'&&s[]=='d'&&s[]=='r'&&s[]=='o'&&s[]=='n')
ans+=;
else if(s[]=='O'&&s[]=='c'&&s[]=='t'&&s[]=='a'&&s[]=='h'&&s[]=='e'&&s[]=='d'&&s[]=='r'&&s[]=='o'&&s[]=='n')
ans+=;
}
printf("%d\n",ans);
}
}
4 seconds
256 megabytes
standard input
standard output
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l1, i, r1, i). Also he has m variants when he will attend programming classes, i-th variant is given by a period of time (l2, i, r2, i).
Anton needs to choose exactly one of n possible periods of time when he will attend chess classes and exactly one of m possible periods of time when he will attend programming classes. He wants to have a rest between classes, so from all the possible pairs of the periods he wants to choose the one where the distance between the periods is maximal.
The distance between periods (l1, r1) and (l2, r2) is the minimal possible distance between a point in the first period and a point in the second period, that is the minimal possible |i - j|, where l1 ≤ i ≤ r1 and l2 ≤ j ≤ r2. In particular, when the periods intersect, the distance between them is 0.
Anton wants to know how much time his rest between the classes will last in the best case. Help Anton and find this number!
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of time periods when Anton can attend chess classes.
Each of the following n lines of the input contains two integers l1, i and r1, i (1 ≤ l1, i ≤ r1, i ≤ 109) — the i-th variant of a period of time when Anton can attend chess classes.
The following line of the input contains a single integer m (1 ≤ m ≤ 200 000) — the number of time periods when Anton can attend programming classes.
Each of the following m lines of the input contains two integers l2, i and r2, i (1 ≤ l2, i ≤ r2, i ≤ 109) — the i-th variant of a period of time when Anton can attend programming classes.
Output one integer — the maximal possible distance between time periods.
3
1 5
2 6
2 3
2
2 4
6 8
3
3
1 5
2 6
3 7
2
2 4
1 4
0
In the first sample Anton can attend chess classes in the period (2, 3) and attend programming classes in the period (6, 8). It's not hard to see that in this case the distance between the periods will be equal to 3.
In the second sample if he chooses any pair of periods, they will intersect. So the answer is 0.
题目链接:http://codeforces.com/contest/785/problem/B
分析:
好恶心的题目,开始用结构体做,WA了三次,查了下数据,发现有点问题,改了以后TL了,mmp,4s暴力会超时!!!那就贪心吧,贪了半天,还是乱七八糟,看了下别人的,然后自己敲了一遍,WA了!!!干脆直接贴别人的吧,1887ms,时间有点长,想想我还是用结构体写吧,187ms AC,时间缩短了十倍!有点晕,先放放!
下面给出我写的187ms AC的代码:
#include <bits/stdc++.h>
using namespace std;
const int maxn=;
struct node
{
int start,end;
}p[maxn];
struct Node
{
int start,end;
}t[maxn];
bool cmp1(node x,node y)
{
if(x.start<y.start&&x.end<y.end)
return true;
if(x.start==y.start&&x.end<y.end)
return true;
return false;
}
bool cmp2(Node x,Node y)
{
if(x.start<y.start&&x.end<y.end)
return true;
if(x.start==y.start&&x.end<y.end)
return true;
return false;
}
int main()
{
int n,m;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=n;i++)
scanf("%d%d",&p[i].start,&p[i].end);
scanf("%d",&m);
for(int i=;i<=m;i++)
scanf("%d%d",&t[i].start,&t[i].end);
sort(p+,p++n,cmp1);
sort(t+,t++m,cmp2);
int mm=,mp,nm=,np;
for(int i=;i<=n;i++)
{
np=max(np,p[i].start);
nm=min(nm,p[i].end);
}
for(int i=;i<=m;i++)
{
mp=max(mp,t[i].start);
mm=min(mm,t[i].end);
}
int q=max(,max(mp-nm,np-mm));
printf("%d\n",q);
}
return ;
}
Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)的更多相关文章
- Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)
题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...
- Codeforces Round #404 (Div. 2) C 二分查找
Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18) 找到 1) [n<= m] cout<<n; 2) ...
- Codeforces Round #404 (Div. 2) DE
昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...
- Codeforces Round #404 (Div. 2) A,B,C,D,E 暴力,暴力,二分,范德蒙恒等式,树状数组+分块
题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory ...
- Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #404 (Div. 2) B. Anton and Classes 水题
B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...
- Codeforces Round #365 (Div. 2) A 水
A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力
B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...
随机推荐
- 【python】函数filter、map
- [数据结构]C语言二叉树的实现
树和图是数据结构中比较麻烦的东西,里面涉及的概念比较多,也最有用, 就比如一般树广泛应用于人工智能的博弈上,而基于图的广度优先和深度优先搜索也广泛应用于人工智能寻路上面 首先我们要把树进行分类: &g ...
- Spark源码剖析(一):如何将spark源码导入到IDEA中
由于近期准备深入研究一下Spark的核心源码,所以开了这一系列用来记录自己研究spark源码的过程! 想要读源码,那么第一步肯定导入spark源码啦(笔者使用的是IntelliJ IDEA),在网上找 ...
- Java8函数之旅 (八) - 组合式异步编程
前言 随着多核处理器的出现,如何轻松高效的进行异步编程变得愈发重要,我们看看在java8之前,使用java语言完成异步编程有哪些方案. JAVA8之前的异步编程 继承Thead类,重写run方法 实现 ...
- lodash源码分析之Hash缓存
在那小小的梦的暖阁,我为你收藏起整个季节的烟雨. --洛夫<灵河> 本文为读 lodash 源码的第四篇,后续文章会更新到这个仓库中,欢迎 star:pocket-lodash gitbo ...
- java 类的继承和接口的继承
父类 public class person { String name; int age; void eat(){ System.out.println("吃饭"); } voi ...
- 第一个Vue插件从封装到发布
前言 这是我封装的第一个Vue插件,实现的功能是滑动选择省市区,虽然只是一个简单的插件,但还是挺开心的,记录一下步骤. 插件地址:https://github.com/leichangchun/vue ...
- Web框架django[Form]组件
新手上路 Django的Form主要具有一下几大功能: 生成HTML标签 验证用户数据(显示错误信息) HTML Form提交保留上次提交数据 初始化页面显示内容 小试牛刀 1.创建Form类 # 创 ...
- [Spark内核] 第32课:Spark Worker原理和源码剖析解密:Worker工作流程图、Worker启动Driver源码解密、Worker启动Executor源码解密等
本課主題 Spark Worker 原理 Worker 启动 Driver 源码鉴赏 Worker 启动 Executor 源码鉴赏 Worker 与 Master 的交互关系 [引言部份:你希望读者 ...
- python matplotlib 绘图基础
在利用Python做数据分析时,探索数据以及结果展现上图表的应用是不可或缺的. 在Python中通常情况下都是用matplotlib模块进行图表制作. 先理下,matplotlib的结构原理: mat ...