Codeforces Round #363 (Div. 2)
2016-07-20 10:46
501 查看
A. Launch of Collider
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
提示:题意说是有序,遍历所有即可,O(n);
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.
#include <iostream>
#include <bits/stdc++.h>
#define LL long long
using namespace std;
char s[200010];
int A[200000];
int main()
{
int n;
while(~scanf("%d",&n))
{
scanf("%s",s);
for(int i=0;i<n;i++)
scanf("%d",&A[i]);
int ans=1e9;
for(int i=1;i<n;i++)
{
if(s[i]=='L'&&s[i-1]=='R')
{
int tmp=A[i]+A[i-1];
if(tmp%2==0)
ans=min(ans,(tmp/2-A[i-1]));
}
}
if(ans==1e9)
printf("-1\n");
else
printf("%d\n",ans);
}
return 0;
}
B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
题意:安放一个炸弹是否可以把所有的墙都炸掉,(炸弹可以炸掉正行和整列);
提示:统计每行每列墙的数目,枚举每个安放炸弹的code;
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
#include <bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char s
;
int H
,L
;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int ans=0;
for(int i=0;i<n;i++)
{
scanf("%s",s[i]);
for(int j=0;j<m;j++)
{
if(s[i][j]=='*')
ans++,H[i]++,L[j]++;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if((H[i]+L[j]-(s[i][j]=='*'))==ans)
{
printf("YES\n%d %d\n",i+1,j+1);
return 0;
}
}
}
printf("NO\n");
}
return 0;
}
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
提示:题意说是有序,遍历所有即可,O(n);
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 <iostream>
#include <bits/stdc++.h>
#define LL long long
using namespace std;
char s[200010];
int A[200000];
int main()
{
int n;
while(~scanf("%d",&n))
{
scanf("%s",s);
for(int i=0;i<n;i++)
scanf("%d",&A[i]);
int ans=1e9;
for(int i=1;i<n;i++)
{
if(s[i]=='L'&&s[i-1]=='R')
{
int tmp=A[i]+A[i-1];
if(tmp%2==0)
ans=min(ans,(tmp/2-A[i-1]));
}
}
if(ans==1e9)
printf("-1\n");
else
printf("%d\n",ans);
}
return 0;
}
B. One Bomb
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
题意:安放一个炸弹是否可以把所有的墙都炸掉,(炸弹可以炸掉正行和整列);
提示:统计每行每列墙的数目,枚举每个安放炸弹的code;
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;
const int N=1e3+10;
char s
;
int H
,L
;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int ans=0;
for(int i=0;i<n;i++)
{
scanf("%s",s[i]);
for(int j=0;j<m;j++)
{
if(s[i][j]=='*')
ans++,H[i]++,L[j]++;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if((H[i]+L[j]-(s[i][j]=='*'))==ans)
{
printf("YES\n%d %d\n",i+1,j+1);
return 0;
}
}
}
printf("NO\n");
}
return 0;
}
相关文章推荐
- android开发命名规范
- Codeforces Round #363 (Div. 2) D. Fix a Tree
- kerl与eclipse中的erlang插件问题记录
- java topo: 开源jtopo框架
- CLGeocoder Error Domain=kCLErrorDomain Code=2
- git命令
- zepto.js 源码解析
- windows下mongodb安装与使用整理
- (Singleton)单例模式的Java实现
- Maven项目中的pom.xml详解
- Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)
- CSS Transitions and Transforms
- POJ 2559 Largest Rectangle in a Histogram 单调栈
- Mac 修改hosts文件
- python中print的不换行即时输出的快速解决方法
- ReactNative Demo - ImageVIew 使用
- MongoDB 3.2.7安装及用户角色配置
- JavaScriptCore框架介绍
- ssh目录权限要求
- Codeforces Round #363 (Div. 2)D. Fix a Tree(并查集)