2017 Multi-University Training Contest - Team 1

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

 

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\n",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\n", k++, ans);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/BobHuang/p/7239401.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值