Good Bye 2017(ABC)

A. New Year and Counting Cards
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Your friend has n cards.

You know that each card has a lowercase English letter on one side and a digit on the other.

Currently, your friend has laid out the cards on a table so only one side of each card is visible.

You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'.

For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true.

To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true.

Input

The first and only line of input will contain a string s (1 ≤ |s| ≤ 50), denoting the sides of the cards that you can see on the table currently. Each character of s is either a lowercase English letter or a digit.

Output

Print a single integer, the minimum number of cards you must turn over to verify your claim.

Examples
Input
ee
Output
2
Input
z
Output
0
Input
0ay1
Output
2
Note

In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.

In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on them.

In the third sample, we need to flip the second and fourth cards.

 

一看就直接猜了,果然不出所料,

如果是字母的话,是元音就要翻一次,是数字的话,如果不是02468的话就翻一次。

所以只要猜到题意,就可以秒了。

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 #define N 1000000
 5 
 6 using namespace std;
 7 string s;
 8 int main(){
 9     std::ios::sync_with_stdio(false);
10     std::cin.tie(0);
11     cin>>s;
12     int cnt = 0;
13     for(int i=0;i<s.length();i++){
14         if(s[i]>='a'&&s[i]<='z'){
15             if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'){
16                 cnt++;
17             }
18         }else{
19             if(s[i]!='0'&&s[i]!='2'&&s[i]!='4'&&s[i]!='6'&&s[i]!='8'){
20                 cnt++;
21             }
22         }
23     }
24     cout<<cnt<<endl;
25 
26     return 0;
27 }

 

B. New Year and Buggy Bot
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob programmed a robot to navigate through a 2d maze.

The maze has some obstacles. Empty cells are denoted by the character '.', where obstacles are denoted by '#'.

There is a single robot in the maze. Its start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit in the maze. Its position is denoted with the character 'E'. This position has no obstacle in it.

The robot can only move up, left, right, or down.

When Bob programmed the robot, he wrote down a string of digits consisting of the digits 0 to 3, inclusive. He intended for each digit to correspond to a distinct direction, and the robot would follow the directions in order to reach the exit. Unfortunately, he forgot to actually assign the directions to digits.

The robot will choose some random mapping of digits to distinct directions. The robot will map distinct digits to distinct directions. The robot will then follow the instructions according to the given string in order and chosen mapping. If an instruction would lead the robot to go off the edge of the maze or hit an obstacle, the robot will crash and break down. If the robot reaches the exit at any point, then the robot will stop following any further instructions.

Bob is having trouble debugging his robot, so he would like to determine the number of mappings of digits to directions that would lead the robot to the exit.

Input

The first line of input will contain two integers n and m (2 ≤ n, m ≤ 50), denoting the dimensions of the maze.

The next n lines will contain exactly m characters each, denoting the maze.

Each character of the maze will be '.', '#', 'S', or 'E'.

There will be exactly one 'S' and exactly one 'E' in the maze.

The last line will contain a single string s (1 ≤ |s| ≤ 100) — the instructions given to the robot. Each character of s is a digit from 0 to 3.

Output

Print a single integer, the number of mappings of digits to directions that will lead the robot to the exit.

Examples
Input
5 6
.....#
S....#
.#....
.#....
...E..
333300012
Output
1
Input
6 6
......
......
..SE..
......
......
......
01232123212302123021
Output
14
Input
5 3
...
.S.
###
.E.
...
3
Output
0
Note

For the first sample, the only valid mapping is , where D is down, L is left, U is up, R is right.

 这个就可以暴力的做了,题意就是给你一个地图,有入口,有出口,然后要你跟着下面的数字走,

