2017 Multi-University Training Contest - Team 1
2017-08-02 10:47
399 查看
题目链接:http://acm.hdu.edu.cn/contests/contest_show.php?cid=759
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2245 Accepted Submission(s): 1053
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 (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 1to 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
Statistic | Submit | Clarifications | Back
解析:等式两边同时取模,转换下就可以了
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000009;
const int mod = 1e9+7ll;
int main()
{
int m, cnt = 0;
while(~scanf("%d", &m))
{
int ans = m * log10(2.0);
printf("Case #%d: %d\n", ++cnt, ans);
}
return 0;
}
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 4809 Accepted Submission(s): 387
Problem Description
![](http://acm.hdu.edu.cn/data/images/C642-1002-1.jpg)
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)
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
Statistic | Submit | Clarifications | Back
解析:每个字符对答案的贡献都可以看作一个 26 进制的数字,问题相当于要给这些贡献加一个 0 到 25 的权重使得答案最大。最大的数匹配 25,次大的数匹配 24,依次类推。排序后这样依次贪心即可,唯一注意的是不能出现前导 0。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000009;
const LL mod = 1e9+7ll;
//typedef pair<int, char> P;
int a[100100][33];
char s[100100];
int x[33], vis[33], m;
bool cmp(int p, int q)
{
for(int j = m-1; j >= 0; j--)
{
if(a[j][p] < a[j][q]) return false;
else if(a[j][p] > a[j][q]) return true;
}
return true;
}
void Sort()
{
for(int i = 0; i < 26; i++) x[i] = i;
for(int i = 0; i < 25; i++)
{
for(int j = i + 1; j < 26; j++)
{
if(cmp(x[i], x[j]))
{
int t = x[i];
x[i] = x[j];
x[j] = t;
}
}
}
}
int main()
{
int n, cnt = 0;
while(~scanf("%d", &n))
{
m = 0;
memset(vis, 0, sizeof(vis));
memset(a, 0, sizeof(a));
for(int i = 1; i <= n; i++)
{
scanf(" %s", s);
int len = strlen(s);
m = max(m, len);
int k = 0;
vis[s[0]-'a'] = 1;
for(int j = len - 1; j >= 0; j--){a[k][s[j] - 'a']++;k++;}
}
int t[33];
memset(t, 0, sizeof(t));
for(int i = 0; i < m-1; i++)
{
for(int j = 0; j < 26; j++)
{
int cur = (t[j] + a[i][j]);
a[i][j] = cur % 26;
t[j] = cur / 26;
}
}
for(int i = 0; i < 26; i++) a[m-1][i] += t[i];
Sort();
LL ans = 0ll;
int k = 1, p;
for(int i = 0; i < 26; i++)
{
int j = x[i];
if(vis[j] == 0)
{
p = j;
break;
}
}
for(int i = 0; i < 26; i++)
{
int cur = x[i];
if(p == cur) continue;
LL num = 0ll;
for(int j = m - 1; j >= 0; j--) num = (num * 26 + k * a[j][cur]) % mod;
ans = (ans + num) % mod;
k++;
}
printf("Case #%d: %lld\n", ++cnt, ((ans%mod)+mod)%mod);
}
return 0;
}
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2375 Accepted Submission(s): 1074
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.
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).
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
Statistic | Submit | Clarifications | Back
解析:找下规律即可,比如n = 4, 123 412312 412312 412312 ,注意特判n=2
代码:
Add More Zero
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2245 Accepted Submission(s): 1053
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 (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 1to 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
Statistic | Submit | Clarifications | Back
解析:等式两边同时取模,转换下就可以了
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000009;
const int mod = 1e9+7ll;
int main()
{
int m, cnt = 0;
while(~scanf("%d", &m))
{
int ans = m * log10(2.0);
printf("Case #%d: %d\n", ++cnt, ans);
}
return 0;
}
Balala Power!
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 4809 Accepted Submission(s): 387
Problem Description
![](http://acm.hdu.edu.cn/data/images/C642-1002-1.jpg)
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)
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
Statistic | Submit | Clarifications | Back
解析:每个字符对答案的贡献都可以看作一个 26 进制的数字,问题相当于要给这些贡献加一个 0 到 25 的权重使得答案最大。最大的数匹配 25,次大的数匹配 24,依次类推。排序后这样依次贪心即可,唯一注意的是不能出现前导 0。
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1000009;
const LL mod = 1e9+7ll;
//typedef pair<int, char> P;
int a[100100][33];
char s[100100];
int x[33], vis[33], m;
bool cmp(int p, int q)
{
for(int j = m-1; j >= 0; j--)
{
if(a[j][p] < a[j][q]) return false;
else if(a[j][p] > a[j][q]) return true;
}
return true;
}
void Sort()
{
for(int i = 0; i < 26; i++) x[i] = i;
for(int i = 0; i < 25; i++)
{
for(int j = i + 1; j < 26; j++)
{
if(cmp(x[i], x[j]))
{
int t = x[i];
x[i] = x[j];
x[j] = t;
}
}
}
}
int main()
{
int n, cnt = 0;
while(~scanf("%d", &n))
{
m = 0;
memset(vis, 0, sizeof(vis));
memset(a, 0, sizeof(a));
for(int i = 1; i <= n; i++)
{
scanf(" %s", s);
int len = strlen(s);
m = max(m, len);
int k = 0;
vis[s[0]-'a'] = 1;
for(int j = len - 1; j >= 0; j--){a[k][s[j] - 'a']++;k++;}
}
int t[33];
memset(t, 0, sizeof(t));
for(int i = 0; i < m-1; i++)
{
for(int j = 0; j < 26; j++)
{
int cur = (t[j] + a[i][j]);
a[i][j] = cur % 26;
t[j] = cur / 26;
}
}
for(int i = 0; i < 26; i++) a[m-1][i] += t[i];
Sort();
LL ans = 0ll;
int k = 1, p;
for(int i = 0; i < 26; i++)
{
int j = x[i];
if(vis[j] == 0)
{
p = j;
break;
}
}
for(int i = 0; i < 26; i++)
{
int cur = x[i];
if(p == cur) continue;
LL num = 0ll;
for(int j = m - 1; j >= 0; j--) num = (num * 26 + k * a[j][cur]) % mod;
ans = (ans + num) % mod;
k++;
}
printf("Case #%d: %lld\n", ++cnt, ((ans%mod)+mod)%mod);
}
return 0;
}
KazaQ's Socks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2375 Accepted Submission(s): 1074
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.
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).
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
Statistic | Submit | Clarifications | Back
解析:找下规律即可,比如n = 4, 123 412312 412312 412312 ,注意特判n=2
代码:
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 1000009; const int mod = 1e9+7ll; LL solve(LL n, LL k) { if(n == 2&&k&1) return 1; else if(n == 2) return 2; if(k <= n - 1) return k; k -= n - 1; k %= 2*(n-1); if(k == 0) return n - 2; if(k <= n - 1) { if(k == 1) return n; return k - 1; } k -= n - 1; if(k == 1) return n-1; return k - 1; } int main() { LL n, k; int cnt = 0; while(~scanf("%lld%lld", &n, &k)) { printf("Case #%d: ", ++cnt); cout << solve(n, k) << endl; } return 0; }
相关文章推荐
- 2017 Multi-University Training Contest - Team 1 1011 KazaQ's Socks
- 2017 Multi-University Training Contest - Team 1 Add More Zero
- hdu 6034 Balala Power!(贪心)( 2017 Multi-University Training Contest - Team 1 )(无耻之sort)
- 2017 Multi-University Training Contest - Team 2 1001 Is Derek lying?
- hdu 6047 Maximum Sequence(2017 Multi-University Training Contest - Team 2)
- hdu 6045 Is Derek lying?(2017 Multi-University Training Contest - Team 2)
- 2017 Multi-University Training Contest - Team 1 :Function
- hdu 6055 Regular polygon(判断正方形)(2017 Multi-University Training Contest - Team 2)
- HDU 6050 Funny Function(构造矩阵+推公式)——2017 Multi-University Training Contest - Team 2
- 【2017 Multi-University Training Contest - Team 10 】Monkeys
- 【2017 Multi-University Training Contest - Team 9】Numbers
- 【2017 Multi-University Training Contest - Team 3】Kanade's sum
- 2017 Multi-University Training Contest - Team 3(补题系列)
- hdu 6058 Kanade's sum(链表)(2017 Multi-University Training Contest - Team 3 )
- 2017 Multi-University Training Contest - Team 3 Kanade's sum
- 2017 Multi-University Training Contest - Team 3 1003 Kanade's sum
- hdu 6069 Counting Divisors(约数个数)(2017 Multi-University Training Contest - Team 4 )
- hdu 6071 Lazy Running(优先队列+dijkstra)(2017 Multi-University Training Contest - Team 4)
- 2017 Multi-University Training Contest - Team 4
- hdu 6073 Matching In Multiplication(2017 Multi-University Training Contest - Team 4 )