• codeforces 1360F 思维


    思维        

    题意:q个测试样例。n个字符串,找到一个字符串满足该字符串与所有的字符串最多只差一个字符。

    思路:n,m范围很小,遍历n个字符串,找出他们的衍生字符串,即每位都变化26次。出现了n次的就是答案。

    #include <iostream>
    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <map>
    #include <iomanip>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <set>
    #include <vector> 
    // #include <bits/stdc++.h>
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define sp ' '
    #define endl '
    '
    #define inf  0x3f3f3f3f;
    #define FOR(i,a,b) for( int i = a;i <= b;++i)
    #define bug cout<<"--------------"<<endl
    #define P pair<int, int>
    #define fi first
    #define se second
    #define pb(x) push_back(x)
    #define mp(a,b) make_pair(a,b)
    #define ms(v,x) memset(v,x,sizeof(v))
    #define rep(i,a,b) for(int i=a;i<=b;i++)
    #define repd(i,a,b) for(int i=a;i>=b;i--)
    #define sca3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
    #define sca2(a,b) scanf("%d %d",&(a),&(b))
    #define sca(a) scanf("%d",&(a));
    #define sca3ll(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
    #define sca2ll(a,b) scanf("%lld %lld",&(a),&(b))
    #define scall(a) scanf("%lld",&(a));
    
    
    using namespace std;
    typedef long long ll;
    ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
    ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
    ll powmod(ll a, ll b, ll mod){ll sum = 1;while (b) {if (b & 1) {sum = (sum * a) % mod;b--;}b /= 2;a = a * a % mod;}return sum;}
    
    const double Pi = acos(-1.0);
    const double epsilon = Pi/180.0;
    const int maxn = 2e5+10;
    int main()
    {
        //freopen("input.txt", "r", stdin);
        int q;
        scanf("%d",&q);
        //set<pair<string,int> >st;
        
        
        while(q--)
        {
            int n,m;
            cin>>n>>m;
            map<string,int>mp;
            rep(i,1,n)
            {
                string s;
                cin>>s;
                set<string>st;
                rep(j,0,m-1)
                {
                    char c = s[j];
                    rep(k,97,122)
                    {
                        s[j] = char(k);
                        st.insert(s);
                    }
                    s[j] = c;
                }
                for(auto i : st){
                    mp[i]++;
                }
            }
            string ans;
            int flag = 0;
            for(auto i : mp){
                int t = i.se;
                if(t == n){
                    flag = 1;
                    ans = i.fi;
                }
    
    /*            if(st.count(i) == n){
                    ans = i;
                    flag = 1;
                    break;
                }*/
            }
            if(flag == 1){
                cout<<ans<<endl;
            }
            else cout<<-1<<endl;
        }
    }
  • 相关阅读:
    随机-byte编码
    dataframe骚操作,待续
    oracle中的rowid
    java提高篇-----理解java的三大特性之继承
    staruml使用教程
    黑马程序员:HTML习题1
    Cocos2d-x-->CCSprite 动画
    地址栏传参中文乱码详解
    Qt学习第二天
    Lync 2010 升级到2013 之部署2013前端服务器!
  • 原文地址:https://www.cnblogs.com/jrfr/p/12990246.html
Copyright © 2020-2023  润新知