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 ...
随机推荐
- 外卖app的header组件开发
1.webpack框架创建 # 全局安装 vue-cli $ npm install --global vue-cli # 创建一个基于 webpack 模板的新项目 $ vue init webpa ...
- 添加MD5 密码加密
编辑 /etc/grub/grub.conf 配置文件 password = 123456 password --md5 $5$H.........SS grub-crypt --md5 ...
- Lambda表达式补充
l“Lambda 表达式”是一个匿名函数,它可以包含表达式和语句,并且可用于创建委托或表达式树类型. lLambda 表达式的运算符 =>,该运算符读为“goes to”. l=> 运算符 ...
- 为什么要学ADO.NET。。。什么是ADO.NET。。。
之前学的 •只能在查询分析器里查看数据,操作数据,我们不能让普通用户去学sql,所以我们搭建一个界面(Web Winform)让用户方便的操作数据库中的数据. •ADO.NET就是一组类库,这组类 ...
- Linux的编码及编码转换
如果你需要在Linux中操作windows下的文件,那么你可能会经常遇到文件编码转换的问题.Windows中默认的文件格式是GBK(gb2312),而Linux一般都是UTF-8.下面介绍一下,在Li ...
- 如何将外部的obj模型导入OpenGL
1.关于obj的说明. obj中存放的是顶点坐标信息(v),面的信息(f),法线(vn),纹理坐标(vt),以及材质(这个放在mtl)中 我使用CINEMA 4D导出用VS查看后的信息: CINEMA ...
- PHP中引入文件的四种方式及区别
文件加载语句:include,require,include_once,require_once include,require: require函数通常放在 PHP 程序的最前面,PHP 程序在执行 ...
- Android真机安装sqlite3的方法
欢迎和大家交流技术相关问题: 邮箱: jiangxinnju@163.com 博客园地址: http://www.cnblogs.com/jiangxinnju GitHub地址: https://g ...
- [转]OpenLiveWriter 代码插件
插件地址链接:http://pan.baidu.com/s/1jHFDtbS 密码:ax31 将文件解压,放在路径下面 重启应用后,如图
- python3之运算符
1.python算术运算符 >>> a=15 >>> b=5 >>> a+b #加 20 >>> a-b #减 10 >& ...