Educational Codeforces Round 26总结

来源:互联网 发布:我的世界0.14作弊js 编辑:程序博客网 时间:2024/06/05 22:26
A. Text Volume
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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.

Output

Print one integer number — volume of text.

Examples
input
7NonZERO
output
5
input
24this is zero answer text
output
0
input
24Harbour Space University
output
1
Note

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.

题意:问这些单词中最多有多少个大写字母
import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年8月3日 下午10:54:33 * 描述:永远的ACM */public class Main {private static final int Max=(int) (1e6+10);private static int n;private static String s;public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin=new Scanner(System.in);n=cin.nextInt();cin.nextLine();s=cin.nextLine();};private static void GetAns(){String []split=s.split(" ");int ans=Integer.MIN_VALUE;for(int i=0;i<split.length;i++){int cnt=0;for(int j=0;j<split[i].length();j++){if(split[i].charAt(j)>='A'&&split[i].charAt(j)<='Z'){cnt++;}}ans=Math.max(ans, cnt);//System.out.println(split[i]);}System.out.println(ans);}}
B. Flag of Berland
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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).

Input

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.

Output

Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).

Examples
input
6 5RRRRRRRRRRBBBBBBBBBBGGGGGGGGGG
output
YES
input
4 3BRGBRGBRGBRG
output
YES
input
6 7RRRGGGGRRRGGGGRRRGGGGRRRBBBBRRRBBBBRRRBBBB
output
NO
input
4 4RRRRRRRRBBBBGGGG
output
NO
Note

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 — 21 and 1.

题意:能不能将面积为n*m的区域划分成3个,并且3个颜色不同(每个区域颜色相同)
解:简单模拟
import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年8月3日 下午10:54:33 * 描述:永远的ACM */public class Main {private static final int Max=(int) (1e3+10);private static int n,m;private static String s[];public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin=new Scanner(System.in);s=new String[Max];n=cin.nextInt();m=cin.nextInt();for(int i=0;i<n;i++){s[i]=cin.next();}};private static void GetAns(){boolean ok=false;if(n%3==0){boolean R=true,G=true,B=true;int row=n/3;char a=s[0].charAt(0);char b=s[row].charAt(0);char c=s[row*2].charAt(0);if(a!=b&&b!=c&&a!=c){for(int i=0;i<row;i++){for(int j=0;j<m;j++){if(a!=s[i].charAt(j)){R=false;}}}for(int i=row;i<row*2;i++){for(int j=0;j<m;j++){if(b!=s[i].charAt(j)){G=false;}}}for(int i=2*row;i<row*3;i++){for(int j=0;j<m;j++){if(c!=s[i].charAt(j)){B=false;}}}if(R&&G&&B){ok=true;}}}if(m%3==0&&(!ok)){boolean R=true,G=true,B=true;int col=m/3;char a=s[0].charAt(0);char b=s[0].charAt(col);char c=s[0].charAt(col*2);if(a!=b&&a!=c&&b!=c){for(int i=0;i<col;i++){for(int j=0;j<n;j++){if(a!=s[j].charAt(i)){R=false;}}}for(int i=col;i<col*2;i++){for(int j=0;j<n;j++){if(b!=s[j].charAt(i)){G=false;}}}for(int i=col*2;i<col*3;i++){for(int j=0;j<n;j++){if(c!=s[j].charAt(i)){B=false;}}}if(R&&G&&B){ok=true;}}}if(ok){System.out.println("YES");}else{System.out.println("NO");}}}


C. Two Seals
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?

Input

The first line contains three integer numbers na and b (1 ≤ n, a, b ≤ 100).

Each of the next n lines contain two numbers xiyi (1 ≤ xi, yi ≤ 100).

Output

Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.

Examples
input
2 2 21 22 1
output
4
input
4 10 92 31 15 109 11
output
56
input
3 10 106 67 720 5
output
0
Note

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.


