zoukankan      html  css  js  c++  java
  • Codeforces Round #342 (Div 2) 解题报告

     除夕夜之有生之年CF第一场
    

    下午从奶奶家回到姥姥家,一看还有些时间,先吃点水果陪姥姥姥爷聊了会儿,再一看表,5:20。。。。woc已经开场20分钟了。。。于是抓紧时间乱搞。。

                                           **A. Guest From the Past**
    

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
    Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles.
    Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn’t know how to act optimally and asks for your help.

    Input
    First line of the input contains a single integer n (1 ≤ n ≤ 1018) — the number of rubles Kolya has at the beginning.
    Then follow three lines containing integers a, b and c (1 ≤ a ≤ 1018, 1 ≤ c < b ≤ 1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively.

    Output
    Print the only integer — maximum number of liters of kefir, that Kolya can drink.
    Sample test(s)

    Input
    10
    11
    9
    8
    Output
    2

    Input
    10
    5
    6
    1
    Output
    2

    Note
    In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
    In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir.

    题目大意:有个人想要买喝的,有塑料瓶装的和玻璃瓶装的,此人有n块钱,每瓶塑料瓶装的要a块钱,每瓶玻璃瓶装的要b块钱,但是每个玻璃瓶可以返还c块钱,为这个人最多能喝多少瓶

    写在前面:一看这到题,打开翻译,翻译的什么东西,硬生生读了两遍好不容易读懂。。。有点像贪心啊,话不多说,写!写完之后,很好,轻松A,一会儿,被hack了。。。于是改之,不慌。。。

    题解:
    先判断塑料瓶的价钱和玻璃瓶的净价钱(一瓶玻璃瓶装-返还的玻璃瓶钱)大小关系,如果塑料瓶装便宜,全买塑料瓶不解释。
    否则 先狂买玻璃瓶装的 买到买不起为止 剩下的全都买塑料瓶装的 (要是一开始就买不起 那就直接买塑料瓶喽,啥都买不起喝西北风去吧)

    code:

    #include<iostream> 
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    long long mon;
    long long pl,gl,glb;
    long long ans=0;
    
    long long read()
    {
        long long x=0,f=1;char ch=getchar();
        while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();}
        while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
        return x*f;
    }
    
    int main()
    {
        mon=read();pl=read();gl=read();glb=read();
        long long glm=gl-glb;
        if (pl<=glm) printf("%I64d
    ",mon/pl);
        else
            {
                if (mon>=gl)
                    ans=1+(mon-gl)/glm,mon-=ans*glm;
                ans+=mon/pl;
                printf("%I64d
    ",ans);
            }
        return 0;
    }
                                                         **B. War of the Corporations**
    

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it’s new tablet Lastus 3000.
    This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol’s artificial intelligence.
    Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol’s director decided to replace some characters in AI name with “#”. As this operation is pretty expensive, you should find the minimum number of characters to replace with “#”, such that the name of AI doesn’t contain the name of the phone as a substring.
    Substring is a continuous subsequence of a string.

    Input
    The first line of the input contains the name of AI designed by Gogol, its length doesn’t exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn’t exceed 30. Both string are non-empty and consist of only small English letters.

    Output
    Print the minimum number of characters that must be replaced with “#” in order to obtain that the name of the phone doesn’t occur in the name of AI as a substring.
    Sample test(s)

    Input
    intellect
    tell
    Output
    1

    Input
    google
    apple
    Output
    0

    Input
    sirisiri
    sir
    Output
    2

    Note
    In the first sample AI’s name may be replaced with “int#llect”.
    In the second sample Gogol can just keep things as they are.
    In the third sample one of the new possible names of AI may be “s#ris#ri”.

    题目大意:说实话,翻译我也没看懂,不过看样例发现,似乎是字符串匹配啊。给出串1串2,求串2在串1中出现的次数

    写在前面:读不懂翻译,有道就是蛋疼。。。KMP裸题啊,shabi题啊,于是秒出模版,哦呵呵。。提交WA?!。。不能理解,一看数据范围,傻逼范围,暴力艹标算,1分钟暴力打完,妥A。。。(原来KMP时串1串2输反了。。)

    题解:
    傻逼暴力,比较S1【i】和S2【j】,如果不相等i+=len2。。。找到一个ans+1。。。shabi题不解释

    code:

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    using namespace std;
    char s1[100010],s2[100010];
    int ans=0;
    int l1,l2;
    
    int main()
    {
        gets(s1); gets(s2);
        l1=strlen(s1); l2=strlen(s2); 
        for (int i=0; i<=l1-l2;)
            {
                bool f=true;
                for (int j=0; j<=l2-1; j++)
                    if (s1[i+j]!=s2[j]) {f=false;break;}
                if (f) ans++,i+=l2;
                  else i++;
            }   
        printf("%d",ans);
        return 0;
    }
                                               **C. K-special Tables**
    

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
    Alis is among these collectors. Right now she wants to get one of k-special tables. In case you forget, the table n × n is called k-special if the following three conditions are satisfied:
    • every integer from 1 to n2 appears in the table exactly once;
    • in each row numbers are situated in increasing order;
    • the sum of numbers in the k-th column is maximum possible.
    Your goal is to help Alice and find at least one k-special table of size n × n. Both rows and columns are numbered from 1 to n, with rows numbered from top to bottom and columns numbered from left to right.

    Input
    The first line of the input contains two integers n and k (1 ≤ n ≤ 500, 1 ≤ k ≤ n) — the size of the table Alice is looking for and the column that should have maximum possible sum.

    Output
    First print the sum of the integers in the k-th column of the required table.
    Next n lines should contain the description of the table itself: first line should contains n elements of the first row, second line should contain n elements of the second row and so on.
    If there are multiple suitable table, you are allowed to print any.

    Sample test(s)
    Input
    4 1
    Output
    28
    1 2 3 4
    5 6 7 8
    9 10 11 12
    13 14 15 16

    Input
    5 3
    Output
    85
    5 6 17 18 19
    9 10 23 24 25
    7 8 20 21 22
    3 4 14 15 16
    1 2 11 12 13

    题目大意:构造一个长宽为n的矩阵,使第k列之和最大,要求1到n*n所有数都出现,且每一行从左到右要求为递增

    写在前面:一开始并不太会做,于是水了水codeVS群。。。里面一个神犇说,第三题shabi题,对着样例找规律,于是开搞,于是轻松A掉了(其实交的时候很虚。——)。。。

    题解:
    对着样例找规律喽,没什么好说的吧。。

    code:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int mat[1000][1000];
    int n,k;
    
    int main()
    {
        while (~scanf("%d%d",&n,&k))
            {
                int cnt=1,ans=0;
                for (int i=1; i<=n; i++)
                    for (int j=1; j<=k-1; j++)
                        mat[i][j]=cnt++;
                for (int i=1; i<=n; i++)
                    for (int j=k; j<=n; j++)
                        mat[i][j]=cnt++;
                for (int i=1; i<=n; i++)
                    ans+=mat[i][k];
                printf("%d
    ",ans);
                for (int i=1; i<=n; i++)
                    {
                        for (int j=1; j<=n-1; j++)
                             printf("%d ",mat[i][j]);
                        printf("%d
    ",mat[i][n]);
                    }
            }
        return 0;
    }
                                               **D. Finals in arithmetic**
    

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.
    Let’s denote a flip operation of an integer as follows: number is considered in decimal notation and then reverted. If there are any leading zeroes afterwards, they are thrown away. For example, if we flip 123 the result is the integer 321, but flipping 130 we obtain 31, and by flipping 31 we come to 13.
    Oksana Fillipovna picked some number a without leading zeroes, and flipped it to get number ar. Then she summed a and ar, and told Vitya the resulting value n. His goal is to find any valid a.
    As Oksana Fillipovna picked some small integers as a and ar, Vitya managed to find the answer pretty fast and became interested in finding some general algorithm to deal with this problem. Now, he wants you to write the program that for given n finds any a without leading zeroes, such that a + ar = n or determine that such a doesn’t exist.

    Input
    The first line of the input contains a single integer n (1 ≤ n ≤ 10100 000).

    Output
    If there is no such positive integer a without leading zeroes that a + ar = n then print 0. Otherwise, print any valid a. If there are many possible answers, you are allowed to pick any.

    Sample test(s)
    Input
    4
    Output
    2

    Input
    11
    Output
    10

    Input
    5
    Output
    0

    Input
    33
    Output
    21

    Note
    In the first sample 4 = 2 + 2, a = 2 is the only possibility.
    In the second sample 11 = 10 + 1, a = 10 — the only valid solution. Note, that a = 01 is incorrect, because a can’t have leading zeroes.
    It’s easy to check that there is no suitable a in the third sample.
    In the fourth sample 33 = 30 + 3 = 12 + 21, so there are three possibilities for a: a = 30, a = 12, a = 21. Any of these is considered to be correct answer.

    没来得及A,先留着,以后来挖坟。。

                                                   **E. Frog Fights**
    

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Ostap Bender recently visited frog farm and was inspired to create his own frog game.
    Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right after the cell number m in the direction of movement. i-th frog during its turn can jump for ai cells.
    Frogs move in turns, game starts with a move by frog 1. On its turn i-th frog moves ai cells forward, knocking out all the frogs on its way. If there is a frog in the last cell of the path of the i-th frog, that frog is also knocked out. After this the value ai is decreased by the number of frogs that were knocked out during this turn. If ai is zero or goes negative, than i-th frog doesn’t make moves anymore.
    After frog number 1 finishes its turn, frog number 2 starts to move, than frog number 3 and so on. After the frog number n makes its move, frog 1 starts to move again, then frog 2 and so on this process goes forever. If some frog was already knocked out from the board, we consider that it skips all its moves.
    Help Ostap to identify, what frogs will stay on the board at the end of a game?

    Input
    First line of the input contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 109, n ≤ m) — number of frogs and gameboard size, respectively.
    Following n lines contains frogs descriptions — two integers pi and ai (1 ≤ pi, ai ≤ m) — the number of cell occupied by i-th frog initially and initial jump length. All pi are guaranteed to be distinct.

    Output
    In the first line output number of frogs on the final gameboard. In the second line output their numbers in any order.

    Sample test(s)
    Input
    3 5
    2 1
    5 3
    4 3
    Output
    1
    3

    Input
    5 6
    1 2
    3 4
    2 5
    5 1
    6 1
    Output
    2
    1 4

    Note
    In the first sample first frog jumps 1 cell and finishes in cell number 3. Second frog jumps for 3 cells and finishes on cell number 3, knocking out frog number 1. Current jump length for frog number 2 is now 2. Third frog jumps to cell 2, then second frog jumps to cell 5. Third frog in turn finishes in cell 5 and removes frog 2 from the gameboard. Now, it’s the only remaining frog in the game.
    In the second sample first frog jumps 2 cells and knocks out frogs in cells 2 and 3. Its value ai is now 0. Then fourth frog jumps and knocks out fifth frog and its ai is now 0 too. These two frogs will remains on the gameboard forever.

    同上。。。。说实话我还不确定能不能做的出来呢。。。

  • 相关阅读:
    C# 中类重写 ToString 方法
    虚方法(virtual)和抽象方法(abstract)的区别
    C#的扩展方法学习
    C# .NET 和.NET Framework区别
    C#值类型和引用类型
    抽象和接口的区别和使用
    什么是委托?
    什么是继承?
    设计模式:单一职责原则
    Java 13,最新最全新特性解读
  • 原文地址:https://www.cnblogs.com/DaD3zZ-Beyonder/p/5346207.html
Copyright © 2011-2022 走看看