A. Anton and Polyhedrons

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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!

Input

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

Output one number — the total number of faces in all the polyhedrons in Anton's collection.

Examples
Input
4 
Icosahedron
Cube
Tetrahedron
Dodecahedron
Output
42
Input
3 
Dodecahedron
Octahedron
Octahedron
Output
28
Note

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);
}
}
B. Anton and Classes
time limit per test

4 seconds

memory limit per test

256 megabytes

input

standard input

output

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!

Input

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

Output one integer — the maximal possible distance between time periods.

Examples
Input
3 
1 5
2 6
2 3
2
2 4
6 8
Output
3
Input
3 
1 5
2 6
3 7
2
2 4
1 4
Output
0
Note

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,排序,贪心)的更多相关文章

  1. Codeforces Round #479 (Div. 3) C. Less or Equal (排序,贪心)

    题意:有一个长度为\(n\)的序列,要求在\([1,10^9]\)中找一个\(x\),使得序列中恰好\(k\)个数满足\(\le x\).如果找不到\(x\),输出\(-1\). 题解:先对这个序列排 ...

  2. 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) ...

  3. Codeforces Round #404 (Div. 2) DE

    昨晚玩游戏竟然不小心错过了CF..我是有多浪啊. 今天总算趁着下课时间补了,感觉最后两题还是挺有意思的,写个题解. D: 题目大意: 给出一个括号序列,问有多少个子序列 是k个'(' + k个')' ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题

    A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...

  8. 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 ...

  9. Codeforces Round #307 (Div. 2) B. ZgukistringZ 暴力

    B. ZgukistringZ Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/551/probl ...

随机推荐

  1. xCode8以及iOS10 的新特性

    其他:ios10中 适配问题(1.系统判断方法失效:2.隐私数据的访问问题:3.UIColor 问题4.真彩色的显示5.ATS问题6.UIStatusBar问题7.UITextField8.UserN ...

  2. NOIP2017day1游记

    NOIP 2017总结 Day1 Day1T1 第一眼看到瞬间慌掉,woc这玩意啥! 然后懵逼了两分钟 好的 我相信他是NOIP第一题 那我就打个表吧 然后花五分钟打了个暴力 玩了几组数据 哇!好像有 ...

  3. Linux 学习记录 一(安装、基本文件操作).

         Linux distributions主要分为两大系统,一种是RPM方式安装软件的系统,包括Red Hat,Fedora,SuSE等都是这类:一种则是使用Debian的dpkg方式安装软件的 ...

  4. touchstart和touchend事件

    touchstart和touchend事件 移动互联网是未来的发展趋势,现在国内很多互联网大佬都在争取移动这一块大饼,如微信及支付宝是目前比较成功的例子,当然还有各种APP和web运用. 由于公司的需 ...

  5. RabbitMQ教程(一) ——win7下安装RabbitMQ

    RabbitMQ依赖erlang,所以先安装erlang,然后再安装RabbitMQ; 下载RabbitMQ,下载地址: rabbitmq-server-3.5.6.exe和erlang,下载地址:o ...

  6. 使用 JSON.parse 反序列化 ISO 格式的日期字符串, 将返回Date格式对象

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. java 泛型基础问题汇总

    泛型是Java SE 1.5的新特性,泛型的本质是参数化类型,也就是说所操作的数据类型被指定为一个参数.这种参数类型可以用在类.接口和方法的创建中,分别称为泛型类.泛型接口.泛型方法. Java语言引 ...

  8. 程序包管理rpm、yum与简单编译安装程序

    Linux程序包管理 Linux中软件的安装主要有两种形式:一种是直接下载源代码包自行编译后安装,另一种直接获取rpm软件包进行安装. 程序的组成部分: 二进制程序:程序的主体文件,比如我们运行一个l ...

  9. Linux下查找文件的方法

    在Linux环境下查找一个文件的方法:find 路径 -name 'filename',filename不清楚全名的话可以用*号进行匹配,如“tomcat.*”.如果不清楚路径的话可以用"/ ...

  10. selenium WebDriver 八种定位方式源码

    /* * 多种元素定位方式 */ package com.sfwork; import java.util.List; import org.openqa.selenium.By; import or ...