题意:选择两个(必须)章,使其占有的面积最大,并且不能覆盖(不能选两个输出0),可以旋转90度
解:将第一个放在左上角,然后看剩余的区域能不能放下第二个
import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年8月3日 下午10:54:33 * 描述:永远的ACM */public class Main {private static final int Max=(int) (1e3+10);private static int n,a,b;private static int []x;private static int []y;public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin=new Scanner(System.in);x=new int[Max];y=new int[Max];n=cin.nextInt();a=cin.nextInt();b=cin.nextInt();for(int i=0;i<n;i++){x[i]=cin.nextInt();y[i]=cin.nextInt();}};private static void GetAns(){int ans=0;for(int i=0;i<n;i++){int sum=0;boolean flag=false;int width1=0,high1=0;int width2=0,high2=0;int width3=0,high3=0;int width4=0,high4=0;boolean ok1=false,ok2=false;if((x[i]<=a&&y[i]<=b)||(x[i]<=b&&y[i]<=a)){sum+=(x[i]*y[i]);if((x[i]<=a&&y[i]<=b)){width1=a-x[i];high1=b;width2=a;high2=b-y[i];ok1=true;}if((x[i]<=b&&y[i]<=a)){width3=b-x[i];high3=a;width4=b;high4=a-y[i];ok2=true;}}else{continue;}int su=0;boolean ok=false;for(int j=i+1;j<n;j++){if(((x[j]<=width1&&y[j]<=high1)||(x[j]<=high1&&y[j]<=width1))||((x[j]<=width2&&y[j]<=high2)||(x[j]<=high2&&y[j]<=width2))){su=Math.max(su, (x[j]*y[j]));ok=true;}if(((x[j]<=width3&&y[j]<=high3)||(x[j]<=high3&&y[j]<=width3))||((x[j]<=width4&&y[j]<=high4)||(x[j]<=high4&&y[j]<=width4))){su=Math.max(su, (x[j]*y[j]));ok=true;}}if(ok){flag=true;sum+=su;}if(flag){ans=Math.max(ans, sum);}}System.out.println(ans);}}


D. Round Subset
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
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.

Input

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).

Output

Print maximal roundness of product of the chosen subset of length k.

Examples
input
3 250 4 20
output
3
input
5 315 16 3 25 9
output
3
input
3 39 77 13
output
0
Note

In the first example there are 3 subsets of 2 numbers. [50, 4] has product 200 with roundness 2[4, 20] — product 80roundness 1,[50, 20] — product 1000roundness 3.

In the second example subset [15, 16, 25] has product 6000roundness 3.

In the third example all subsets has product with roundness 0.


