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 }
  • 相关阅读:
    string的erase函数和find、find_first_of函数
    strtok和strtok_r
    Linux添加硬盘 挂载硬盘(附 Linux磁盘挂载和mount共享 带图)
    linux下访问中文目录文件
    用yield写协程实现生产者消费者
    用进程池和线程池实现高并发服务器
    python自带线程池
    python自带进程池
    模拟线程池代码
    面向对象的多次调用线程(含参版)
  • 原文地址:https://www.cnblogs.com/z-712/p/7544235.html
Copyright © 2011-2022 走看看