Codeforces Round #404 (Div. 2)(A+B)

来源:互联网 发布:淘宝卖家和买家都被骗 编辑:程序博客网 时间:2024/05/21 17:46

A. Anton and Polyhedrons
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
题意:问n个图形一共有多少个面。
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;const int N=1e9;string str;int main(){    int n;    cin>>n;    int ans=0;    for(int i=1; i<=n; i++)    {        cin>>str;        if(str=="Tetrahedron") ans+=4;        if(str=="Cube") ans+=6;        if(str=="Octahedron") ans+=8;        if(str=="Dodecahedron") ans+=12;        if(str=="Icosahedron") ans+=20;    }    cout<<ans<<endl;}

B. Anton and Classes
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
题意:给出n个时间段和m个时间段,问nm之间的最大时间间隔。
题解:ans=max(l)-min(r);
代码:

#include<bits/stdc++.h>#define ll long longusing namespace std;struct node{    int l,r;}a[200100],b[200100];int main(){    int n,m;    int q,w,e,r;    q=e=1e9+10;    w=r=0;    cin>>n;    for(int i=1;i<=n;i++) cin>>a[i].l>>a[i].r,q=min(q,a[i].r),r=max(r,a[i].l);    cin>>m;    for(int i=1;i<=m;i++) cin>>b[i].l>>b[i].r,w=max(w,b[i].l),e=min(e,b[i].r);    int ans=max(0,w-q);    int ans2=max(0,r-e);    cout<<max(ans,ans2)<<endl;}
0 0
原创粉丝点击