Codeforces_Good_Bye_2017
2017-12-30 12:17
686 查看
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
output
input
output
input
output
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.
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. It's start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit
in the maze. It's 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
output
input
output
input
output
Note
For the first sample, the only valid mapping is
,
where D is down, L is
left, U is up, R is
right.
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
output
Note
The final positions of the disks will look as follows:
In particular, note the position of the last disk.
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.
#include<bits/stdc++.h> using namespace std; int main(){ string str; while(cin>>str){ int len=str.size(); int ans=0; for(int i=0;i<len;i++){ if(str[i]>='a'&&str[i]<='z'){ if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'){ ans++; } } else if(str[i]>='0'&&str[i]<='9'){ int num=(int)(str[i]-'0'); if(num%2==1){ ans++; } } } cout<<ans<<endl; } return 0; }
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. It's start position is denoted with the character 'S'. This position has no obstacle in it. There is also a single exit
in the maze. It's 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.
#include<bits/stdc++.h> using namespace std; char mapp[100][100]; int main(){ int n,m; while(cin>>n>>m){ int num[4]={0,1,2,3}; int s_x,s_y; int e_x,e_y; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>mapp[i][j]; if(mapp[i][j]=='S'){s_x=i;s_y=j;} if(mapp[i][j]=='E'){e_x=i;e_y=j;} } } int 9caa ans=0; int a=s_x;int b=s_y; string str;cin>>str;int len=str.size(); do { s_x=a;s_y=b; for(int i=0;i<len;i++){ int mm=(int)(str[i]-'0'); if(mm==num[0]){ s_x++; if(mapp[s_x][s_y]=='#')break; if(s_x<0||s_x>=n||s_y<0||s_y>=m)break; if(s_x==e_x&&s_y==e_y){ ans++;break; } } else if(mm==num[1]){ s_y++; if(mapp[s_x][s_y]=='#')break;if(s_x<0||s_x>=n||s_y<0||s_y>=m)break; if(s_x==e_x&&s_y==e_y){ ans++;break; } } else if(mm==num[2]){ s_x--; if(mapp[s_x][s_y]=='#')break;if(s_x<0||s_x>=n||s_y<0||s_y>=m)break; if(s_x==e_x&&s_y==e_y){ ans++;break; } } else if(mm==num[3]){ s_y--; if(mapp[s_x][s_y]=='#')break;if(s_x<0||s_x>=n||s_y<0||s_y>=m)break; if(s_x==e_x&&s_y==e_y){ ans++;break; } } } }while(next_permutation(num,num+4)); cout<<ans<<endl; } return 0; }
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 25 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.
#include<bits/stdc++.h> using namespace std; const int maxn=1000+100; int pos[maxn]; double ans[maxn]; int main(){ int n,r; while(~(scanf("%d%d",&n,&r))){ for(int i=0;i<n;i++){ scanf("%d",&pos[i]); } ans[0]=r; for(int i=1;i<n;i++){ double tmp=0.0; for(int j=0;j<i;j++){ if(pos[i]-pos[j]>2*r||pos[j]-pos[i]>2*r){ double y=r*1.0; tmp=max(tmp,y); } else if(pos[i]-pos[j]==2*r||pos[j]-pos[i]==2*r){ double y=ans[j]; tmp=max(tmp,y); } else if(pos[i]-pos[j]>0&&pos[i]-pos[j]<2*r){ double l=(double)(pos[i]-pos[j]); double rr=(double)(2*r); double h=sqrt(rr*rr-l*l); double y=ans[j]+h; tmp=max(tmp,y); } else if(pos[j]-pos[i]>0&&pos[j]-pos[i]<2*r){ double l=(double)(pos[j]-pos[i]); double rr=(double)(2.0*r); double h=sqrt(rr*rr-l*l); double y=ans[j]+h; tmp=max(tmp,y); } else{ double h=(double)(2.0*r); double y=ans[j]+h; tmp=max(tmp,y); } } ans[i]=tmp; } for(int i=0;i<n;i++){ if(i==n-1)printf("%.10lf\n",ans[i]); else printf("%.10lf ",ans[i]); } } return 0; }
相关文章推荐
- Codeforeces Good Bye 2017 A-C
- codeforce Good Bye 2017 C. New Year and Curling 暴力
- [杂题] Codeforces 772D VK Cup 2017 - Round 2 D. Varying Kibibits
- [置顶] 那些年我看过的书 —— 致敬我的大学生活 —— Say Good Bye !
- bye 2016, hi 2017
- hash(good)codeforces225D
- Say good bye to 2008! and welcome 2009!
- [交互 点分治] Codeforces 772E VK Cup 2017 - Round 2 E. Verifying Kingdom
- Codeforces Good Bye 2017
- codeforces 2016-2017 NTUWFTSC J Zero Game
- CodeForces-672B-Different is Good
- Codeforces Good Bye 2017 D. New Year and Arbitrary Arrangement
- Codeforces 838E IndiaHacks 2nd Elimination 2017 mirror Convex Countour :毛线DP啊
- [几何] Codeforces 772B VK Cup 2017 - Round 2 B. Volatile Kite
- Codeforces Good Bye 2017
- Codeforces Good Bye 2017 B. New Year and Buggy Bot 枚举全排列、模拟
- CodeForces P507E Breaking Good
- Good-Bye
- 跟去年SAY GOOD BYE
- 最后一个星期五 – My Good-Bye Party at Google