• CF930B Game with String(思维)


    一看数据范围,显然是平方算法,这题的题意是,总共有n种情况,每次给你首字母,你可以任意选择一个位置看更改后的字符是多少,问能猜测出答案的最大个数

    因为给定了首字母再猜,那么显然对于首字母不同的情况他们是不干扰的,因此对首字母分类讨论。

    那么对于每种情况,我们可以直接枚举选的位置,计算最大的答案取即可,最大的答案其实就是单独数出现最多的位置。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int,int> pll;
    const int N=2e5+10;
    const int mod=1e9+7;
    vector<int> num[N];
    int st[30];
    int main(){
        //ios::sync_with_stdio(false);
        string s;
        cin>>s;
        int n;
        n=(int)s.size();
        s=" "+s;
        int i,j;
        for(i=1;i<=n;i++){
            int x=s[i]-'a';
            num[x].push_back(i);
        }
        int cnt=0;
        for(int c=0;c<26;c++){
            int res=0;
            for(i=2;i<=n;i++){
                memset(st,0,sizeof st);
                for(auto x:num[c]){
                    int pos=(x+i-1);
                    if(pos>n)
                        pos-=n;
                    st[s[pos]-'a']++;
                }
                int tmp=0;
                for(j=0;j<26;j++){
                    if(st[j]==1)
                        tmp++;
                }
                res=max(res,tmp);
            }
            cnt+=res;
        }
        printf("%.8f
    ",1.0*cnt/n);
        return 0;
    }
    View Code
  • 相关阅读:
    什么是评审
    缺陷识别与缺陷跟踪
    白盒测试用例设计
    黑盒测试用例设计(二)
    黑盒测试用例设计技术
    Mysql基础
    JS函数
    SpringBoot整合JPA
    Python中的保留字
    操作系统的发展史
  • 原文地址:https://www.cnblogs.com/ctyakwf/p/14104798.html
Copyright © 2020-2023  润新知