• Codeforces Round #342 (Div. 2)


    比赛链接:click here


    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 ab and c (1 ≤ a ≤ 10181 ≤ 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.


    思路:看清题意
    代码:
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    int main()
    {
        LL n,a,b,c;
        scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
        LL res=0;
        if(n>=b && b-c<=a)
        {
            res+=(n-b)/(b-c)+1;
            n-=res*(b-c);
        }
        res+=n/a;
        printf("%I64d",res);
        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".


    思路:模拟就可以,找到子串的个数就可以

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    const int maxn=1e5+10;
    char s[maxn],t[maxn];
    int main()
    {
        scanf("%s%s",s,t);
        int res=0;
        for(int i=0; i+m<=n; ++i)
        {
            bool flag=true;
            for(int j=0; j<m; ++j)
                if(s[i+j]!=t[j])flag=false;
            if(flag)
            {
                s[i+m-1]='#';
                res++;
            }
        }
        printf("%d
    ",res);
        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
    
    
    思路:暴力模拟即可,要单调递增,那么就从后面单调递减即可了

    代码:

    #include <iostream>
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int maxn =1e5+10;
    int a[505][505];
    int main()
    {
        int n,k;
        scanf("%d%d",&n,&k);
        int cnt=n*n;
        for(int i=1; i<=n; i++)
        {
            for(int j=n; j>=k; j--)
            {
                a[i][j]=cnt--;
            }
        }
        for(int i=1; i<=n; i++)
            for(int j=k-1; j>=1; j--)
                a[i][j]=cnt--;
        int tot=0;
        for(int i=1; i<=n; i++)
            tot+=a[i][k];
        printf("%d
    ",tot);
        for(int i=1; i<=n; i++)
        {
            for(int j=1; j<=n; j++)
                printf("%s%d",(j>1 ?

    " " :""),a[i][j]); printf(" "); } return 0; }




  • 相关阅读:
    【产品设计】设计中的文档管理
    【基础知识】极管类器件的选用
    【Altium Designer】DatabaseLib的使用方法
    【电力电子】功率因素无功功率
    【基础知识】电阻标称阻值查询表
    【元器件】电容的使用
    【EMC】浪涌
    【仪表】电力专用术语
    往mysql中插入一条新的数据
    mysql 中导出表源码
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/7140463.html
Copyright © 2020-2023  润新知