Codeforces Round #295 (Div. 2)(A,B,C)

A. Pangram
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.

You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

Input

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.

The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output

Output "YES", if the string is a pangram and "NO" otherwise.

Sample test(s)
input
12
toosmallword
output
NO
input
35
TheQuickBrownFoxJumpsOverTheLazyDog
output
YES

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
char str[110];
int has[110];
int main()
{
    int n,i;
    int flag;
        scanf("%d",&n);
        memset(has,0,sizeof(has));
        flag=1;
        scanf("%s",str);
        for(i=0;str[i]!='\0';i++)
            if(str[i]>='A'&&str[i]<='Z')
            has[str[i]-'A']=1;
           else if(str[i]>='a'&&str[i]<='z')
            has[str[i]-'a']=1;
            for(i=0;i<26;i++){
                if(has[i]==0){
                    printf("NO\n");
                    return 0;
                }
            }
        printf("YES\n");
}

B. Two Buttons
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.

Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?

Input

The first and the only line of the input contains two distinct integers n and m (1 ≤ n, m ≤ 104), separated by a space .

Output

Print a single number — the minimum number of times one needs to push the button required to get the number m out of number n.

Sample test(s)
input
4 6
output
2
input
10 1
output
9
Note

In the first example you need to push the blue button once, and then push the red button once.

In the second example, doubling the number is unnecessary, so we need to push the blue button nine times.


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
int n,m;
int vis[100010];
struct node
{
    int x;
    int ans;
}q[100010];
struct node t,f;
void bfs()
{
    int i;
    int s=0,e=0;
    memset(vis,0,sizeof(vis));
    t.x=n;
    vis[t.x]=1;
    t.ans=0;
    q[e++]=t;
    while(s<e){
        t=q[s++];
        if(t.x==m){
            printf("%d\n",t.ans);
            return ;
        }
        for(i=0;i<2;i++){
            if(i==0)
                f.x=t.x-1;
            else if(i==1)
                f.x=t.x*2;
            if(f.x>=0&&f.x<=100010&&!vis[f.x]){
                f.ans=t.ans+1;
                q[e++]=f;
                vis[f.x]=1;
            }
        }
    }
}
int main()
{
    while(~scanf("%d %d",&n,&m)){
        bfs();
    }
    return 0;
}

C. DNA Alignment
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences.

Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in which the respective symbols of s and t are the same. Function h(s, t) can be used to define the function of Vasya distance ρ(s, t):

where   is obtained from string  s, by applying left circular shift  i times. For example,
ρ("AGC", "CGT") = 
h("AGC", "CGT") + h("AGC", "GTC") + h("AGC", "TCG") + 
h("GCA", "CGT") + h("GCA", "GTC") + h("GCA", "TCG") + 
h("CAG", "CGT") + h("CAG", "GTC") + h("CAG", "TCG") = 
1 + 1 + 0 + 0 + 1 + 1 + 1 + 0 + 1 = 6

Vasya found a string s of length n on the Internet. Now he wants to count how many strings t there are such that the Vasya distance from the string s attains maximum possible value. Formally speaking, t must satisfy the equation: .

Vasya could not try all possible strings to find an answer, so he needs your help. As the answer may be very large, count the number of such strings modulo 109 + 7.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 105).

The second line of the input contains a single string of length n, consisting of characters "ACGT".

Output

Print a single number — the answer modulo 109 + 7.

Sample test(s)
input
1
C
output
1
input
2
AG
output
4
input
3
TTT
output
1
Note

Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one.

In the first sample, there is ρ("C", "C") = 1, for the remaining strings t of length 1 the value of ρ(s, t) is 0.

In the second sample, ρ("AG", "AG") = ρ("AG", "GA") = ρ("AG", "AA") = ρ("AG", "GG") = 4.

In the third sample, ρ("TTT", "TTT") = 27


#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
int n,A,G,C,T;
char str[100010];
int main()
{
    int i;
    scanf("%d",&n);
    scanf("%s",str);
    A=G=C=T=0;
    for(i=0;i<n;i++){
        if(str[i]=='A') A++;
        if(str[i]=='G') G++;
        if(str[i]=='C') C++;
        if(str[i]=='T') T++;
    }
    int maxx=max(max(A,G),max(C,T));
    int cnt=0;
    if(A==maxx) cnt++;
    if(G==maxx) cnt++;
    if(C==maxx) cnt++;
    if(T==maxx) cnt++;
    long long res=1;
    for(i=0;i<n;i++)
        res=(res*cnt)%mod;
    printf("%lld\n",res%mod);
    return 0;
}


已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 酷酷鲨 设计师:CSDN官方博客 返回首页
实付 9.90元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值