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

    A. Fake NP
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.

    You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.

    Solve the problem to show that it's not a NP problem.

    Input

    The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).

    Output

    Print single integer, the integer that appears maximum number of times in the divisors.

    If there are multiple answers, print any of them.

    Examples
    input
    19 29
    output
    2
    input
    3 6
    output
    3
    Note

    Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html

    The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.

    The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.

    哈哈,数学推导,试几个样例直接拿代码试啊,毕竟DIV2 A轻轻松松可以水过的,写这些题就是想标记下,希望自己以后可以拿数论推一下

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int a,b;
        scanf("%d%d",&a,&b);
        if(a==b) printf("%d
    ",a);
        else if(b-a==3&&b%3==0)
        printf("%d
    ",3);
        else printf("2
    ");
        return 0;
    }
    View Code
    B. 3-palindrome
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick.

    He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible.

    Input

    The first line contains single integer n (1 ≤ n ≤ 2·105) — the length of the string.

    Output

    Print the string that satisfies all the constraints.

    If there are multiple answers, print any of them.

    Examples
    input
    2
    output
    aa
    input
    3
    output
    bba
    Note

    palindrome is a sequence of characters which reads the same backward and forward.

     B题脑洞题,类似于模拟,挺简单的

    #include<stdio.h>
    char a[5]="aabb";
    int main()
    {
        int n;
        scanf("%d",&n);
        int c=0;
        for(int i=0;i<n;i++)
        {
            printf("%c",a[c%4]);
            c++;
        }
        return 0;
    }
    View Code
    C. Find Amir
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.

    There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs  and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.

    Input

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

    Output

    Print single integer: the minimum cost of tickets needed to visit all schools.

    Examples
    input
    2
    output
    0
    input
    10
    output
    4
    Note

    In the first example we can buy a ticket between the schools that costs .

    继续脑洞啊,肯定是让首尾连两个结合啊,然后再往中间走,然后不就是(n-1)/2了

    #include <stdio.h>
    int main(){
    int n;
    scanf("%d",&n);
    printf("%d
    ",n-1>>1);
    return 0;}
    View Code
    D. Minimum number of steps
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7.

    The string "ab" appears as a substring if there is a letter 'b' right after the letter 'a' somewhere in the string.

    Input

    The first line contains the initial string consisting of letters 'a' and 'b' only with length from 1 to 106.

    Output

    Print the minimum number of steps modulo 109 + 7.

    Examples
    input
    ab
    output
    1
    input
    aab
    output
    3
    Note

    The first example: "ab"  →  "bba".

    The second example: "aab"  →  "abba"  →  "bbaba"  →  "bbbbaa".

     有点像做过的PAT这种题,就是有只有这两种字符,不是b就是a啊,多推一会得到公式就好,有点dp的感觉

    #include <bits/stdc++.h>
    using namespace std;
    const int N=1e9+7;
    int main()
    {
        string s;
        cin>>s;
        int ans=0;
        int t=0;
        for(int i=s.length()-1;i>=0;i--)
        {
            if(s[i]=='b')
                t=(t+1)%N;
            else
            {
                ans=(ans+t)%N;
                t=(t*2)%N;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    FBX Software Development Kit
    如何用Nsight调试C# OpenGL程序
    Xcode如何编译Debug版和Release版
    Mapbox
    OpenGL
    OpenGL Tutorial
    Unity3D Sprite Draw Call合批规则
    MONO加载DLL调试命令
    如何在Flash Builder里新建ActionScript工程
    Flash Frameworks
  • 原文地址:https://www.cnblogs.com/BobHuang/p/6826564.html
Copyright © 2011-2022 走看看