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 ...
随机推荐
- iOS动态性:动态添加属性的方法——关联(e.g. 向Category添加属性)
想到要如何为所有的对象增加实例变量吗?我们知道,使用Category可以很方便地为现有的类增加方法,但却无法直接增加实例变量.不过从Mac OS X v10.6开始,系统提供了Associative ...
- SQL Server 数据库引擎怎样记录完整备份后修改过的数据
SQL Server 使用两个内部数据结构跟踪被大容量复制操作修改的区,以及自上次完整备份后修改的区.这些数据结构极大地加快了差异备份的速度.当数据库使用大容量日志恢复模式时,这些数据结构也可以加快将 ...
- 【算法】论平衡二叉树(AVL)的正确种植方法
参考资料 <算法(java)> — — Robert Sedgewick, Kevin Wayne <数据结构> ...
- 掌握numpy(二)
目录 掌握numpy(一) 掌握numpy(二) 掌握numpy(三) 掌握numpy(四) 数组的reshape 顾名思义,就是对数组的形状进行改变,比如行变成列,一行变多行等. in place ...
- Oracle学习笔记_09_字符串相关函数
二.参考资料 0.Oracle中的字符串类型及相关函数详解 1.ORACLE 字符串操作 2.oracle函数大全-字符串处理函数
- Python 为何能坐稳 AI 时代头牌语言
原文链接:https://mp.weixin.qq.com/s?__biz=MzI0ODcxODk5OA==&mid=2247487055&idx=2&sn=ca0fe8740 ...
- springBoot系列教程04:mybatis及druid数据源的集成及查询缓存的使用
首先说下查询缓存:查询缓存就是相同的数据库查询请求在设定的时间间隔内仅查询一次数据库并保存到redis中,后续的请求只要在时间间隔内都直接从redis中获取,不再查询数据库,提高查询效率,降低服务器负 ...
- 一个好用的PHOTOSHOP切图插件(CutterMan插件下载)
请关注CutterMan官方微博,分享本站点到自己微博中@Cutterman,私信TA,就有啦~~ 下载地址:http://www.cutterman.cn/ 也许你兴冲冲的下载了,然后发现安装不上, ...
- 鸟哥的linux私房菜学习-(三)X Window与文本模式的切换
通常我们也称文本模式为终端机接口, terminal 或 console喔!Linux默认的情况下会提供六个Terminal来让使用者登陆, 切换的方式为使用:[Ctrl] + [Alt] + [F1 ...
- 房上的猫:StringBuffer类
一.使用StringBuffer类 StringBuffer类位于java.lang包中,是String类的增强类 步骤: 1.声明StringBuffer对象并初始化 StringBuffer s ...