Educational Codeforces Round 26总结
来源:互联网 发布:我的世界0.14作弊js 编辑:程序博客网 时间:2024/06/05 22:26
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.
7NonZERO
5
24this is zero answer text
0
24Harbour 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.
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);}}
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 5RRRRRRRRRRBBBBBBBBBBGGGGGGGGGG
YES
4 3BRGBRGBRGBRG
YES
6 7RRRGGGGRRRGGGGRRRGGGGRRRBBBBRRRBBBBRRRBBBB
NO
4 4RRRRRRRRBBBBGGGG
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.
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");}}}
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 21 22 1
4
4 10 92 31 15 109 11
56
3 10 106 67 720 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.
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);}}
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 250 4 20
3
5 315 16 3 25 9
3
3 39 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.
题意:从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;}}}
- Educational Codeforces Round 26总结
- Educational Codeforces Round 26
- Educational Codeforces Round 26
- Educational Codeforces Round 4 总结
- Educational Codeforces Round 5 总结
- Educational Codeforces Round 6 总结
- Educational Codeforces Round 7总结
- Educational Codeforces Round 8 总结
- Educational Codeforces Round 9 总结
- Educational Codeforces Round 20总结
- Educational Codeforces Round 21总结
- Educational Codeforces Round 23总结
- Educational Codeforces Round 25总结
- Codeforces Educational Round 27 总结
- Educational Codeforces Round 30 总结
- Educational Codeforces Round 26 B
- Educational Codeforces Round 26 C
- Educational Codeforces Round 26 D
- [PAT乙级]1012. 数字分类 (20)
- Hadoop 安装
- LinkedList与ArrayList的性能比较
- 【C++】继承和多态之——菱形继承
- 排序算法三归并排序
- Educational Codeforces Round 26总结
- 蓝桥杯练习题 BEGIN-2 序列求和
- (三)Angular4 英雄征途HeroConquest-初始化组件文件介绍
- 网络协议的综合思考 及 网络体系: OSI vs TCP/IP
- 总结:Distributed systems for fun and profit
- SSH面密码登陆设置失败一直需要输入密码可能原因分析
- Android 网络连接基本方式
- 基础排序(四)
- QTableView 数据操作