每个数字都表示一种方向,但是是不一样的,也就是说只有四个不一样的数字,然后求不一样的走法有多少种。

 1 #include <iostream>
 2 #include <cstring>
 3 
 4 #define N 100
 5 
 6 using namespace std;
 7 int n,m;
 8 char k[N][N];
 9 char vis[24][4]={{ 0, 1, 2, 3 }, { 0, 1, 3, 2 }, { 0, 2, 1, 3 }, { 0, 2, 3, 1 }, { 0, 3, 1, 2 }, { 0, 3, 2, 1 },
10 { 1, 0, 2, 3 }, { 1, 0, 3, 2 }, { 1, 2, 0, 3 }, { 1, 2, 3, 0 }, { 1, 3, 0, 2 }, { 1, 3, 2, 0 },
11 { 2, 0, 1, 3 }, { 2, 0, 3, 1 }, { 2, 1, 0, 3 }, { 2, 1, 3, 0 }, { 2, 3, 0, 1 }, { 2, 3, 1, 0 },
12 { 3, 0, 1, 2 }, { 3, 0, 2, 1 }, { 3, 1, 0, 2 }, { 3, 1, 2, 0 }, { 3, 2, 0, 1 }, { 3, 2, 1, 0 }};
13 string s;
14 int main(){
15     std::ios::sync_with_stdio(false);
16     std::cin.tie(0);
17     cin>>n>>m;
18     int aa,bb;
19     for(int i=1;i<=n;i++){
20         for(int j=1;j<=m;j++){
21             cin>>k[i][j];
22             if(k[i][j]=='S'){
23                 aa=i,bb=j;
24             }
25         }
26     }
27     cin>>s;
28     int cnt = 0;
29 
30     for(int i=0;i<24;i++){
31         bool prime = true;
32         bool flag = false;
33         int a=aa,b=bb;
34         for(int j=0;j<s.length();j++){
35             int x=s[j]-'0';
36             // cout<<x<<" *** ";
37             if(vis[i][x]==0){
38                 a=a+1;
39             }else if(vis[i][x]==1){
40                 b=b+1;
41             }else if(vis[i][x]==2){
42                 a=a-1;
43             }else{
44                 b=b-1;
45             }
46             if(k[a][b]=='#'||a<1||a>n||b<1||b>m){
47                 prime = false;
48                 break;
49             }
50             if(k[a][b]=='E'){
51                 flag = true;
52                 break;
53             }
54         }
55         // cout<<endl;
56         if(prime&&flag){
57             cnt++;
58         }
59     }
60     cout<<cnt<<endl;
61     return 0;
62 }

 

C. New Year and Curling
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Carol is currently curling.

She has n disks each with radius r on the 2D plane.

Initially she has all these disks above the line y = 10100.

She then will slide the disks towards the line y = 0 one by one in order from 1 to n.

When she slides the i-th disk, she will place its center at the point (xi, 10100). She will then push it so the disk’s y coordinate continuously decreases, and x coordinate stays constant. The disk stops once it touches the line y = 0 or it touches any previous disk. Note that once a disk stops moving, it will not move again, even if hit by another disk.

Compute the y-coordinates of centers of all the disks after all disks have been pushed.

Input

The first line will contain two integers n and r (1 ≤ n, r ≤ 1 000), the number of disks, and the radius of the disks, respectively.

The next line will contain n integers x1, x2, ..., xn (1 ≤ xi ≤ 1 000) — the x-coordinates of the disks.

Output

Print a single line with n numbers. The i-th number denotes the y-coordinate of the center of the i-th disk. The output will be accepted if it has absolute or relative error at most 10 - 6.

Namely, let's assume that your answer for a particular value of a coordinate is a and the answer of the jury is b. The checker program will consider your answer correct if for all coordinates.

Example
Input
6 2
5 5 6 8 3 12
Output
2 6.0 9.87298334621 13.3370849613 12.5187346573 13.3370849613
Note

The final positions of the disks will look as follows:

In particular, note the position of the last disk.

一开始没怎么看懂,然后看懂的时候,发现自己没啥思路,(忘了关注数据量,突然发现直接暴力来的更方便。)

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 #include <algorithm>
 5 #include <cmath>
 6 #define N 1005
 7 using namespace std;
 8 
 9 int m,n;
10 int k[N];
11 double vis[N];
12 int main(){
13     ios::sync_with_stdio(false);
14     cin.tie(0);
15     cin>>m>>n;
16     for(int i=0;i<m;i++)
17         cin>>k[i];
18     for(int i=0;i<m;i++){
19         double s = n;
20         for(int t=0;t<i;t++){
21             if(abs(k[i]-k[t])<=2*n){
22                 s = max(s,sqrt(4.0*n*n-(k[i]-k[t])*(k[i]-k[t]))+vis[t]);
23             }
24         }
25         vis[i] = s;
26     }
27     for(int i=0;i<m;i++){
28         printf("%.10lf ",vis[i]);
29     }
30     printf("\n");
31     return 0;
32 }

 

posted @ 2018-01-02 10:28  #忘乎所以#  阅读(169)  评论(0编辑  收藏  举报