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代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 char s[100]; 6 int n; 7 while(scanf("%d",&n)!=EOF) 8 { 9 int ans=0; 10 while(n--) 11 { 12 scanf("%s",s); 13 if(s[0]=='I'&&s[1]=='c'&&s[2]=='o'&&s[3]=='s'&&s[4]=='a'&&s[5]=='h'&&s[6]=='e'&&s[7]=='d'&&s[8]=='r'&&s[9]=='o'&&s[10]=='n') 14 ans+=20; 15 else if(s[0]=='C'&&s[1]=='u'&&s[2]=='b'&&s[3]=='e') 16 ans+=6; 17 else if(s[0]=='T'&&s[1]=='e'&&s[2]=='t'&&s[3]=='r'&&s[4]=='a'&&s[5]=='h'&&s[6]=='e'&&s[7]=='d'&&s[8]=='r'&&s[9]=='o'&&s[10]=='n') 18 ans+=4; 19 else if(s[0]=='D'&&s[1]=='o'&&s[2]=='d'&&s[3]=='e'&&s[4]=='c'&&s[5]=='a'&&s[6]=='h'&&s[7]=='e'&&s[8]=='d'&&s[9]=='r'&&s[10]=='o'&&s[11]=='n') 20 ans+=12; 21 else if(s[0]=='O'&&s[1]=='c'&&s[2]=='t'&&s[3]=='a'&&s[4]=='h'&&s[5]=='e'&&s[6]=='d'&&s[7]=='r'&&s[8]=='o'&&s[9]=='n') 22 ans+=8; 23 } 24 printf("%d\n",ans); 25 } 26 }
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的代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn=200010; 4 struct node 5 { 6 int start,end; 7 }p[maxn]; 8 struct Node 9 { 10 int start,end; 11 }t[maxn]; 12 bool cmp1(node x,node y) 13 { 14 if(x.start<y.start&&x.end<y.end) 15 return true; 16 if(x.start==y.start&&x.end<y.end) 17 return true; 18 return false; 19 } 20 bool cmp2(Node x,Node y) 21 { 22 if(x.start<y.start&&x.end<y.end) 23 return true; 24 if(x.start==y.start&&x.end<y.end) 25 return true; 26 return false; 27 } 28 int main() 29 { 30 int n,m; 31 while(scanf("%d",&n)!=EOF) 32 { 33 for(int i=1;i<=n;i++) 34 scanf("%d%d",&p[i].start,&p[i].end); 35 scanf("%d",&m); 36 for(int i=1;i<=m;i++) 37 scanf("%d%d",&t[i].start,&t[i].end); 38 sort(p+1,p+1+n,cmp1); 39 sort(t+1,t+1+m,cmp2); 40 int mm=1000000000,mp,nm=1000000000,np; 41 for(int i=1;i<=n;i++) 42 { 43 np=max(np,p[i].start); 44 nm=min(nm,p[i].end); 45 } 46 for(int i=1;i<=m;i++) 47 { 48 mp=max(mp,t[i].start); 49 mm=min(mm,t[i].end); 50 } 51 int q=max(0,max(mp-nm,np-mm)); 52 printf("%d\n",q); 53 } 54 return 0; 55 }