zoukankan      html  css  js  c++  java
  • 【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
    ", ksm(cnt, n));
        //printf("
    %.2lf sec 
    ", (double)clock() / CLOCKS_PER_SEC);
        return 0;
    }
  • 相关阅读:
    什么是OOAD?什么是UML?
    Linux下Gvim 的基本操作-适合新手看
    关于mongodb ,redis,memcache之间见不乱理还乱的关系和作用
    phpcms常用标签
    请问如何更改dedecms“文件保存目录”的字符限制 ?
    如何通过刷百度指数来提高网站的权重
    HDU 1263(水果统计 **)
    HDU 1284(钱币兑换 背包/母函数)
    HDU 1028(数字拆分 分治)
    HDU 1036(平均速度 **)
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626486.html
Copyright © 2011-2022 走看看