zoukankan      html  css  js  c++  java
  • 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}.

    题意:求因子

    1 #include <bits/stdc++.h>
    2 using namespace std;
    3 int main(){  
    4     int l,r;
    5     scanf("%d%d",&l,&r);
    6     if(l==r) printf("%d
    ",l);
    7     else printf("2
    ");      
    8 
    9 } 
    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".

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int mod=1e9+7;
     4 int main(){
     5     string s;
     6     cin>>s;
     7     int ans=0;
     8     int t=0;
     9     for(int i=s.length()-1;i>=0;i--){
    10         if(s[i]=='b')
    11             t=(t+1)%mod;
    12         else {
    13         ans=(ans+t)%mod;
    14         t=(t*2)%mod;
    15         }
    16     }
    17     cout<<ans<<endl;
    18     return 0;
    19 }
  • 相关阅读:
    计算机专业,刚刚大一,该如何学好程序设计?
    打王者要有装备,学编程要有设备,学习编程必备大礼包
    Java学习笔记:数据库中的范式和反范式的区别
    linux云计算主要就业岗位有哪些
    字典
    python统计字符串里每个字符的次数
    cf509B Painting Pebbles
    cf509A Maximum in Table
    bzoj1996 [Hnoi2010]chorus 合唱队
    bzoj3173 [Tjoi2013]最长上升子序列
  • 原文地址:https://www.cnblogs.com/z-712/p/7544235.html
Copyright © 2011-2022 走看看