Educational Codeforces Round 57 (Rated for Div. 2) (待更新)

A.Find Divisible

You are given a range of positive integers from l to r .

Find such a pair of integers (x,y) that l≤x,y≤r , x≠y and x divides y .

If there are multiple answers, print any of them.

You are also asked to answer T independent queries.

Input

The first line contains a single integer T (1≤T≤1000 ) — the number of queries.

Each of the next T lines contains two integers l and r (1≤l≤r≤998244353 ) — inclusive borders of the range.

It is guaranteed that testset only includes queries, which have at least one suitable pair.

Output

Print T lines, each line should contain the answer — two integers x and y such that l≤x,y≤r , x≠y and x divides y . The answer in the i -th line should correspond to the i -th query from the input.

If there are multiple answers, print any of them.

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#define inf 0x3fffffff
using namespace std;
int main()
{
    int t,x,y,m;
    cin>>t;
    while(t--)
    {
        cin>>x>>y;
        m=y/x;
        if(m>1)
            cout<<x<<" "<<2*x<<endl;
        else cout<<endl;
    }
    return 0;
}

B. Substring Removal

You are given a string ss of length nn consisting only of lowercase Latin letters.

A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.

Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).

It is guaranteed that there is at least two different characters in s.

Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.

Since the answer can be rather large (not very large though) print it modulo 998244353.

If you are Python programmer, consider using PyPy instead of Python when you submit your code.

Input

The first line of the input contains one integer n (2≤n≤2⋅105) — the length of the string s.

The second line of the input contains the string s of length n consisting only of lowercase Latin letters.

It is guaranteed that there is at least two different characters in ss.

Output

Print one integer — the number of ways modulo 998244353 to remove exactly one substring from ss in such way that all remaining characters are equal.

分析:字符串去掉子串(连续的)后各字符需要满足的要求

1.剩余字符数量可以为0。

2.剩余字符中不同种字符相互间数量相等。

3.剩余字符中存在不同的字符种类为0或1种。(比赛的时候把这条看漏的我哭唧唧)

因为去掉的子串是连续的,所以直接判断首尾的字符种类和数量就好了。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#define mod 998244353
using namespace std;
int main()
{
    int n;
    long long a=1,b=1;
    string s;
    cin>>n>>s;
    while(a)
    {
        if(s[a]!=s[0]) break;
        a++;
    }
    while(b)
    {
        if(s[n-b-1]!=s[n-1]) break;
        b++;
    }
//    cout<<a<<" "<<b<<endl;
//可以检验一哈字符数量是不是对的
    if(s[0]==s[n-1]) cout<<(a*b+a+b+1)%mod<<endl;
    else if(s[0]!=s[n-1]) cout<<(a+b+1)%mod<<endl;
    return 0;
}

 

 

C.Polygon for the Angle

You are given an angle angang.

The Jury asks You to find such regular n-gon (regular polygon with nn vertices) that it has three vertices a, b and c (they can be non-consecutive) with ∠abc=ang or report that there is no such n-gon.

If there are several answers, print the minimal one. It is guarantied that if answer exists then it doesn't exceed 998244353.

Input

The first line contains single integer T (1≤T≤180) — the number of queries.

Each of the next T lines contains one integer ang (1≤ang<180) — the angle measured in degrees.

Output

For each query print single integer nn (3≤n≤998244353) — minimal possible number of vertices in the regular n-gon or −1 if there is no such n.

分析:假设取n边形一点为顶点,另取两个相邻顶点组成n边形的单位角p=180/n。

当ang能被p整除的话,n满足题意。设正整数m使ang=m*p  ->  180/ang=n/m。

所以将180/ang约为最简分数,分子为满足题意的最小n,分母为ang角夹的边长数。

判断m<=n-2 输出分子,反之输出分子的两倍。

代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#define inf 0x3fffffff
using namespace std;
int main()
{
    int dg(int a,int b);
    int t,x,n,m;
    cin>>t;
    while(t--)
    {
        cin>>x;
        if(x>=180) cout<<-1<<endl;
        else
        {
            m=dg(180,x);
            n=180/m;
            m=x/m;
            if(m<n-1) cout<<n<<endl;
            else cout<<2*n<<endl;
        }
    }
    return 0;
}
int dg(int a,int b)
{
    int t;
    do
    {
        t=max(a,b);
        b=min(a,b);
        a=t;
        a=a%b;
    }
    while(a);
    return b;
}

D. Easy Problem

Vasya is preparing a contest, and now he has written a statement for an easy problem. The statement is a string of length n consisting of lowercase Latin latters. Vasya thinks that the statement can be considered hard if it contains a subsequence hard; otherwise the statement is easy. For example, hard, hzazrzd, haaaaard can be considered hard statements, while har, hart and drah are easy statements.

Vasya doesn't want the statement to be hard. He may remove some characters from the statement in order to make it easy. But, of course, some parts of the statement can be crucial to understanding. Initially the ambiguity of the statement is 0, and removing i-th character increases the ambiguity by ai (the index of each character is considered as it was in the original statement, so, for example, if you delete character r from hard, and then character d, the index of d is still 4 even though you delete it from the string had).

Vasya wants to calculate the minimum ambiguity of the statement, if he removes some characters (possibly zero) so that the statement is easy. Help him to do it!

Recall that subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.

Input

The first line contains one integer n (1≤n≤105) — the length of the statement.

The second line contains one string s of length n, consisting of lowercase Latin letters — the statement written by Vasya.

The third line contains n integers a1,a2,…,an(1≤ai≤998244353).

Output

Print minimum possible ambiguity of the statement after Vasya deletes some (possibly zero) characters so the resulting statement is easy.

分析:

if   h-0  a-1  r-2  d-3   字符串为s

e(j)   :   表示字符串中当前位置是 j 且是最后一个 j 的话一定满足题意的最小偏差。

​if(s[i]=='h')  e[0]+=a[i];
//因为h是hard的首位,所以前面的h都要去掉
if(s[i]=='a')  e[1]=min(e[0],e[1]+a[i]);
//判断是去掉前面所有h还是i-1时候的e[1]加上去掉当前位置的a偏差更小
if(s[i]=='r')  e[2]=min(e[1],e[2]+a[i]);
//同理,因为i-1时e[1]和e[0]比较过留下的e[1],所以直接和e[1]比较
if(s[i]=='d')  e[3]=min(e[2],e[3]+a[i]);
//同上

//因为d是hard的末尾,直接输出e[3]
cout<<e[3]<<endl;
​

代码:

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=1e5+5;
int main()
{
    int n,a[maxn],i;
    long long b=0,c=0,d=0,e=0;
    string s;
    cin>>n>>s;
    for(i=0;i<n;i++)
        cin>>a[i];
    i=-1;
    while(s[++i])
    {
        if(s[i]=='h') b+=a[i];
        else if(s[i]=='a') c=min(b,c+a[i]);
        else if(s[i]=='r') d=min(c,d+a[i]);
        else if(s[i]=='d') e=min(d,e+a[i]);
        else;
    }
    cout<<e<<endl;
    return 0;
}

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值