zoukankan      html  css  js  c++  java
  • 【76.83%】【codeforces 554A】Kyoya and Photobooks

    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard output
    Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled “a” to “z”, and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some “special edition” photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has?

    Please help Haruhi solve this problem.

    Input
    The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters.

    Output
    Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.

    Examples
    input
    a
    output
    51
    input
    hi
    output
    76
    Note
    In the first case, we can make ‘ab’,’ac’,…,’az’,’ba’,’ca’,…,’za’, and ‘aa’, producing a total of 51 distinct photo booklets.

    【题目链接】:http://codeforces.com/contest/554/problem/A

    【题解】

    枚举26个字母,再枚举这个字母要插入到哪里;
    判重的时候就直接用map搞。

    【完整代码】

    #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 pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    #define pri(x) printf("%d",x)
    #define prl(x) printf("%I64d",x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    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 double pi = acos(-1.0);
    
    string s;
    map <string,int> dic;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        LL ans = 0;
        cin >> s;
        int len = s.size();
        rep1(i,1,26)
        {
            char ke = i+'a'-1;
            rep1(j,0,len)
                {
                    string temp = s;
                    string st = "";
                    st+=ke;
                    temp.insert(j,st);
                    if (!dic[temp])
                    {
                        dic[temp] = 1;
                        ans++;
                    }
                }
        }
        cout << ans << endl;
        return 0;
    }
  • 相关阅读:
    ansible 2.2的源码编译安装
    存储过程-快速上手
    从库重启后报1062错误
    删除一张600万记录表的一个索引需要多长时间?
    mysql主从复制Error1205
    浅谈管理(三)如何管理资料库
    kettle之时间字段默认值为空或’0000-00-00’问题
    浅谈管理(二)项目管理
    乌龙之Ignoring query to other database问题
    一、安装
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626835.html
Copyright © 2011-2022 走看看