Codeforces Round #411 (Div. 2)(A+B+C+D)

A. Fake NP
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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}.

题意:给出l和r求l到r之间每个数因子最多的是几?
题解:相同就是l否则就是2.
代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long


int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b) printf("%d\n",a);
    else printf("2\n");
    return 0;
}

B. 3-palindrome
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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
A palindrome is a sequence of characters which reads the same backward and forward.

题意:构造出一个由a,b,c组成长度为n且没有长度>=3的回文子串的串,c尽可能少。
题解:明显构造成aabbaabb这种就行。
代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%4==1||i%4==2) cout<<"a";
        else cout<<"b";
    }
    cout<<endl;
}

C. Find Amir
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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个学校,两点之间的消耗为(i+j)%(n+1)。起点终点任意,问遍历所有学校的最小消耗。
题解:消耗小,就尽可能让i+j==n+1.则1先到n(无消耗),n到(2)(消耗为1),2到n-1(消耗为1)。。。
代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    cout<<(n-1)/2<<endl;
}

D. Minimum number of steps
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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”.
题意:出现ab就用bba代替,问操作次数。
题解:

消耗新串
ab1bba
aab3bbbbaa
aaab7bbbbbbbbaaa

明显消耗为2^i-1.(i为a的个数)对于每一个b判断前面a的个数。然后求和。
代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
char a[10010000];
ll solo(ll x,int y)
{
    ll sum=1;
    while(y)
    {
        if(y&1)
        sum=(sum*x)%MOD;
        x=(x*x)%MOD;
        y>>=1;
    }
    return sum-1;
}
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    ll ans=0;
    int ge=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]=='a')
        {
            ge++;
        }
        else
        {
            if(ge==0) continue;
            ans+=solo(2,ge);
            ans=ans%MOD;
        }
    }
    printf("%I64d\n",ans%MOD);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
资源包主要包含以下内容: ASP项目源码:每个资源包中都包含完整的ASP项目源码,这些源码采用了经典的ASP技术开发,结构清晰、注释详细,帮助用户轻松理解整个项目的逻辑和实现方式。通过这些源码,用户可以学习到ASP的基本语法、服务器端脚本编写方法、数据库操作、用户权限管理等关键技术。 数据库设计文件:为了方便用户更好地理解系统的后台逻辑,每个项目中都附带了完整的数据库设计文件。这些文件通常包括数据库结构图、数据表设计文档,以及示例数据SQL脚本。用户可以通过这些文件快速搭建项目所需的数据库环境,并了解各个数据表之间的关系和作用。 详细的开发文档:每个资源包都附有详细的开发文档,文档内容包括项目背景介绍、功能模块说明、系统流程图、用户界面设计以及关键代码解析等。这些文档为用户提供了深入的学习材料,使得即便是从零开始的开发者也能逐步掌握项目开发的全过程。 项目演示与使用指南:为帮助用户更好地理解和使用这些ASP项目,每个资源包中都包含项目的演示文件和使用指南。演示文件通常以视频或图文形式展示项目的主要功能和操作流程,使用指南则详细说明了如何配置开发环境、部署项目以及常见问题的解决方法。 毕业设计参考:对于正在准备毕业设计的学生来说,这些资源包是绝佳的参考材料。每个项目不仅功能完善、结构清晰,还符合常见的毕业设计要求和标准。通过这些项目,学生可以学习到如何从零开始构建一个完整的Web系统,并积累丰富的项目经验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值