Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B
来源:互联网 发布:mac打印6寸相纸 编辑:程序博客网 时间:2024/05/22 05:13
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”.
题意:问字符串能能组成多少个”Bulbasaur“。
题解:简单题。
代码:
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <map>#define ll long longusing namespace std;string str;int main(){ cin>>str; int B,l,b,a,s,u,r; b=B=l=a=s=u=r=0; int len=str.length(); for(int i=0;i<len;i++) { if(str[i]=='b') b++; if(str[i]=='B') B++; if(str[i]=='u') u++; if(str[i]=='l') l++; if(str[i]=='a') a++; if(str[i]=='s') s++; if(str[i]=='r') r++; } int mx=10000000; mx=min(mx,min(b,B)); mx=min(mx,min(u/2,l)); mx=min(mx,min(a/2,s)); mx=min(mx,r); cout<<mx<<endl;}
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 if gcd(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
3
2 3 4
Output
2
Input
5
2 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.
题意:求出最长子序列使得gcd(a1。。ax)!=1
题解:先处理出每个因子对答案的贡献。然后o(n)求出最大值即可。
代码:
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string.h>#include <algorithm>#include <math.h>#include <map>#define ll long longusing namespace std;int a[100010];int vis[100010];int ans[100010];void solve(){ memset(ans,0,sizeof(ans)); memset(a,0,sizeof(a)); for(int i=2;i<=100000;i++) { if(a[i]==0) { ans[i]+=vis[i]; for(int k=i*2;k<=100010;k+=i) { ans[i]+=vis[k]; a[k]=1; } } }}int n,x;int main(){ scanf("%d",&n); memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { scanf("%d",&x); vis[x]++; } solve(); int op=1; for(int i=1;i<=100000;i++) { op=max(op,ans[i]); } printf("%d\n",op);}
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B - Bash's Big Day 枚举
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- B. Bash's Big Day (唯一分解定理)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day 数论+贪心
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) A. Gotta Catch Em' All!(水题)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming! 哈希
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C - Felicity is Coming!
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) B. Bash's Big Day(分拆素因子+求最多的公因子)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) -- C. Felicity is Coming! (STL水过)
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!组合学+集合
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)A+B
- Codeforces Round #400 (Div. 1 + Div. 2, combined)B.Sherlock and his girlfriend【预处理素数+思维】
- Codeforces Round #400 (Div. 1 + Div. 2, combined) 776B Sherlock and his girlfriend
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) 题解(A-E)
- Divide by Zero 2017 and Codeforces Round #399 (Div. 1 + Div. 2, combined) A(贪心)
- tensorflow数据可视化
- 统计每日单量MySQL语句
- putty的的颜色配置步骤
- 线程安全之SimpleDateFormat
- MVC4结合GetOrgChart.js实现组织架构图
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined)A+B
- MATLAB工具箱下载地址总汇
- List<Map<String,Object>>使用Java代码遍历以获取String,Object的值
- 图片平移实现水波动画
- 《连载 - 物联网框架ServerSuperIO教程》- 7.自控通讯模式开发及注意事项
- 【牛客网】构造MaxTree
- myeclipse自动设置类和方法的注释(快捷键)
- 2017.1.16【初中部 】普及组模拟赛C组 chicken 题解
- 几个闭包内存泄漏的优化方案!