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 ;
}