【codeforces 520C】DNA Alignment

【题目链接】:http://codeforces.com/contest/520/problem/C

【题意】

给你一个函数;
它的作用是评估两个字符串的相似程度;
评估的时候;
保持一个字符串不动,另外一个字符串比较n次->n为字符串的长度
但比较的n次是这样的:另外一个字符串比完一次之后会往左滑动一格,第一个字符串会跑到最后一个位置;
然后第一个字符串也按照上面的规则往左移动一个格子;然后再比较n次。
每次比较得到的相同的字符的个数的和就是这个函数的输出.

【题解】

贪心。
记录输入的字符串出现次数最多的字符;
最后结果全是那个字符是最优解;
但可能有多个出现次数最多的字符->设组成集合S;
则每个位置选那个集合里面任意一个元素都可以;
所以就是S的大小x它的n次方;

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define ref(x) scanf("%lf",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const char t[5] = { '8','A','C','G','T' };
const double pi = acos(-1.0);
const int N = 1e5+100;
const LL MOD = 1e9 + 7;

int n;
char s[N];
map<char, int> dic;

LL ksm(LL x, LL y)
{
    if (y == 1)
        return x;
    LL temp = ksm(x, y >> 1);
    temp = (temp*temp)%MOD;
    if (y & 1) temp = (temp*x)%MOD;
    return temp;
}

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    rei(n);
    scanf("%s", s + 1);
    rep1(i, 1, n)
        dic[s[i]]++;
    int ma = 0, cnt = 0;
    rep1(i, 1, 4)
        if (dic[t[i]] > ma)
        {
            ma = dic[t[i]];
            cnt = 1;
        }
        else
            if (dic[t[i]] == ma)
                cnt++;
    printf("%lld\n", ksm(cnt, n));
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626486.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值