• 【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;
    }
  • 相关阅读:
    【原创】深入理解c++的右值引用
    【原创】c++拷贝初始化和直接初始化的底层区别
    【原创】Github团队协作之Pull请求
    【原创】基于多线程的银行家算法设计
    【原创】Git删除暂存区或版本库中的文件
    【笔记】程序员的思维修炼3
    【笔记】德雷福斯模型
    【原创】GC/垃圾回收简介
    数据库——JavaWEB数据库连接
    多线程
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626835.html
Copyright © 2020-2023  润新知