A Add More Zero
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 (2m−1) (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.
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 (2m−1) (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 1≤m≤105.
Output
For each test case, output "Case #x: y" 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
求满足2^m >= 10^k的最大k值,所以k = m*log10(2)。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #include <cmath> 5 #define ll long long 6 using namespace std; 7 8 int main() { 9 int m, kk = 1; 10 while(scanf("%d",&m)!=EOF) { 11 ll k = m*log10(2); 12 printf("Case #%d: %lld ",kk++,k); 13 } 14 return 0; 15 }
B Balala Power!
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. (1≤n≤100000)
Each of the next n lines contains a string si consisting of only lower case letters. (1≤|si|≤100000,∑|si|≤106)
For each test case, the first line contains one positive integers n, the number of strings. (1≤n≤100000)
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 #x: y" 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
每个字母都可以当成0-25之中的某个数字,但两个字母不能重复。0不能为前导(这个尤其注意)。
#include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #define ll long long using namespace std; const int MAX = 1e5+5; const int mod = 1e9+7; ll fac[MAX] = {1}; int Hash[27]; bool lead[27]; char str[MAX]; void init() { for(int i = 1; i < MAX; i ++) { fac[i] = fac[i-1]*26%mod; } } struct node { int cnt[MAX]; int id; bool operator < (const node &a) const { for(int i = MAX-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, ca = 1; init(); while(scanf("%d",&n)!=EOF) { memset(a, 0, sizeof(a)); memset(Hash, -1, sizeof(Hash)); 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 ++) { //满26进1 for(int j = 0; j < MAX; 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 ++) Hash[a[i].id] = 26-i-1; for(int i = 0; i < 26; i ++) { //查找前导是否有为0的,有的话就换掉 if(lead[a[i].id] && Hash[a[i].id] == 0) { for(int j = 25; j >= 0; j --) { if(!lead[a[j].id]) { for(int k = 25; k >= j+1; k --) { Hash[a[k].id] = Hash[a[k-1].id]; } Hash[a[j].id] = 0; break; } } break; } } ll ans = 0; for(int i = 0; i < 26; i ++) { for(int j = 0; j < MAX; j ++) { ans = (ans + fac[j]*a[i].cnt[j]*Hash[a[i].id]%mod)%mod; } } printf("Case #%d: %lld ",ca++,ans); } return 0; }
K KazaQ's Socks
Problem Description
KazaQ wears socks everyday.
At the beginning, he has n pairs of socks numbered from 1 to n in his closets.
Every morning, he puts on a pair of socks which has the smallest number in the closets.
Every evening, he puts this pair of socks in the basket. If there are n−1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.
KazaQ would like to know which pair of socks he should wear on the k-th day.
At the beginning, he has n pairs of socks numbered from 1 to n in his closets.
Every morning, he puts on a pair of socks which has the smallest number in the closets.
Every evening, he puts this pair of socks in the basket. If there are n−1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.
KazaQ would like to know which pair of socks he should wear on the k-th day.
Input
The input consists of multiple test cases. (about 2000)
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
3 7
3 6
4 9
Sample Output
Case #1: 3
Case #2: 1
Case #3: 2
水题,判断一下。
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 #define ll long long 5 using namespace std; 6 7 int main() { 8 int ca = 1; 9 ll n, k; 10 while(scanf("%lld%lld",&n,&k)!=EOF) { 11 if(k <= n){ 12 printf("Case #%d: %lld ",ca++,k); 13 }else { 14 int a = (k-n)/(n-1); 15 if(a&1){ 16 int w = (k-n)%(n-1); 17 if(w)printf("Case #%d: %d ",ca++,w); 18 else printf("Case #%d: %lld ",ca++,n-1LL); 19 }else{ 20 int w = (k-n)%(n-1); 21 if(w)printf("Case #%d: %d ",ca++,w); 22 else printf("Case #%d: %lld ",ca++,n); 23 } 24 } 25 } 26 return 0; 27 }