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 }
  • 相关阅读:
    DataGrid数据格式设置表达式
    删除确认按钮
    获取CpuID
    R0~R31寄存器
    动态改变asp.net网页的标题
    使用"Infragistics"问题集
    Read Cpu Id
    操作DataRow记录
    用Javascript创建"后退"按钮
    日历控件的“星期几”变为“几”
  • 原文地址:https://www.cnblogs.com/z-712/p/7544235.html
Copyright © 2011-2022 走看看