Educational Codeforces Round 26
1 second
256 megabytes
standard input
standard output
You are given a text of single-space separated words, consisting of small and capital Latin letters.
Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text.
Calculate the volume of the given text.
The first line contains one integer number n (1 ≤ n ≤ 200) — length of the text.
The second line contains text of single-space separated words s1, s2, ..., si, consisting only of small and capital Latin letters.
Print one integer number — volume of text.
7
NonZERO
5
24
this is zero answer text
0
24
Harbour Space University
1
In the first example there is only one word, there are 5 capital letters in it.
In the second example all of the words contain 0 capital letters.
求一个单词内最多的大写字母个数,遇到空格处理下,最后也处理下
#include<bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
getchar();
string s;
getline(cin,s);
int sum=,f=;
for(int i=;s[i];i++){
if(s[i]==' '){
if(f>sum)sum=f;
f=;
}else if(s[i]<'a')f++;
}
if(f>sum)sum=f;
cout<<sum<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
The flag of Berland is such rectangular field n × m that satisfies following conditions:
- Flag consists of three colors which correspond to letters 'R', 'G' and 'B'.
- Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color.
- Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
YES
4 3
BRG
BRG
BRG
BRG
YES
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
NO
4 4
RRRR
RRRR
BBBB
GGGG
NO
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
怎样才是波兰的国旗,就是有RGB对吧,那我MAP一下枚举就好了啊
#include<bits/stdc++.h>
using namespace std;
char s[][];
int main() {
int n,m;
cin>>n>>m;
for(int i=;i<n;i++){
cin>>s[i];
}
map<char,int>M;
M['R']=,M['B']=,M['G']=;
if(n%==){
for(int i=;i<n;i+=n/){
char c=s[i][];
for(int j=i;j<i+n/;j++)
for(int k=;k<m;k++)
if(c!=s[j][k]) M[c]=-;
if(M[c]==){M[c]=;}
}
}
if(M['R']==&&M['G']==&&M['B']==)
return *puts("YES");
M['R']=,M['B']=,M['G']=;
if(m%==){
for(int i=;i<m;i+=m/){
char c=s[][i];
for(int j=i;j<i+m/;j++)
for(int k=;k<n;k++){
if(c!=s[k][j]) M[c]=-;}
if(M[c]==)M[c]=;
}
}
if(M['R']==&&M['G']==&&M['B']==)
return *puts("YES");
puts("NO");
return ;
}
1 second
256 megabytes
standard input
standard output
One very important person has a piece of paper in the form of a rectangle a × b.
Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees).
A very important person wants to choose two different seals and put them two impressions. Each of the selected seals puts exactly one impression. Impressions should not overlap (but they can touch sides), and the total area occupied by them should be the largest possible. What is the largest area that can be occupied by two seals?
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100).
Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
2 2 2
1 2
2 1
4
4 10 9
2 3
1 1
5 10
9 11
56
3 10 10
6 6
7 7
20 5
0
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper.
In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the largest area.
In the third example there is no such pair of seals that they both can fit on a piece of paper.
C也直接枚举就完事了,枚举左上,再判断另一个合适么?
等换了显示器我就可以换成这种大括号换行了
#include <bits/stdc++.h>
using namespace std;
int N,X,Y,a[],b[],f=;
void la(int x0,int y0,int x1,int y1)
{
if((x0+x1<=X)&&(y0<=Y)&&(y1<=Y))
{
f=max(f,x0*y0+x1*y1);
}
if((y0+y1<=Y)&&(x0<=X)&&(x1<=X))
{
f=max(f,x0*y0+x1*y1);
}
} int main()
{
cin>>N>>X>>Y;
for(int i=; i<N; i++)
{
cin>>a[i]>>b[i];
}
for(int i=; i<N; i++)
{
for(int j=; j<i; j++)
{
la(a[i],b[i],a[j],b[j]);
la(a[i],b[i],b[j],a[j]);
la(b[i],a[i],a[j],b[j]);
la(b[i],a[i],b[j],a[j]);
}
}
cout<<f<<endl;
return ;
}
1 second
256 megabytes
standard input
standard output
Vasya is studying number theory. He has denoted a function f(a, b) such that:
- f(a, 0) = 0;
- f(a, b) = 1 + f(a, b - gcd(a, b)), where gcd(a, b) is the greatest common divisor of a and b.
Vasya has two numbers x and y, and he wants to calculate f(x, y). He tried to do it by himself, but found out that calculating this function the way he wants to do that might take very long time. So he decided to ask you to implement a program that will calculate this function swiftly.
The first line contains two integer numbers x and y (1 ≤ x, y ≤ 1012).
Print f(x, y).
3 5
3
6 3
1
数论的题目,想起来是没有是什么,因为好像和公因数有关,但又不知道有哪些关系还是看大佬代码比较靠谱
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF=1e18;
vector <LL> s;
LL gcd(LL a,LL b)
{
return b==?a:gcd(b,a%b);
}
void la(LL x)
{
LL rx=sqrt(x+0.5);
if(!(x&))
{
s.push_back();
while(!(x&)) x/=;
}
for(int i=; i<=rx; i+=)
{
if(x%i==)
{
s.push_back(i);
while(x%i==) x/=i;
}
}
if(x>) s.push_back(x);
}
int main()
{
LL x,y;
scanf("%lld%lld",&x,&y);
la(x);
LL ans=,m;
while(y)
{
LL g=gcd(x,y);
x/=g;
y/=g;
m=y;
for(auto p:s)
if(x%p==) m=min(m,y%p);
ans+=m;
y-=m;
}
printf("%lld\n",ans);
return ;
}
2 seconds
256 megabytes
standard input
standard output
Let's call the roundness of the number the number of zeros to which it ends.
You have an array of n numbers. You need to choose a subset of exactly k numbers so that the roundness of the product of the selected numbers will be maximum possible.
The first line contains two integer numbers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n).
The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 1018).
Print maximal roundness of product of the chosen subset of length k.
3 2
50 4 20
3
5 3
15 16 3 25 9
3
3 3
9 77 13
0
In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2, [4, 20] — product 80, roundness 1, [50, 20] — product 1000, roundness 3.
In the second example subset [15, 16, 25] has product 6000, roundness 3.
In the third example all subsets has product with roundness 0.
k个数的后缀0最多,10的因子是2和5,然后每次取2和5的最小值就好的,dp
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
ll a[];
int n2[];
int n5[];
int dp[][][];
int la2(ll num)
{
int sum=;
while(num%==)num/=,sum++;
return sum;
}
int la5(ll num)
{
int sum=;
while(num%==)num/=,sum++;
return sum;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(dp,-,sizeof(dp));
for(int i=; i<=n; i++)scanf("%I64d",&a[i]);
for(int i=; i<=n; i++)
{
n2[i]=la2(a[i]);
n5[i]=la5(a[i]);
}
int ma=;
dp[][][]=;
int f1=,f2=;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
for(int k=; k>=; k--)
{
dp[f2][j][k]=max(dp[f1][j][k],dp[f1][j][k]);
if(k>=n2[i]&&dp[f1][j-][k-n2[i]]!=-)
dp[f2][j][k]=max(dp[f2][j][k],dp[f1][j-][k-n2[i]]+n5[i]);
ma=max(ma,min(k,dp[f2][j][k]));
}
}
dp[f2][][]=dp[f1][][];
swap(f1,f2);
}
printf("%d\n",ma);
}
}
Educational Codeforces Round 26的更多相关文章
- CodeForces 837F - Prefix Sums | Educational Codeforces Round 26
按tutorial打的我血崩,死活挂第四组- - 思路来自FXXL /* CodeForces 837F - Prefix Sums [ 二分,组合数 ] | Educational Codeforc ...
- CodeForces - 837E - Vasya's Function | Educational Codeforces Round 26
/* CodeForces - 837E - Vasya's Function [ 数论 ] | Educational Codeforces Round 26 题意: f(a, 0) = 0; f( ...
- CodeForces 837D - Round Subset | Educational Codeforces Round 26
/* CodeForces 837D - Round Subset [ DP ] | Educational Codeforces Round 26 题意: 选k个数相乘让末尾0最多 分析: 第i个数 ...
- Educational Codeforces Round 26 [ D. Round Subset ] [ E. Vasya's Function ] [ F. Prefix Sums ]
PROBLEM D - Round Subset 题 OvO http://codeforces.com/contest/837/problem/D 837D 解 DP, dp[i][j]代表已经选择 ...
- Educational Codeforces Round 26 B,C
B. Flag of Berland 链接:http://codeforces.com/contest/837/problem/B 思路:题目要求判断三个字母是否是条纹型的,而且宽和高相同,那么先求出 ...
- Educational Codeforces Round 26 D dp
D. Round Subset time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Educational Codeforces Round 26 F. Prefix Sums 二分,组合数
题目链接:http://codeforces.com/contest/837/problem/F 题意:如题QAQ 解法:参考题解博客:http://www.cnblogs.com/FxxL/p/72 ...
- Educational Codeforces Round 26 E - Vasya's Function
数论题还是好恶心啊. 题目大意:给你两个不超过1e12的数 x,y,定义一个f ( x, y ) 如果y==0 返回 0 否则返回1+ f ( x , y - gcd( x , y ) ); 思路:我 ...
- Educational Codeforces Round 26 A B C题
题目链接 A. Text Volume 题意:计算句子中,每个单词大写字母出现次数最多的那个的出现次数(混不混乱QAQ). 解题思路:注意getchar()就没啥了. #include<cstd ...
随机推荐
- npm scripts 常用规范总结
npm scripts 常用规范总结 随着 npm scripts 使用越来越多,需要规范一下, npm run 的使用词. 定义 我定义如下形式: npm run <action>:&l ...
- jdk下载安装配置环境变量
因为学习原因要用到一些工具,jdk12的版本与那个工具不兼容,所以这里推荐使用的是jdk1.8的版本, 不知道是电脑原因还是啥原因,jdk 12的版本用不了配不好环境变量. 首先可以在官网下载jdk1 ...
- this/super/static/final/匿名对象/继承/抽象类/访问权限修饰符
1.this关键字的作用 1)调用本类中的属性; 2)调用本类中的构造方法;且只能放首行,且必须留一个构造方法作为出口,即不能递归调用 3)表示当前对象; 2.匿名对象 ...
- Hibernate框架关系映射一对多双向关联
直入主题,首先大配置常规配置, 这里住要说关联关系,大配置不多少,而且jar包默认添加好,笔者用的是idea2016. 然后我们知道关联关系主要是在小配置添加节点来配置属性.个人认为关联映射,就是对应 ...
- Glide图片框架
//加载圆形图片Glide.with(this).load(WSCAppStatic.WEB_KEFU_PHOTO_URL+ "?usercode=8120000315") .as ...
- hihoCoder hiho一下 第四十六周 博弈游戏·Nim游戏·三( sg函数 )
题意: 给出几堆石子数量,每次可以取走一堆中任意数量的石头,也可以将一堆分成两堆,而不取.最后取走者胜. 思路: 先规矩地计算出sg值,再对每个数量查SG值就可以了.最后求异或和.和不为0的就是必赢. ...
- 百度影棒安装apk方法
确保影棒和电脑接入家中同一WIFI中,开启影棒USB调试,手机端运行悟空助手或沙发管家等软件,之后无线推送需要安装的APK. 安装文件管理apk后,可以使用U盘安装.
- Go 1.4 正式版发布,官方正式支持 Android
Go 1.4 正式发布啦,是第五个 Go 的稳定版本,与上一个稳定版本 Go 1.3 相隔 6 个月.Go 1.4 包括一些小的语言改进,支持更多的操作系统和处理器架构:改进了工具链和库.同时,Go ...
- JSON数组不用字符串转换的写法
var organization = []; //机构组织 //初始化用户数据列表中用户机构列的数据源 admin.ajax("GetOrganizationInfo", null ...
- python读取.mat文件
可以先看一下.mat中存了些什么: import scipy.io as sio box_file = '/home/bnrc/formatm/test/1479504458876408533_box ...