zoukankan      html  css  js  c++  java
  • 2017 Multi-University Training Contest

    弱校也不打多校,自己也可以咸鱼嘛。水一水,玩一玩

    Add More Zero

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 643    Accepted Submission(s): 449


    Problem Description
    There is a youngster known for amateur propositions concerning several mathematical hard problems.

    Nowadays, he is preparing a thought-provoking problem on a specific type of supercomputer which has ability to support calculations of integers between 0 and (2m1) (inclusive).

    As a young man born with ten fingers, he loves the powers of 10 so much, which results in his eccentricity that he always ranges integers he would like to use from 1 to 10k (inclusive).

    For the sake of processing, all integers he would use possibly in this interesting problem ought to be as computable as this supercomputer could.

    Given the positive integer m, your task is to determine maximum possible integer k that is suitable for the specific supercomputer.
     
    Input
    The input contains multiple test cases. Each test case in one line contains only one positive integer m, satisfying 1m105.
     
    Output
    For each test case, output "Case #xy" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
     
    Sample Input
    1 64
     
    Sample Output
    Case #1: 0 Case #2: 19
     
    Source
    拿数学公式推一推就好了,O(1)的,就是n*log10(2)的下取整
    #include <stdio.h>
    #include <math.h>
    int main() {
        int n,k=1;
        while(~scanf("%d",&n)){
            printf("Case #%d: %d
    ",k++,(int)(log10(2)*n));
        }
        return 0;
    }

    Balala Power!

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
    Total Submission(s): 3268    Accepted Submission(s): 738


    Problem Description

    Talented Mr.Tang has n strings consisting of only lower case characters. He wants to charge them with Balala Power (he could change each character ranged from a to z into each number ranged from 0 to 25, but each two different characters should not be changed into the same number) so that he could calculate the sum of these strings as integers in base 26 hilariously.

    Mr.Tang wants you to maximize the summation. Notice that no string in this problem could have leading zeros except for string "0". It is guaranteed that at least one character does not appear at the beginning of any string.

    The summation may be quite large, so you should output it in modulo 109+7.
     
    Input
    The input contains multiple test cases.

    For each test case, the first line contains one positive integers n, the number of strings. (1n100000)

    Each of the next n lines contains a string si consisting of only lower case letters. (1|si|100000,|si|106)
     
    Output
    For each test case, output "Case #xy" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
     
    Sample Input
    1
    a
    2
    aa
    bb
    3
    a
    ba
    abc
     
    Sample Output
    Case #1: 25
    Case #2: 1323
    Case #3: 18221
    这个图魔性了,强无敌,其实就是2进制的字符串,假如可以有前导零的话,算下贡献,贡献最大的数是25不就好了,但是不能有前导0的贪心就要后移,自己讨论下并不难,不过这个模拟也不短,等过些日子找个短的代码贴一下
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    const int mod = 1e9+7;
    const int N = 1e5+5;
    ll fac[N]= {1};
    int ma[27];
    bool lead[27];
    char str[N];
    void init() {
        for(int i=1; i < N; i++)
            fac[i]=fac[i-1]*26%mod;
    }
    struct node {
        int cnt[N];
        int id;
        bool operator < (const node &a) const {
            for(int i = N-1; i >= 0; i--) {
                if(cnt[i] > a.cnt[i]) return 1;
                else if(cnt[i] < a.cnt[i]) return 0;
                else ;
            }
        }
    } a[27];
    
    int main() {
        int n, k = 1;
        init();
        while(~scanf("%d", &n)) {
            memset(a, 0, sizeof(a));
            memset(ma, -1, sizeof(ma));
            memset(lead, 0, sizeof(lead));
            for(int i = 1; i <= n; i++) {
                scanf(" %s", str);
                int len = strlen(str);
                if(len != 1)
                    lead[str[0]-'a'] = 1;
                for(int i = 0; i < len; i++)
                    a[str[i]-'a'].cnt[len-i-1]++;
            }
            for(int i = 0; i < 26; i++) {
                for(int j = 0; j < N; j++) {
                    if(a[i].cnt[j] >= 26) {
                        a[i].cnt[j+1] += a[i].cnt[j]/26;
                        a[i].cnt[j] %= 26;
                    }
                }
                a[i].id = i;
            }
            sort(a, a+26);
            for(int i = 0; i < 26; i++)
                ma[a[i].id] = 26-i-1;
            for(int i = 0; i < 26; i++)
                if(lead[a[i].id] && ma[a[i].id] == 0) {
                    for(int j = 25; j >= 0; j--) {
                        if(!lead[a[j].id]) {
                            for(int k = 25; k >= j+1; k--)
                                ma[a[k].id] = ma[a[k-1].id];
                            ma[a[j].id] = 0;
                            break;
                        }
                    }
                    break;
                }
            ll ans = 0;
            for(int i = 0; i < 26; i++) {
                for(int j = 0; j < N; j++) {
                    ans = (ans+fac[j]*a[i].cnt[j]*ma[a[i].id]%mod)%mod;
                }
            }
            printf("Case #%d: %lld
    ", k++, ans);
        }
        return 0;
    }
    大佬您太强了,还请多多指教哎
  • 相关阅读:
    法正(44):鄙视
    法正(43):许攸
    法正(42):孔明
    法正(41):帮派
    法正(40):常委
    法正(39):寡妇
    法正(38):吴苋
    法正(37):刘备
    法正(29):暗弱
    法正(36):花瓶
  • 原文地址:https://www.cnblogs.com/BobHuang/p/7239401.html
Copyright © 2011-2022 走看看