Codeforces Round #363 (Div. 2) (A,B,C)
2016-07-20 10:33
351 查看
A. Launch of Collider
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched
inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is
the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even
integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left
or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the
foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 ≤ n ≤ 200 000) —
the number of particles.
The second line contains n symbols "L"
and "R". If the i-th symbol equals
"L", then the i-th particle will
move to the left, otherwise the i-th symbol equals "R"
and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) —
the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
input
output
input
output
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will
simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty
(".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and
all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
Input
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) —
the number of rows and columns in the depot field.
The next n lines contain m symbols
"." and "*" each — the description of the field. j-th
symbol in i-th of them stands for cell (i, j).
If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*"
and the corresponding cell is occupied by a wall.
Output
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If
there are multiple answers, print any of them.
Examples
input
output
input
output
input
output
C. Vacations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each
of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th
day there are four options:
on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the
same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 ≤ n ≤ 100)
— the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3)
separated by space, where:
ai equals
0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
ai equals
1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
ai equals
2, if on the i-th day of vacations the gym is open and the contest is not carried out;
ai equals
3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
to do sport on any two consecutive days,
to write the contest on any two consecutive days.
Examples
input
output
input
output
input
output
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched
inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is
the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even
integers.
You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left
or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the
foreseeable time.
Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
Input
The first line contains the positive integer n (1 ≤ n ≤ 200 000) —
the number of particles.
The second line contains n symbols "L"
and "R". If the i-th symbol equals
"L", then the i-th particle will
move to the left, otherwise the i-th symbol equals "R"
and the i-th particle will move to the right.
The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) —
the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
Output
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen.
Examples
input
4 RLRL 2 4 6 10
output
1
input
3 LLR 40 50 60
output
-1
Note
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will
simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
#include <bits/stdc++.h> using namespace std; int a[200005]; int main() { int n; string ch; cin>>n; cin>>ch; for(int i=0;i<=n-1;i++) cin>>a[i]; int ans=1<<30; for(int i=0;i<=n-1;i++) { if(ch[i]=='R'&&ch[i+1]=='L') ans=min(ans,(a[i+1]-a[i])/2); } if(ans==1<<30) cout<<-1<<endl; else cout<<ans<<endl; return 0; }
B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty
(".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and
all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
Input
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) —
the number of rows and columns in the depot field.
The next n lines contain m symbols
"." and "*" each — the description of the field. j-th
symbol in i-th of them stands for cell (i, j).
If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*"
and the corresponding cell is occupied by a wall.
Output
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If
there are multiple answers, print any of them.
Examples
input
3 4 .*.. .... .*..
output
YES 1 2
input
3 3 ..* .*. *..
output
NO
input
6 5 ..*.. ..*.. ***** ..*.. ..*.. ..*..
output
YES 3 3
#include <bits/stdc++.h> using namespace std; char ch[1005][1005],ch1[1005][1005]; int row[1005],col[1005],n,m,flag=1; bool judge(int x,int y,int k) { flag=1; for(int i=1;i<=n;i++) k==0?ch[i][y]='.':ch1[i][y]='.'; for(int i=1;i<=m;i++) (k==0)?ch[x][i]='.':ch1[x][i]='.'; for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(!k&&ch[i][j]=='*'||k&&ch1[i][j]=='*') { flag=0; break; } } if(flag==0) return false; return true; } int main() { int x1=0,y1=0,x2=0,y2=0,num=0; scanf("%d %d",&n,&m); for(int i=1;i<=n;i++) { scanf("%s",ch[i]+1); strcpy(ch1[i]+1,ch[i]+1); } for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { if(ch[i][j]=='*') { num++; if(!x1){x1=x2=i;y1=y2=j;} else { if(x1!=i&&y1!=j) { x2=i; y2=j; break; } } } } //cout<<x1<<" "<<y1<<endl; //cout<<x2<<" "<<y2<<endl; if(num==1) { cout<<"YES"<<endl; cout<<x1<<" "<<y1<<endl; } else if(num==0) { cout<<"YES"<<endl; cout<<1<<" "<<1<<endl; } else if(judge(x1,y2,0)) { cout<<"YES"<<endl; cout<<x1<<" "<<y2<<endl; } else if(judge(x2,y1,1)) { cout<<"YES"<<endl; cout<<x2<<" "<<y1<<endl; } else cout<<"NO"<<endl; return 0; }
C. Vacations
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each
of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th
day there are four options:
on this day the gym is closed and the contest is not carried out;
on this day the gym is closed and the contest is carried out;
on this day the gym is open and the contest is not carried out;
on this day the gym is open and the contest is carried out.
On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).
Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the
same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.
Input
The first line contains a positive integer n (1 ≤ n ≤ 100)
— the number of days of Vasya's vacations.
The second line contains the sequence of integers a1, a2, ..., an (0 ≤ ai ≤ 3)
separated by space, where:
ai equals
0, if on the i-th day of vacations the gym is closed and the contest is not carried out;
ai equals
1, if on the i-th day of vacations the gym is closed, but the contest is carried out;
ai equals
2, if on the i-th day of vacations the gym is open and the contest is not carried out;
ai equals
3, if on the i-th day of vacations the gym is open and the contest is carried out.
Output
Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
to do sport on any two consecutive days,
to write the contest on any two consecutive days.
Examples
input
4 1 3 2 0
output
2
input
7 1 3 3 2 1 2 3
output
0
input
22 2
output
1
Note
In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day.
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#define maxn 105
#define inf 1<<30#define loop(a,b,c) for(int a=b;a<=c;a++)
using namespace std;
int a[maxn],dp[maxn][5];
int main()
{
//freopen("data","r",stdin);
int n;
cin>>n;
loop(i,1,n) cin>>a[i];
loop(i,0,n)
loop(j,0,2)
dp[i][j]=(i==0)?0:inf;
loop(i,1,n){
dp[i][0]=min(dp[i-1][0],min(dp[i-1][1],dp[i-1][2]))+1;
if(a[i]==1||a[i]==3) dp[i][1]=min(dp[i-1][0],dp[i-1][2]);
if(a[i]==2||a[i]==3) dp[i][2]=min(dp[i-1][0],dp[i-1][1]);
}
cout<<min(dp
[0],min(dp
[1],dp
[2]))<<endl;
return 0;
}
相关文章推荐
- Python 语法积累
- Android Studio导入Github上的项目
- MangoDB 实例
- css中隐藏元素的几种方法
- 博客-初篇
- 【iOS开发】iO7以上CIFilter生成二维码
- 自定义控件其实很简单5/12
- input中文字的垂直居中
- 微信支付#cool
- Ubuntu安装PyCharm
- win7 安装 vagrant + centos + virtualbox
- Spring10种常见异常解决方法
- tcl ,perl 脚本语言简单入门
- Ubuntu16.04 安装OpenCV 错误解决 ffmpeg
- Java 前端加密传输后端解密以及验证码功能
- 开发工具
- python之IP地址处理模块IPy
- Filter过滤器详解
- 47 大结局 不用加减乘除做加法
- hdu1240 Asteroids!--DFS & BFS