zoukankan      html  css  js  c++  java
  • Codeforces Round #404 (Div. 2) ABC

    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!

    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.

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 string str[5] = {"Tetrahedron","Cube","Octahedron","Dodecahedron","Icosahedron"};
     6 int num[5] = {4,6,8,12,20};
     7 int main()
     8 {
     9 
    10     int n;
    11     scanf("%d",&n);
    12     int ans = 0;
    13     for(int i=0;i<n;i++) {
    14         string s;
    15         cin>>s;
    16         int flag = -1;
    17 
    18         for(int i=0;i<5;i++) {
    19             if(str[i]==s) {
    20                 flag = i;
    21                 break;
    22             }
    23         }
    24         if(flag!=-1) {
    25             ans += num[flag];
    26         }
    27     }
    28     cout<<ans<<endl;
    29     return 0;
    30 }
    View Code
    B. Anton and Classes

    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.

    分析: 按照左右端点排序,找相隔最远的区间。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 struct Chess {
     6     int l,r;
     7 }chess[200010];
     8 
     9 bool cmp1(Chess a,Chess b) {
    10     return a.r < b.r;
    11 }
    12 
    13 bool cmp3(Chess a,Chess b) {
    14     return a.l < b.l;
    15 }
    16 
    17 struct Prog {
    18     int l,r;
    19 }progs[200010];
    20 
    21 bool cmp2(Prog a,Prog b) {
    22     return a.l < b.l;
    23 }
    24 
    25 bool cmp4(Prog a,Prog b) {
    26     return a.r < b.r;
    27 }
    28 
    29 int main()
    30 {
    31     int n,m;
    32     scanf("%d",&n);
    33 
    34     for(int i=0;i<n;i++)
    35         scanf("%d%d",&chess[i].l,&chess[i].r);
    36 
    37     scanf("%d",&m);
    38     for(int i=0;i<m;i++)
    39         scanf("%d%d",&progs[i].l,&progs[i].r);
    40 
    41     sort(chess,chess+n,cmp1);
    42     sort(progs,progs+m,cmp2);
    43 
    44     int ans = 0;
    45     if(chess[0].r<progs[m-1].l)
    46         ans = progs[m-1].l - chess[0].r;
    47 
    48     if(progs[0].r<chess[n-1].l)
    49         ans = max(ans,chess[n-1].l-progs[0].r);
    50 
    51     sort(chess,chess+n,cmp3);
    52     sort(progs,progs+m,cmp4);
    53 
    54     if(chess[n-1].l>progs[0].r) {
    55         ans = max(ans,chess[n-1].l - progs[0].r);
    56     }
    57 
    58     if(progs[m-1].l>chess[0].r) {
    59         ans = max(ans,progs[m-1].l - chess[0].r);
    60     }
    61 
    62     cout<<ans<<endl;
    63 
    64     return 0;
    65 }
    View Code
    C. Anton and Fairy Tale

    Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:

    "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."

    More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens:

    • m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account).
    • Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.

    Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!

    Input

    The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018) — the capacity of the barn and the number of grains that are brought every day.

    Output

    Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.

    分析:

    当每次供给很大的时候,第二天总能将它补满,那么只能是,一天之内就将食物全部吃完。也就是第 n 天。

    否则的话:

    前 m 天,每次吃走一些,又补满,这样持续 m 天,m 天后,粮食才开始减少,每天减少 1 ,2,3,

    也就是:

    m + (1+mid)*mid/2 >=n 的时候就吃完了,注意这个 mid 时间,是 m 天之后的,那个时候才开始减少。也就是说,结果是 mid + m。

    注意,二分的时候, 右区间的范围很大。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     long long n,m;
     8     cin>>n>>m;
     9 
    10     if(m>=n)
    11         cout<<n<<endl;
    12     else {
    13         long long l = 0,r = ((long long)1<<31);
    14 
    15         while(l<r) {
    16 
    17             long long mid = l + (r - l)/2;
    18             if(m + (mid+1)*mid/2 < n)
    19                 l = mid+ 1;
    20             else r = mid;
    21 
    22         }
    23         cout<<m+l<<endl;
    24     }
    25 
    26     return 0;
    27 }
    View Code
  • 相关阅读:
    实现移动端1像素线--stylus
    用户信息认证session和token
    深入了解new的过程,和call,apply,bind的区别
    微信公众号开发过程--踏坑指南
    Better-scroll巨坑!!!
    JS ES6中Arguments和Parameters的区别
    知识点1
    面试--随笔1
    pytts3语音合成遇到的中文问题
    需求,需要谁参与进来?
  • 原文地址:https://www.cnblogs.com/TreeDream/p/6558915.html
Copyright © 2011-2022 走看看