码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces #295(Div 2) A Pangram、B Two Buttons、C DNA Alignment

时间:2015-03-09 12:56:52      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:

A

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
int A[50];
int main()
{
	int n; string s;
	cin>>n;
	cin>>s;
	memset(A,0,sizeof(A));
	for(int i=0;i<n;i++)
	{
		int c;
		if(s[i] >= 'A' && s[i] <= 'Z')
			c = s[i] - 'A';
		else if(s[i] >= 'a' && s[i] <='z')  c = s[i] - 'a';
		A[c] = 1;
	}
	int flag = true;
	for(int i=0;i<26;i++) if(A[i] == 0)
	{
		flag = false;
		break;
	}
	if(flag) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

B

/* ***********************************************
Author        :mogu
Created Time  :2015/3/9 10:17:30
File Name     :
************************************************ */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main()
{
	int N, M;
	cin>>N>>M;
	int r = 0;
	while(M > N)
	{
		if(M & 1) M++,r++;
		M /= 2;
		r++;
	}
	cout<<r + N - M<<endl;	
    return 0;
}
C题
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <cmath>
#define LL long long
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 100000 + 10;
int C[MAXN];
LL pow_mod(LL a, LL b)
{
    LL res = 1;
    while(b)
    {
        if(b & 1) res = res * a % mod;
        a = a * a % mod;
        b>>=1;
    }
    return res;
}
int main()
{
    int n; string s;
    while(cin>>n)
    {
        cin>>s;
        memset(C, 0, sizeof(C));
        int len = s.length();
        for(int i=0;i<len;i++)
        {
            if(s[i] == 'A') C[0]++;
            else if(s[i] == 'G') C[1]++;
            else if(s[i] == 'C') C[2]++;
            else C[3]++;
        }
        sort(C,C+4,greater<int>());
        int x = 1;
        for(int i=1;i<=3;i++)
        {
            if(C[i] == C[0]) x++;
            else break;
        }
        int ans = pow_mod(x, n);
        cout<<ans<<endl;
    }
    return 0;
}




Codeforces #295(Div 2) A Pangram、B Two Buttons、C DNA Alignment

标签:

原文地址:http://blog.csdn.net/moguxiaozhe/article/details/44152491

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!