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

    A - Turn the Rectangles

     CodeForces - 1008B 

    There are nn rectangles in a row. You can either turn each rectangle by 9090 degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles.

    Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such).

    Input

    The first line contains a single integer nn (1n1051≤n≤105) — the number of rectangles.

    Each of the next nn lines contains two integers wiwi and hihi (1wi,hi1091≤wi,hi≤109) — the width and the height of the ii-th rectangle.

    Output

    Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO".

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

    Examples

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

    Note

    In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3].

    In the second test, there is no way the second rectangle will be not higher than the first one.

    这题是之前写过的一道原题,博客里也有

    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    int main()
    {
        char s[100005];
        while(~scanf("%s",s))
        {
            int k,ans=0,t,ans2=0,ans1=0;
            k=strlen(s);
            for(int i=0; i<k; i++)
            {
                if(s[i]=='1')
                    ans++;
                if(s[i]=='0')
                    ans2++;
                if(s[i]=='2')
                    ans1++;
            }
            for(int i=0; i<k; i++)
            {
                if(s[i]=='2')
                {
                    t=i;
                    break;
                }
            }
            if(ans1>0)
            {
                for(int i=0; i<k; i++)
                {
                    if(i==t)
                    {
                        for(int j=1; j<=ans; j++)
                        {
                            printf("1");
                        }
                    }
                        if(s[i]=='1')
                            continue;
                        else
                            printf("%c",s[i]);
                }
            }
            else
            {
                for(int i=0; i<ans2; i++)
                    printf("0");
                for(int i=0; i<ans; i++)
                    printf("1");
            }
            printf("
    ");
        }
        return 0;
    }

    B - Reorder the Array

     CodeForces - 1008C 

    You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.

    For instance, if we are given an array [10,20,30,40][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. Read the note for the first example, there is one more demonstrative test case.

    Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

    Input

    The first line contains a single integer nn (1n1051≤n≤105) — the length of the array.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) — the elements of the array.

    Output

    Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

    Examples

    Input
    7
    10 1 1 1 5 5 3
    Output
    4
    Input
    5
    1 1 1 1 1
    Output
    0

    Note

    In the first sample, one of the best permutations is [1,5,5,3,10,1,1][1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.

    In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

    题意:给你一个数组,让你重新排列,使得当前位置的数字比原来的数字大,求这样的位置最多有多少个

    分析:

    比如数组 10 1 1 1 5 5 3

    从小到大排序  1 1 1 3 5 5 10

    用两个指针来遍历,指针i与指针j,一开始指针i指在第1个数,指针j指在第2个数,如果a[j]>a[i],i指针向后移一位,ans++;否则,i指针还是指在原来的位置;j指针向后移,直到j>n。

    思路:其实就是想让第一小的位置 放第二小的数字,第二小的位置放第三小的数字,以此类推

    比如数组1 2 3 4 5 6  当排列为 2 3 4 5 6 1 时这样的位置有5个 最大

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,a[100005];
     8     while(~scanf("%d",&n))
     9     {
    10         for(int i=1; i<=n; i++)
    11             scanf("%d",&a[i]);
    12         sort(a+1,a+1+n);
    13         int ans=0,j=2;
    14         for(int i=1; j<=n; j++)
    15         {
    16             if(a[j]>a[i])
    17             {
    18                 i++;
    19                 ans++;
    20             }
    21         }
    22         printf("%d
    ",ans);
    23     }
    24     return 0;
    25 }

    C - Romaji

     CodeForces - 1008A 

    Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.

    In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.

    Help Vitya find out if a word ss is Berlanese.

    Input

    The first line of the input contains the string ss consisting of |s||s| (1|s|1001≤|s|≤100) lowercase Latin letters.

    Output

    Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO".

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

    Examples

    Input
    sumimasen
    Output
    YES
    Input
    ninja
    Output
    YES
    Input
    codeforces
    Output
    NO

    Note

    In the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.

    In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.

    分析题意:元音字符有a e i o u,辅音字符是除了元音字符以外的字母,辅音字母后面只能跟元音字母,除了辅音字母n,它后面可以跟任意字符或者不跟字符;元音字符后面可以跟任意字符。给你一个字符串,如果满足以上条件,则输出yes,否则输出no

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     char s[105];
     8     while(~scanf("%s",s))
     9     {
    10         int k,i;
    11         k=strlen(s);
    12         for(i=0;i<k;i++)
    13         {
    14             if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u')
    15             {
    16                 continue;
    17             }
    18             else
    19             {
    20                 if(s[i]!='n')
    21                 {
    22                     if(s[i+1]=='a'||s[i+1]=='e'||s[i+1]=='i'||s[i+1]=='o'||s[i+1]=='u')
    23                         continue;
    24                     else if(i==k-1)
    25                         break;
    26                     else
    27                     {
    28                         break;
    29                     }
    30                 }
    31             }
    32         }
    33         if(i==k)
    34             printf("YES
    ");
    35         else
    36             printf("NO
    ");
    37     }
    38     return 0;
    39 }

    D - Game Shopping

     CodeForces - 1009A 

    Maxim wants to buy some games at the local game shop. There are nn games in the shop, the ii-th game costs cici.

    Maxim has a wallet which can be represented as an array of integers. His wallet contains mm bills, the jj-th bill has value ajaj.

    Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.

    When Maxim stands at the position ii in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the ii-th game using this bill. After Maxim tried to buy the nn-th game, he leaves the shop.

    Maxim buys the ii-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the ii-th game. If he successfully buys the ii-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.

    For example, for array c=[2,4,5,2,4]c=[2,4,5,2,4] and array a=[5,3,4,6]a=[5,3,4,6] the following process takes place: Maxim buys the first game using the first bill (its value is 55), the bill disappears, after that the second bill (with value 33) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because c2>a2c2>a2, the same with the third game, then he buys the fourth game using the bill of value a2a2 (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value a3a3.

    Your task is to get the number of games Maxim will buy.

    Input

    The first line of the input contains two integers nn and mm (1n,m10001≤n,m≤1000) — the number of games and the number of bills in Maxim's wallet.

    The second line of the input contains nn integers c1,c2,,cnc1,c2,…,cn (1ci10001≤ci≤1000), where cici is the cost of the ii-th game.

    The third line of the input contains mm integers a1,a2,,ama1,a2,…,am (1aj10001≤aj≤1000), where ajaj is the value of the jj-th bill from the Maxim's wallet.

    Output

    Print a single integer — the number of games Maxim will buy.

    Examples

    Input
    5 4
    2 4 5 2 4
    5 3 4 6
    Output
    3
    Input
    5 2
    20 40 50 20 40
    19 20
    Output
    0
    Input
    6 4
    4 8 15 16 23 42
    1000 1000 1000 1000
    Output
    4

    Note

    The first example is described in the problem statement.

    In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.

    In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.

    题意:商店里有n个玩具,你的钱包里有m张票子,下面一行n个数分别代表第i个玩具的价格,再下面一行有m个数分别代表第j张票子的价值。如果你的第一张钞票的价值大于等于第i个玩具的价格,ans++,第一张钞票失效,现在的第一张变成了后面的那张钞票。求你能买到的玩具的数量

    分析:其实这道题也用了双指针,唔,代码很容易看懂,题目说了,这个人是按照输入的顺序来买玩具的

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     int n,m,c[1005],a[1005];//c数组代表玩具的价格,a数组代表票子的价值
     8     while(~scanf("%d %d",&n,&m))
     9     {
    10         for(int i=1;i<=n;i++)
    11             scanf("%d",&c[i]);
    12         for(int i=1;i<=m;i++)
    13             scanf("%d",&a[i]);
    14         int j=1,ans=0;//ans表示买到的玩具的数量
    15         for(int i=1;i<=n;i++)
    16         {
    17             if(a[j]>=c[i])
    18             {
    19                 ans++;
    20                 j++;
    21             }//如果买到了,就用下一张票子来买,所以j++
    22             if(j==m+1)//当票子花光了就跳出
    23                 break;
    24         }
    25         printf("%d
    ",ans);
    26     }
    27     return 0;
    28 }

    E - Minimum Ternary String

     CodeForces - 1009B 

    You are given a ternary string (it is a string which consists only of characters '0', '1' and '2').

    You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characters '1' and '2' (i.e. replace "12" with "21" or vice versa).

    For example, for string "010210" we can perform the following moves:

    • "010210" → "100210";
    • "010210" → "001210";
    • "010210" → "010120";
    • "010210" → "010201".

    Note than you cannot swap "02" → "20" and vice versa. You cannot perform any other operations with the given string excluding described above.

    You task is to obtain the minimum possible (lexicographically) string by using these swaps arbitrary number of times (possibly, zero).

    String aa is lexicographically less than string bb (if strings aa and bb have the same length) if there exists some position ii (1i|a|1≤i≤|a|, where |s||s| is the length of the string ss) such that for every j<ij<i holds aj=bjaj=bj, and ai<biai<bi.

    Input

    The first line of the input contains the string ss consisting only of characters '0', '1' and '2', its length is between 11 and 105105 (inclusive).

    Output

    Print a single string — the minimum possible (lexicographically) string you can obtain by using the swaps described above arbitrary number of times (possibly, zero).

    Examples

    Input
    100210
    Output
    001120
    Input
    11222121
    Output
    11112222
    Input
    20
    Output
    20
    这题没读懂题,蛮心痛的,不过也没什么好心痛的,读懂了想了半个小时也没想出来
    看了题解啧啧
    题意:要你求最小字典序,前提是,0和1能互相交换,1和2能互相交换,但是0,2不能互相交换
    分析:你会发现,1是可以分布在任意位置的,而2,0的位置相对是不变的,只要把所有的1在第一个2之前输出即可,其他元素位置不变,还要考虑当2的数量为0的时候
     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 int main()
     6 {
     7     char s[100005];
     8     while(~scanf("%s",s))
     9     {
    10         int k,ans=0,t,ans2=0,ans1=0;
    11         k=strlen(s);
    12         for(int i=0; i<k; i++)
    13         {
    14             if(s[i]=='1')
    15                 ans++;
    16             if(s[i]=='0')
    17                 ans2++;
    18             if(s[i]=='2')
    19                 ans1++;
    20         }//统计0,1,2的数量
    21         for(int i=0; i<k; i++)
    22         {
    23             if(s[i]=='2')
    24             {
    25                 t=i;
    26                 break;
    27             }//找到第一个2的位置
    28         }
    29         if(ans1>0)//如果2的数量大于0
    30         {
    31             for(int i=0; i<k; i++)
    32             {
    33                 if(i==t)//在第一个2之前输出所有的1
    34                 {
    35                     for(int j=1; j<=ans; j++)
    36                     {
    37                         printf("1");
    38                     }
    39                 }
    40                     if(s[i]=='1')
    41                         continue;
    42                     else
    43                         printf("%c",s[i]);//其他元素照样输出除了1
    44             }
    45         }
    46         else//当2的数量为0的时候
    47         {
    48             for(int i=0; i<ans2; i++)
    49                 printf("0");
    50             for(int i=0; i<ans; i++)
    51                 printf("1");
    52         }
    53         printf("
    ");
    54     }
    55     return 0;
    56 }


  • 相关阅读:
    fatfs输出目录
    《基于多光程长的高散射物质光学参数的测量及其应用》论文
    《2013李永乐线性代数强化班》视频1,2,3,4
    oled屏幕模块
    python中数据结构
    大数据python词频统计之hdfs分发-cacheFile
    8大排序之Python实现 冒泡排序优化
    大数据python词频统计之本地分发-file
    2019-04-30vmware虚拟机安装macos 10.8格式为iso
    2019-04-24Scurecrt 如何下载文本文件
  • 原文地址:https://www.cnblogs.com/LLLAIH/p/9735120.html
Copyright © 2011-2022 走看看