zoukankan      html  css  js  c++  java
  • 2018SDIBT_国庆个人第六场

    A - A codeforces 714A

    Description

    Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!

    Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.

    Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.

    Calculate the number of minutes they will be able to spend together.

    Input

    The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.

    Output

    Print one integer — the number of minutes Sonya and Filya will be able to spend together.

    Sample Input

    Input
    1 10 9 20 1
    Output
    2
    Input
    1 100 50 200 75
    Output
    50

    Hint

    In the first sample, they will be together during minutes 9 and 10.

    In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.

    题意:小E要在白天去拜访S,S呢在白天只有(l1,r1)是醒着的,小E选择在(l2,r2)去拜访S,但是在第K分钟的时候,他们不能共处,问他们最多能一起相处多长时间

    分析:这题其实就是找两个区间的交集啦,注意数据量要开long long,所以错了一发

    分下面六种情况:

    l2 r2 l1 r1

    l1 r1 l2 r2

    l1 l2 r1 r2

    l2 l1 r2 r1

    l1 l2 r2 r1

    l2 l1 r1 r2

    然后开写啦~是不是很简单

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cmath>
     6 using namespace std;
     7 int main()
     8 {
     9     long long l1,r1,l2,r2,k;
    10     while(~scanf("%lld %lld %lld %lld %lld",&l1,&r1,&l2,&r2,&k))
    11     {
    12         long long sum=0;
    13         if(l1>=l2&&r2>=r1)
    14         {
    15             sum=r1-l1+1;
    16             if(k>=l1&&k<=r1)
    17                 sum--;
    18         }
    19         else if(r2<l1||l2>r1)
    20         {
    21             sum=0;
    22         }
    23         else if(l2<=l1&&r2>=l1&&r2<=r1)
    24         {
    25             sum=r2-l1+1;
    26             if(k<=r2&&k>=l1)
    27                 sum--;
    28         }
    29         else if(l2>=l1&&l2<=r1&&r2>=r1)
    30         {
    31             sum=r1-l2+1;
    32             if(k<=r1&&k>=l2)
    33                 sum--;
    34         }
    35         else if(l2>=l1&&r2<=r1)
    36         {
    37             sum=r2-l2+1;
    38             if(k>=l2&&k<=r2)
    39                 sum--;
    40         }
    41         printf("%lld
    ",sum);
    42     }
    43     return 0;
    44 }

    B - B

    codeforces 1059B

    Description

    Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

    For simplicity, the signature is represented as an n×mn×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×33×3 square without its central cell if it is completely contained inside the grid, as shown below.


    xxx
    x.x
    xxx

    Determine whether is it possible to forge the signature on an empty n×mn×m grid.

    Input

    The first line of input contains two integers nn and mm (3n,m10003≤n,m≤1000).

    Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

    Output

    If Andrey can forge the signature, output "YES". Otherwise output "NO".

    You can print each letter in any case (upper or lower).

    Sample Input

    Input
    3 3
    ###
    #.#
    ###
    Output
    YES
    Input
    3 3
    ###
    ###
    ###
    Output
    NO
    Input
    4 3
    ###
    ###
    ###
    ###
    Output
    YES
    Input
    5 7
    .......
    .#####.
    .#.#.#.
    .#####.
    .......
    Output
    YES

    Hint

    In the first sample Andrey can paint the border of the square with the center in (2,2)(2,2).

    In the second sample the signature is impossible to forge.

    In the third sample Andrey can paint the borders of the squares with the centers in (2,2)(2,2) and (3,2)(3,2):

    1. we have a clear paper:

      ...
      ...
      ...
      ...
    2. use the pen with center at (2,2)(2,2).

      ###
      #.#
      ###
      ...
    3. use the pen with center at (3,2)(3,2).

      ###
      ###
      ###
      ###

    In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3)(3,3) and (3,5)(3,5).

     题意:给你一个n*m的矩阵,问你这个矩阵是否可行,如果可以,则输出YES否则输出NO.一开始矩阵全由'.'组成,一个点只能影响它周围九个点,使其变为'#'.

    分析:另外再开一个数组b,模拟一遍,如果数组a中存在周围九个点都是'#',则将b数组中对应的那九个点变为'#',最后判断a数组与b数组是否相等

     
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    #include<iostream>
    using namespace std;
    char a[1005][1005],b[1005][1005];
    void judge(int i,int j)
    {
        int flag=0;
        for(int t=i-1;t<=i+1;t++)
            for(int tt=j-1;tt<=j+1;tt++)
        {
            if(t==i&&tt==j)
                continue;
            if(a[t][tt]!='#')
            {
                flag=1;
                break;
            }
        }//判断周围九个点
        if(flag==0)
        {
         b[i-1][j-1]='#';
         b[i-1][j+1]='#';
         b[i][j-1]='#';
         b[i][j+1]='#';
         b[i+1][j-1]='#';
         b[i+1][j+1]='#';
         b[i-1][j]='#';
         b[i+1][j]='#';
        }//将b也染色
    }
    int main()
    {
        int n,m;
        while(~scanf("%d %d",&n,&m))
        {
            getchar();
            memset(b,'.',sizeof(b));//将b初始化
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    scanf("%c",&a[i][j]);
                }
                getchar();
    
            }
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(i-1>=1&&i+1<=n&&j-1>=1&&j+1<=m)
                            judge(i,j);
                 }
            }
            int flag=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m;j++)
                {
                    if(a[i][j]!=b[i][j])
                    {
                        flag=1;
                        break;
                    }
                }
            }//判断a数组与b数组是否相等
            if(flag==1)
                printf("NO
    ");
            else
                printf("YES
    ");
        }
        return 0;
    }

    D - D codeforces 714B

    Description

    Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.

    Filya is given an array of non-negative integers a1, a2, ..., an. First, he pick an integer x and then he adds x to some elements of the array (no more than once), subtract x from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.

    Now he wonders if it's possible to pick such integer x and change some elements of the array using this x in order to make all elements equal.

    Input

    The first line of the input contains an integer n (1 ≤ n ≤ 100 000) — the number of integers in the Filya's array. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 109) — elements of the array.

    Output

    If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes).

    Sample Input

    Input
    5
    1 3 3 2 1
    Output
    YES
    Input
    5
    1 2 3 4 5
    Output
    NO

    Hint

    In the first sample Filya should select x = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.

    题意:给你一个数组,可以选择对这个数组的某些数进行加x操作(只能操作一次)或者对这个数组里的某些数进行减x操作(只能操作一次),问是否能使整个数组里的所有数都相等,如果可以,输出YES,否则输出NO

    分析:如果数组里不同的数的个数大于3时,一定输出NO,

              如果数组里的不同的数的个数小于等于2时,一定输出YES

              如果数组里的不同的数的个数刚好等于3时,

              当最大的数和最小的数到中间那个数的距离相等的时候,他们加减的都是x,一定输出YES,否则输出NO

              苍天啊啊啊,一定很注意细节的问题了,交题之前还专门瞄了一眼YESNO的大小写,没想到竟然是栽在N0上,被自己蠢哭了)

     

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cmath>
     6 using namespace std;
     7 int main()
     8 {
     9     int n,a[100005],b[100005];
    10     while(~scanf("%d",&n))
    11     {
    12         int k=0;
    13        for(int i=1;i<=n;i++)
    14        {
    15            scanf("%d",&a[i]);
    16        }
    17        sort(a+1,a+1+n);
    18        b[1]=a[1];
    19        int j=2;
    20        for(int i=2;i<=n;i++)
    21        {
    22            if(a[i]!=a[i-1])
    23             {
    24                 k++;
    25                 b[j++]=a[i];
    26             }//k其实就是来统计不同的数的个数的
    27        }
    28        int t=0;
    29        if(k==2)
    30        {
    31            if(b[2]-b[1]==b[3]-b[2])
    32             t=1;
    33        }当最大的数和最小的数到中间那个数的距离相等的时候
    34        if(k<2)//当不同的数的个数小于等于2时
    35         t=1;
    36        if(k>2||t==0)
    37        {
    38            printf("NO
    ");
    39        }//当不同的数的个数大于3时
    40        else
    41        {
    42            printf("YES
    ");
    43        }
    44 
    45     }
    46     return 0;
    47 }

    E - E codeforces714c

    Description

    Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type:

    1.  + ai — add non-negative integer ai to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer.
    2.  - ai — delete a single occurrence of non-negative integer ai from the multiset. It's guaranteed, that there is at least one ai in the multiset.
    3. ?s — count the number of integers in the multiset (with repetitions) that match some pattern s consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer x matches the pattern s, if the parity of the i-th from the right digit in decimal notation matches the i-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left.

    For example, if the pattern is s = 010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.

    Input

    The first line of the input contains an integer t (1 ≤ t ≤ 100 000) — the number of operation Sonya has to perform.

    Next t lines provide the descriptions of the queries in order they appear in the input file. The i-th row starts with a character ci — the type of the corresponding operation. If ci is equal to '+' or '-' then it's followed by a space and an integer ai (0 ≤ ai < 1018) given without leading zeroes (unless it's 0). If ci equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18.

    It's guaranteed that there will be at least one query of type '?'.

    It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.

    Output

    For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.

    Sample Input

    Input
    12
    + 1
    + 241
    ? 1
    + 361
    - 241
    ? 0101
    + 101
    ? 101
    - 101
    ? 101
    + 4000
    ? 0
    Output
    2
    1
    2
    1
    1
    Input
    4
    + 200
    + 200
    - 200
    ? 0
    Output
    1

    题意:你有一个空数组,t次查询,每次查询有一个字符 c和数字a,如果c是‘+’,则把数字a加到数组中去(数组里的数字可以重复),如果c是‘-’,则把数字a从数组中删去(保证数组里一定会有数字a),如果c是‘?’,则在数组里查询有多少个数字a的奇偶性相同(a中的0代表偶数,1代表奇数),如果数组里的数字长度小于a时,则在数字的左边添零,同样,如果a的长度小于数组里的数字时,在a的左边添0,输出和a奇偶性相同的数的个数.

    分析:如果直接用数组来存的话,会TLE的,所以选择用map来存,存之前得预处理一下,把数字a转换成1和0的形式

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<iostream>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<map>
     7 using namespace std;
     8 int main()
     9 {
    10     map<long long,int>m;
    11     int t;
    12     char c;
    13     long long d;
    14     scanf("%d",&t);
    15     while(t--)
    16     {
    17         getchar();
    18         scanf("%c%lld",&c,&d);
    19         long long dd=0,k=1;
    20         while(d)
    21         {
    22             if((d%10)%2==1)
    23                 dd+=k*((d%10)%2);
    24             k*=10;
    25             d/=10;
    26         }//预处理
    27 //        printf("%lld
    ",dd);
    28         if(c=='+')
    29         {
    30              m[dd]++;
    31         }
    32         else if(c=='-')
    33         {
    34             m[dd]--;
    35         }
    36         else
    37         {
    38             printf("%d
    ",m[dd]);
    39         }
    40     }
    41     return 0;
    42 }
  • 相关阅读:
    Redis
    Log4Net
    EF脚手架生成数据库上下文(scaffold-dbcontext)
    quartz.net
    基于LNMP的小米电子商务网站平台
    LVS的DR模式负载均衡
    华为交换机SSH配置
    VMware ESXi 6.5安装
    VLAN划分
    华为路由设备SSH配置
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/9749086.html
Copyright © 2011-2022 走看看