codeforces-757-【B、C思维】

来源:互联网 发布:怎么样信任软件 编辑:程序博客网 时间:2024/06/11 18:19

题目链接:点击打开链接

A. Gotta Catch Em' All!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbasaur.

Each day, he takes the front page of the newspaper. He cuts out the letters one at a time, from anywhere on the front page of the newspaper to form the word "Bulbasaur" (without quotes) and sticks it on his wall. Bash is very particular about case — the first letter of "Bulbasaur" must be upper case and the rest must be lower case. By doing this he thinks he has caught one Bulbasaur. He then repeats this step on the left over part of the newspaper. He keeps doing this until it is not possible to form the word "Bulbasaur" from the newspaper.

Given the text on the front page of the newspaper, can you tell how many Bulbasaurs he will catch today?

Note: uppercase and lowercase letters are considered different.

Input

Input contains a single line containing a string s (1  ≤  |s|  ≤  105) — the text on the front page of the newspaper without spaces and punctuation marks. |s| is the length of the string s.

The string s contains lowercase and uppercase English letters, i.e. .

Output

Output a single integer, the answer to the problem.

Examples
input
Bulbbasaur
output
1
input
F
output
0
input
aBddulbasaurrgndgbualdBdsagaurrgndbb
output
2
Note

In the first case, you could pick: Bulbbasaur.

In the second case, there is no way to pick even a single Bulbasaur.

In the third case, you can rearrange the string to BulbasaurBulbasauraddrgndgddgargndbb to get two words "Bulbasaur".


#include<cstdio>#include<cstring>#include<algorithm>using namespace std;char str[100010];int num[20];int main(){while(~scanf("%s",str)){memset(num,0,sizeof(num));int len=strlen(str);if(len<9){puts("0");continue;}for(int i=0;i<len;i++){if(str[i]=='B')num[1]++;if(str[i]=='u')num[2]++;if(str[i]=='l')num[3]++;if(str[i]=='b')num[4]++;if(str[i]=='a')num[5]++;if(str[i]=='s')num[6]++;if(str[i]=='r')num[7]++;}num[2]>>=1; num[5]>>=1;int ans=100010;for(int i=1;i<=7;i++)ans=min(ans,num[i]);printf("%d\n",ans);}return 0;}

题目链接:点击打开链接

B. Bash's Big Day
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.

But Zulu warns him that a group of k > 1 Pokemon with strengths {s1, s2, s3, ..., sk} tend to fight among each other ifgcd(s1, s2, s3, ..., sk) = 1 (see notes for gcd definition).

Bash, being smart, does not want his Pokemon to fight among each other. However, he also wants to maximize the number of Pokemon he takes from the lab. Can you help Bash find out the maximum number of Pokemon he can take?

Note: A Pokemon cannot fight with itself.

Input

The input consists of two lines.

The first line contains an integer n (1 ≤ n ≤ 105), the number of Pokemon in the lab.

The next line contains n space separated integers, where the i-th of them denotes si (1 ≤ si ≤ 105), the strength of the i-th Pokemon.

Output

Print single integer — the maximum number of Pokemons Bash can take.

Examples
input
32 3 4
output
2
input
52 3 4 6 7
output
3
Note

gcd (greatest common divisor) of positive integers set {a1, a2, ..., an} is the maximum positive integer that divides all the integers{a1, a2, ..., an}.

In the first sample, we can take Pokemons with strengths {2, 4} since gcd(2, 4) = 2.

In the second sample, we can take Pokemons with strengths {2, 4, 6}, and there is no larger group with gcd ≠ 1.


大意:统计最大公约数不为 1 的一组数的个数;特殊情况:原数列全为 1 ,那么结果为 1


#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int n;int vis[100010];int main(){while(~scanf("%d",&n)){memset(vis,0,sizeof(vis));while(n--){int x;scanf("%d",&x);vis[x]++;}int ans=1;for(int i=2;i<=100000;i++){int tp=0;for(int j=i;j<=100000;j+=i){tp+=vis[j];}ans=max(ans,tp);}printf("%d\n",ans);}return 0;}

题目链接:点击打开链接

C. Felicity is Coming!
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan region numbered from 1 to m. There is a special evolution camp set up in the fest which claims to evolve any Pokemon. The type of a Pokemon could change after evolving, subject to the constraint that if two Pokemon have the same type before evolving, they will have the same type after evolving. Also, if two Pokemon have different types before evolving, they will have different types after evolving. It is also possible that a Pokemon has the same type before and after evolving.