题意:从n个数中选k个数,使这K个数的乘积末尾的0个数最多
写的太复杂了,直接看代码吧
import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年8月3日 下午10:54:33 * 描述:永远的ACM */public class Main {private static final int Max=(int) (1e3+10);private static int n,k;private static ArrayList<Node2> list2;private static ArrayList<Node5> list5;private static ArrayList<Node25> list25;public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin=new Scanner(System.in);list2=new ArrayList<>();list5=new ArrayList<>();list25=new ArrayList<>();n=cin.nextInt();k=cin.nextInt();long a;for(int i=0;i<n;i++){a=cin.nextLong();Get(a);}};private static void GetAns(){Collections.sort(list25,new Comparator<Node25>() {@Overridepublic int compare(Node25 o1, Node25 o2) {return Math.min(o1.con2, o1.con5)-Math.min(o2.con2, o2.con5);}});Collections.sort(list2,new Comparator<Node2>() {@Overridepublic int compare(Node2 o1, Node2 o2) {return o1.con2-o2.con2;}});Collections.sort(list5,new Comparator<Node5>() {@Overridepublic int compare(Node5 o1, Node5 o2) {return o1.con5-o2.con5;}});int cnt=0;int ANS2=0,ANS5=0;int len2=list2.size()-1;int len5=list5.size()-1;int len25=list25.size()-1;while(cnt<k&&(len2>=0||len5>=0||len25>=0)){int ans1=-1,ans2=-1,ans3=-1;if(len25>=0){ans1=Math.min(list25.get(len25).con2, list25.get(len25).con5);}if(len2>=0){ans2=list2.get(len2).con2;}if(len5>=0){ans3=list5.get(len5).con5;}if(cnt==k-1){//if(ans1!=-1){//ANS2+=list25.get(len25).con2;//ANS5+=list25.get(len25).con5;//}else{//if(ans2!=-1&&ans3!=-1){//if(Math.min(ANS2+ans2, ANS5)>=Math.min(ANS2, ANS5+ans3)){//ANS2+=ans2;//}else{//ANS5+=ans3;//}//}else if(ans2!=-1&&ans3==-1){//ANS2+=ans2;//}else{//ANS5+=ans3;//}//}if(ans1!=-1&&ans2!=-1&&ans3!=-1){//!!!int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);int k2=Math.min(ANS2+ans2, ANS5);int k3=Math.min(ANS2, ANS5+ans3);int k=Math.max(k1, Math.max(k2, k3));if(k==k1){ANS2+=list25.get(len25).con2;ANS5+=list25.get(len25).con5;}else if(k==k2){ANS2+=ans2;}else{ANS5+=ans3;}}else if(ans1!=-1&&ans2!=-1&&ans3==-1){//!!=int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);int k2=Math.min(ANS2+ans2, ANS5);int k=Math.max(k1, k2);if(k==k1){ANS2+=list25.get(len25).con2;ANS5+=list25.get(len25).con5;}else{ANS2+=ans2;}}else if(ans1!=-1&&ans2==-1&&ans3!=-1){//!=!int k1=Math.min(ANS2+list25.get(len25).con2, ANS5+list25.get(len25).con5);int k2=Math.min(ANS2, ANS5+ans3);int k=Math.max(k1, k2);if(k==k1){ANS2+=list25.get(len25).con2;ANS5+=list25.get(len25).con5;}else{ANS5+=ans3;}}else if(ans1!=-1&&ans2==-1&&ans3==-1){//!==ANS2+=list25.get(len25).con2;ANS5+=list25.get(len25).con5;}else if(ans1==-1&&ans2!=-1&&ans3!=-1){//=!!int k2=Math.min(ANS2+ans2, ANS5);int k3=Math.min(ANS2, ANS5+ans3);int k=Math.max(k2, k3);if(k==k2){ANS2+=ans2;}else{ANS5+=ans3;}}else if(ans1==-1&&ans2!=-1&&ans3==-1){//=!=ANS2+=ans2;}else if(ans1==-1&&ans2==-1&&ans3!=-1){//==!ANS5+=ans3;}else if(ans1==-1&&ans2==-1&&ans3==-1){//===continue;}break;}if(ans1>=Math.min(ans2, ans3)&&ans1!=-1){ANS2+=list25.get(len25).con2;ANS5+=list25.get(len25).con5;len25--;cnt++;}else{if(ans2!=-1&&ans3!=-1){ANS2+=ans2;ANS5+=ans3;}else if(ans2!=-1&&ans3==-1){ANS2+=ans2;}else{ANS5+=ans3;}len2--;len5--;cnt+=2;}}//System.out.println(ANS2+"  "+ANS5);System.out.println(Math.min(ANS2, ANS5));}private static void Get(long x){int ans2=0,ans5=0;while(x%2==0){ans2++;x/=2;}while(x%5==0){ans5++;x/=5;}if(ans2!=0&&ans5!=0){Node25 node25=new Node25(ans2, ans5);list25.add(node25);}else if(ans2!=0&&ans5==0){Node2 node2=new Node2(ans2);list2.add(node2);}else{Node5 node5=new Node5(ans5);list5.add(node5);}}static class Node2{int con2;public Node2(int con2) {this.con2 = con2;}}static class Node5{int con5;public Node5(int con5) {this.con5 = con5;}}static class Node25{int con2;int con5;public Node25(int con2, int con5) {this.con2 = con2;this.con5 = con5;}}}



原创粉丝点击