Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】
A. Launch of Collider
题目链接:
http://codeforces.com/problemset/problem/699/A
题意:
两个数组【char【表示方向只有L和R】、int【x轴上的坐标】】 每秒都更新 根据方向来移动单位1,求第几秒时 两点或者几点 第一次相撞
解题:
只要寻找相邻两点为RL的,求所有这些组合min (两者的差/2)
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <map>
#include <cmath>
using namespace std;
#define eps 1e-6
#define pi 3.14159265359
typedef long long LL;
typedef long double LD;
const int maxn = 200100;
int n, h, k;
LL a[maxn];
char s[maxn];
int main(){
while(~scanf("%d",&n)){
scanf("%s",s);
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
LL ma =1000000000;
for(int i=0;i<n-1;i++){
if(s[i]=='R'&& s[i+1]=='L') //a[i] 为 even
ma = min(ma,(a[i+1]-a[i])/2);
}
if(ma!=1000000000)printf("%lld\n",ma);
else printf("-1\n");
}
return 0;
}
B. One Bomb
题目链接:
http://codeforces.com/problemset/problem/699/B
题意:
在n*m的矩阵里面有未知堵墙,若在某点放置一个炸弹【能炸同列和同行】,问能不能把所有的墙炸碎?
解题:
暴力枚举 墙数 cnt、每行r[i] 和每列c[i] 的炸弹数,再二重for遍历判断此点可以炸的墙cou==cnt?【考虑a[i][j]为墙的情况,排除重叠】;有特殊情况,若无墙cnt为0,炸弹无论炸哪都是可以的,默认炸点(1,1)。
#include"cstdio"
#include"cstring"
#include"iostream"
using namespace std;
#define M 1200
char a[M][M];
int r[M],c[M];
int n,m,cnt,ii,jj,flag_,cou;
struct node{
int bi,bj;
}b[M*M];
void dfs(){
flag_ = 0;
for(int i=1;i<=n && !flag_;i++){
for(int j=1;j<=m && !flag_;j++){
cou = r[i]+c[j];
if(a[i][j]=='*') cou--;//a[i][j]为墙 排除行列重叠的
if(cnt==cou){
flag_ = 1;
ii = i,jj = j;
break;
}
}
}
}
int main(){
while(~scanf("%d %d",&n,&m)){
cnt = 0;
memset(r,0,sizeof(r));
memset(c,0,sizeof(c));
for(int i=1;i<=n;i++){
getchar();
for(int j=1;j<=m;j++){
scanf("%c",&a[i][j]);
if(a[i][j]=='*'){
r[i]++,c[j]++;
cnt++;
}
}
}
if(!cnt) {
printf("YES\n");
printf("1 1\n");//要放炸弹
continue;
}
dfs();
if(!flag_) printf("NO\n");
else{
printf("YES\n");
printf("%d %d\n",ii,jj);
}
}
return 0;
}