Formally, an evolution plan is a permutation f of {1, 2, ..., m}, such that f(x) = y means that a Pokemon of type x evolves into a Pokemon of type y.

The gym leaders are intrigued by the special evolution camp and all of them plan to evolve their Pokemons. The protocol of the mountain states that in each gym, for every type of Pokemon, the number of Pokemon of that type before evolving any Pokemon should be equal the number of Pokemon of that type after evolving all the Pokemons according to the evolution plan. They now want to find out how many distinct evolution plans exist which satisfy the protocol.

Two evolution plans f1 and f2 are distinct, if they have at least one Pokemon type evolving into a different Pokemon type in the two plans, i. e. there exists an i such that f1(i) ≠ f2(i).

Your task is to find how many distinct evolution plans are possible such that if all Pokemon in all the gyms are evolved, the number of Pokemon of each type in each of the gyms remains the same. As the answer can be large, output it modulo 109 + 7.

Input

The first line contains two integers n and m (1 ≤ n ≤ 1051 ≤ m ≤ 106) — the number of gyms and the number of Pokemon types.

The next n lines contain the description of Pokemons in the gyms. The i-th of these lines begins with the integer gi (1 ≤ gi ≤ 105) — the number of Pokemon in the i-th gym. After that gi integers follow, denoting types of the Pokemons in the i-th gym. Each of these integers is between 1 and m.

The total number of Pokemons (the sum of all gi) does not exceed 5·105.

Output

Output the number of valid evolution plans modulo 109 + 7.

Examples
input
2 32 1 22 2 3
output
1
input
1 33 1 2 3
output
6
input
2 42 1 23 2 3 4
output
2
input
2 23 2 2 12 1 2
output
1
input
3 72 1 22 3 43 5 6 7
output
24
Note

In the first case, the only possible evolution plan is:

In the second case, any permutation of (1,  2,  3) is valid.

In the third case, there are two possible plans:

In the fourth case, the only possible evolution plan is:


大意:给出 n 组数,每组 gi 个数,每个数属于1~m。每个数可以变化(若规定某一 gi 中的某一数 a 变为 b,那么剩余所有的 gi 中的 a 也变为 b),但变化前相同的数变化后依然相同(即 gi 里边元素的排列顺序发生了变化,元素的种类不变,同一种元素的个数不变),变化前不同的数变化后依然不同,且可能不变。但经过变化后每组的每种数的个数不会变化,求变化的总方案数。


思路:只有在每个 gym 上出现次数都相同的数 x,y 可以存在 f [x] = y 或 f [y] = x。那么最终在每个 gym 出现次数都相同的数会成为一个个集合。设这些集合的大小为 x1,x2,x3 ..... 显然对于一个大小为 x 的集合,方案数为 x!,即为他们的全排列数。那么 ans = x1! * x2! * x3! ..... xk!

#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<map>#define LL long longusing namespace std;const LL MOD=1e9+7;int n,m;vector<int> G[1000010];map< vector<int>,int > M;map< vector<int>,int > ::iterator it;LL solve(int x){LL ans=1;for(int i=2;i<=x;i++){ans=ans*i%MOD;}return ans;}int main(){while(~scanf("%d%d",&n,&m)){for(int i=0;i<1000010;i++)G[i].clear();M.clear();for(int i=1;i<=n;i++){int x;scanf("%d",&x);while(x--){int y;scanf("%d",&y);G[y].push_back(i);}}for(int i=1;i<=m;i++)M[G[i]]++;LL cnt=1,ans=1;for(it=M.begin();it!=M.end();it++){ans=ans*solve(it->second)%MOD;}printf("%I64d\n",ans);}return 0;}/**************#include<cstdio>#include<algorithm>#include<cstring>#include<vector>#include<iostream>#define LL long longusing namespace std;const LL MOD=1e9+7;int n,m;vector<int> G[1000010];int main(){while(~scanf("%d%d",&n,&m)){for(int i=0;i<1000010;i++)G[i].clear();for(int i=1;i<=n;i++){int x;scanf("%d",&x);while(x--){int y;scanf("%d",&y);G[y].push_back(i);}}sort(G+1,G+m+1); // 之前压入的都是有序的,这里只排一级地址 LL cnt=1,ans=1;for(int i=2;i<=m;i++){if(G[i]==G[i-1]){cnt++;ans=ans*cnt%MOD;}elsecnt=1;}printf("%I64d\n",ans);}return 0;}**************/



0 0
原创粉丝点击