Codeforces Round #295 (Div. 2)

本来应该去打DIV1的,但是,今天这场div1打的闹心,还是因为自己太弱了,没有达到div1的实力,刚刚吃完饭,,把div2的AB题补掉了,等明天把C题和D题做掉。。

A题:

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

解题思路:

这道题就是说,输入n个长度的字符串,然后,让你不论大小写,只要能在这n个字符中含有'a'-'z'的话,就说明这个字符串是个program。那么,我们就开始把输入的不论大小写都转换成小写,然后用字符串hash去统计就行了,'a'->1 'b'->2 'c'->3.。。。。。

代码:

# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>

using namespace std;

# define inf 999999999

char s[123];
int hash[27];

int main(void)
{
    int n;
    while ( cin>>n )
    {
        cin>>s;
        for ( int i = 0;i < n;i++ )
        {
            if ( s[i]>='A'&&s[i]<='Z' )
            {
                s[i]+=32;
            }
        }
        for ( int i = 0;i < n;i++ )
        {
           hash[s[i]-'a'+1]++;
        }
        int flag = 0;
        for ( int i = 1;i <= 26;i++ )
        {
            if ( hash[i] ==0 )
            {
               flag = 1;
                break;
            }
        }
        if ( flag )
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }



	return 0;
}



B题:

解题思路:

就是说现在有两种操作,一个操作是将n*2,一个操作是n-1,问经过最少的步骤使得m==n,一开始看到后,想用bfs去搜的,但是感觉贪心更简单一点,开始分三种情况,

当n>m的时候,我们就输出n-m。

当n==m的时候,我们就输出0

当n<m的时候,我们就利用贪心的思想倒过来想,怎么样把m变成n,当m为偶数的时候,直接m/2,操作数++,当m为奇数的时候,直接加1,直到n==m为止

代码:

# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>

using namespace std;

# define inf 999999999

int main(void) 
{
	int n,m;
	cin>>n>>m;
	if( n == m )
    {
		cout<<"0"<<endl;
	}
	else if( n > m )
    {
		cout<<n-m<<endl;
	}
	else
    {
		int ctr=0;
		while( n!=m )
        {
			if( m%2 == 0 && n < m )
			{
				m/=2;
				ctr++;
			}
			else
			{
				m+=1;
				ctr++;
			}
		}
		cout<<ctr<<endl;
	}

	return 0;
}
C题:
这题就是div1的A题了,当时想了好一会,没什么思路,还SB到在纸上花了个n*n阶的矩阵,让这个矩阵的行来观察t串的变化,让这个矩阵的列来观察s的变化,,果然被骗进了出题人的圈套中。根据题目的意思,就是说,t只能由AGCT构成,而S也是这样输入的,按照向左循环的规定,我们可以把一位一位的改变,直到s[i]和t[i]相等的个数最多,问的就是这样最多的有多少个。。。其实就是把S串中最大种类数目的个数拿出来玩n次方。

代码:

# include<cstdio>
# include<iostream>
# include<algorithm>
# include<cstring>
# include<string>
# include<cmath>
# include<queue>
# include<stack>
# include<set>
# include<map>

using namespace std;

# define inf 999999999
# define MAX 100000+7

typedef long long ll;
const ll MOD = 1000000000+7;

int ans[5];
char s[MAX];

ll my_pow( int k,int n )
{
    ll res = 1;
    for ( int i = 1;i <= n;i++ )
    {
        res = ( res*k )%MOD;
    }
    return res;
}


int main(void)
{
    int n;cin>>n;
    cin>>s;
    for ( int i = 0;i < n;i++ )
    {
        if ( s[i]=='A' )
            ans[0]++;
        else if ( s[i] == 'C' )
            ans[1]++;
        else if ( s[i] == 'G' )
            ans[2]++;
        else
            ans[3]++;
    }
    sort(ans,ans+4);

    if ( ans[0]==ans[3] )
        cout<<my_pow(4,n);
    else if ( ans[1]==ans[3] )
        cout<<my_pow(3,n);
    else if ( ans[2]==ans[3] )
        cout<<my_pow(2,n);
    else
        cout<<my_pow(1,n);

	return 0;
}

D题没看,

E题:

解题思路:

代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值