Educational Codeforces Round 25总结

来源:互联网 发布:windows优化大师电脑版 编辑:程序博客网 时间:2024/06/05 19:02
A. Binary Protocol
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm:

  • Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones).
  • Digits are written one by one in order corresponding to number and separated by single '0' character.

Though Polycarp learnt how to encode the numbers, he has no idea how to decode them back. Help him calculate the decoded number.

Input

The first line contains one integer number n (1 ≤ n ≤ 89) — length of the string s.

The second line contains string s — sequence of '0' and '1' characters, number in its encoded format. It is guaranteed that the number corresponding to the string is positive and doesn't exceed 109. The string always starts with '1'.

Output

Print the decoded number.

Examples
input
3111
output
3
input
9110011101
output
2031

题意:一个1代表1个价值,每个数字之间用0隔开。给你结果,叫你反转求原来的值

解:模拟

import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年7月16日 下午11:04:25 * 描述: */public class Main {private static final int Max = (int) (1e5 + 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();s=cin.next();};private static void GetAns() {int ans=0;int index=0;for(int i=0;i<n;i++){if(s.charAt(i)=='1'){index=i;ans++;}else{System.out.print(ans);ans=0;}}System.out.println(ans);//if(ans!=0){//System.out.print(ans);//}//for(int i=0;i<(n-1-(index))/2;i++){//System.out.print("0");//}//System.out.println();};}

B. Five-In-a-Row
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.

In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.

Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.

Input

You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.

It is guaranteed that in the current arrangement nobody has still won.

Output

Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.

Examples
input
XX.XX..........OOOO.................................................................................
output
YES
input
XXOXX.....OO.O......................................................................................
output
NO
题意:在任意有点的地方插入一个X,问是否能五子连珠(可以大于5子)

解:循环给i,j为点的位置赋值成X,然后判断是否可以

import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年7月16日 下午11:04:25 * 描述: */public class Main {private static final int Max = (int) (1e3 + 10);private static String []s;private static char [][]a;public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin = new Scanner(System.in);s=new String[Max];a=new char[Max][Max];for(int i=0;i<10;i++){s[i]=cin.next();a[i]=s[i].toCharArray();}};private static void GetAns() {for(int i=0;i<10;i++){for(int j=0;j<10;j++){if(a[i][j]=='.'){a[i][j]='X';if(judge()){System.out.println("YES");return;}a[i][j]='.';}}}System.out.println("NO");return;};private static boolean judge(){for(int i=0;i<10;i++){//判断横for(int j=0;j<=10-5;j++){if(a[i][j]=='X'&&a[i][j+1]=='X'&&a[i][j+2]=='X'&&a[i][j+3]=='X'&&a[i][j+4]=='X'){return true;}}}for(int i=0;i<10;i++){//判断竖for(int j=0;j<=10-5;j++){if(a[j][i]=='X'&&a[j+1][i]=='X'&&a[j+2][i]=='X'&&a[j+3][i]=='X'&&a[j+4][i]=='X'){return true;}}}for(int i=0;i<10;i++){for(int j=0;j<10;j++){int cnt=0;if(Check(i, j)){cnt++;}if(Check(i+1, j+1)){cnt++;}if(Check(i+2, j+2)){cnt++;}if(Check(i+3, j+3)){cnt++;}if(Check(i+4, j+4)){cnt++;}if(cnt==5){return true;}}}for(int i=0;i<10;i++){for(int j=0;j<10;j++){int cnt=0;if(Check(i, j)){cnt++;}if(Check(i+1, j-1)){cnt++;}if(Check(i+2, j-2)){cnt++;}if(Check(i+3, j-3)){cnt++;}if(Check(i+4, j-4)){cnt++;}if(cnt==5){return true;}}}return false;}private static boolean Check(int x,int y){if(x>=0&&x<10&&y>=0&&y<10&&a[x][y]=='X'){return true;}return false;}}

C. Multi-judge Solving
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).

Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty  (no matter on what online judge was it).

Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.

With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.

For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.

Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.

Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

Input

The first line contains two integer numbers nk (1 ≤ n ≤ 1031 ≤ k ≤ 109).

The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output

Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

Examples
input
3 32 1 9
output
1
input
4 2010 3 6 3
output
0
Note

In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.

In the second example he can solve every problem right from the start.


题意:codeforces上有n个问题,要解决难度为a[i]的,必须解决难度为d>=a[iJ/2(在任何OJ上都行),求最少在其他OJ上完成多少道题

解:对于每个不能完成的,求最少需要完成多少。然后再把当前难度调整为a[i];

import java.util.Arrays;import java.util.Scanner;/** *  * 作者:张宇翔 * 创建日期:2017年7月16日 下午11:04:25 * 描述: */public class Main {private static final int Max = (int) (1e4 + 10);private static int n,k;private static int []a;public static void main(String[] args) {InitData();GetAns();}private static void InitData() {Scanner cin = new Scanner(System.in);a=new int[Max];n=cin.nextInt();k=cin.nextInt();for(int i=0;i<n;i++){a[i]=cin.nextInt();}};private static void GetAns() {Arrays.sort(a,0,n);int ans=0;int MAX=k;for(int i=0;i<n;i++){int x=a[i]%2==0?(a[i]/2):(a[i]/2+1);if(MAX>=x){MAX=Math.max(MAX, a[i]);}else{int temp=x;while(MAX<temp){ans++;temp=temp%2==0?(temp/2):(temp/2+1);}MAX=a[i];}}System.out.println(ans);};}



原创粉丝点击