URAL 2024 Adventure Time 思维题、Interesting
2016-07-30 23:41
204 查看
A - Adventure Time
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice URAL
2024
Description
‘Here’s for you!’ shouted Finn fighting the Shadow Guardians. ‘Jake! Collect the Darkness Rocks and let’s run from here!’
Jake would have been glad to finish as soon as possible, because it was wet and sad in the Dangerous Cave, but it was not so easy to
gather Rocks. So he called BMO and asked him to help with choosing an optimal set of Rocks. Jake told BMO that there were n Rocks
in the Cave, and they were numbered with different integers from 1 to n. Each Rock was painted one of 26 colors. Jake also reminded BMO of Princess Bubblegum’s warning: there should be at most k Rocks of
pairwise different colors among the Rocks taken from
the Cave. Only a set of Rocks with this property is safe. If one takes an unsafe set of Rocks from the Cave, Cosmic Evil will be awakened! Of course, Jake doesn’t want to awaken the Evil, but he wants to take
as many Darkness Rocks from the Cave as possible.
Help BMO to find the size of the largest safe set of Rocks and the number of different safe sets of this size. Two sets of Rocks are different if one of them contains a Rock with a number that is not contained in the other set.
Input
The first line contains n lowercase English letters (1 ≤ n ≤ 10 5); each letter denotes the color of a Rock. In the second line you are
given the integer k (1 ≤ k ≤ 26).
Output
Output two integers separated with a space: the size of the largest safe set of Darkness Rocks and the number of different safe sets of
this size.
Sample Input
Source
UESTC 2016 Summer Training #17 Div.2
URAL 2024
My Solution
统计每个字母出现的次数, 然后从大到小排序
最大的k的总个数就是 he size of the largest safe set of Darkness Rocks
然后1)如果color[k-1] != 0, 则 统计这k个里的 color[i] == color[k-1] 记为cnt1, 并统计所有的里面的color[i] == color[k-1] 记为 cnt2, 然后C[cnt2][cnt1]就是the number of different safe sets of this size.了
2)否则直接就是答案
复杂度 O(n)
Thank you!
------from ProLights
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
Submit Status Practice URAL
2024
Description
‘Here’s for you!’ shouted Finn fighting the Shadow Guardians. ‘Jake! Collect the Darkness Rocks and let’s run from here!’
Jake would have been glad to finish as soon as possible, because it was wet and sad in the Dangerous Cave, but it was not so easy to
gather Rocks. So he called BMO and asked him to help with choosing an optimal set of Rocks. Jake told BMO that there were n Rocks
in the Cave, and they were numbered with different integers from 1 to n. Each Rock was painted one of 26 colors. Jake also reminded BMO of Princess Bubblegum’s warning: there should be at most k Rocks of
pairwise different colors among the Rocks taken from
the Cave. Only a set of Rocks with this property is safe. If one takes an unsafe set of Rocks from the Cave, Cosmic Evil will be awakened! Of course, Jake doesn’t want to awaken the Evil, but he wants to take
as many Darkness Rocks from the Cave as possible.
Help BMO to find the size of the largest safe set of Rocks and the number of different safe sets of this size. Two sets of Rocks are different if one of them contains a Rock with a number that is not contained in the other set.
Input
The first line contains n lowercase English letters (1 ≤ n ≤ 10 5); each letter denotes the color of a Rock. In the second line you are
given the integer k (1 ≤ k ≤ 26).
Output
Output two integers separated with a space: the size of the largest safe set of Darkness Rocks and the number of different safe sets of
this size.
Sample Input
input | output |
---|---|
abcde 1 | 1 5 |
ababac 2 | 5 1 |
UESTC 2016 Summer Training #17 Div.2
URAL 2024
My Solution
统计每个字母出现的次数, 然后从大到小排序
最大的k的总个数就是 he size of the largest safe set of Darkness Rocks
然后1)如果color[k-1] != 0, 则 统计这k个里的 color[i] == color[k-1] 记为cnt1, 并统计所有的里面的color[i] == color[k-1] 记为 cnt2, 然后C[cnt2][cnt1]就是the number of different safe sets of this size.了
2)否则直接就是答案
复杂度 O(n)
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; const int maxn = 1e5 + 8; char val[maxn]; LL color[26], C[maxn][30]; inline bool cmp(LL a, LL b) { return a > b; } int main() { memset(C, 0, sizeof C); for(int i = 0; i <= 26; i++){ C[i][0] = 1; for(int j = 1; j <= i; j++){ C[i][j] = C[i-1][j-1] + C[i-1][j]; } } #ifdef LOCAL freopen("a.txt", "r", stdin); //freopen("b.txt", "w", stdout); int T = 3; while(T--){ #endif // LOCAL memset(color, 0, sizeof color); LL sz = 0, num = 1, k; scanf("%s", val); scanf("%I64d", &k); int len = strlen(val); for(int i = 0; i < len; i++) color[val[i] - 'a']++; sort(color, color + 26, cmp); int cnt1 = 0, cnt2 = 0; for(int i = 0; i < k; i++){ sz += color[i]; if(color[k-1] !=0 && color[i] == color[k-1]) cnt1++; } for(int i = 0; i < 26; i++){ if(color[k-1] != 0 && color[i] == color[k-1]) cnt2++; } if(color[k-1] != 0){ num = C[cnt2][cnt1]; } printf("%I64d %I64d", sz, num); #ifdef LOCAL printf("\n"); } #endif // LOCAL return 0; }
Thank you!
------from ProLights
相关文章推荐
- PROBLEM_A: URAL 2024 Adventure Time
- URAL 2021. Scarily interesting!(*贪心? set整理)
- G - Caterpillars URAL - 2064 ----思维题
- 思维题 URAL 1409 Two Gangsters
- Ural 2003: Simple Magic(数论&思维)
- ural 2072 - Kirill the Gardener 3 详细题解 (思维+dp)
- Gym 100541 B. Sum 分块的技巧、思维题、Interesting
- Ural 2067 Friends and Berries 【思维】
- Ural2004: Scientists from Spilkovo(德布鲁因序列&思维)
- HDU 6016 Count the Sheep(思维题)(Interesting)
- C - Different Sums URAL - 2065 ----思维题
- 思维题+set URAL 1718 Rejudge
- ural 1820. Ural Steaks -思维题
- ural 1542 字典树(思维)
- Codeforces 769D k-Interesting Pairs Of Integers【思维+预处理+暴力枚举】
- URAL 1409 Two Gangsters (开放思维)
- G - Hard Rock URAL - 2069 ----思维题
- Scarily interesting! (URAL - 2021)
- URAL 1409 Bishops 思维问题
- Adventure Time URAL - 2024---多坑点的排列组合