Codeforces Round #363(Div. 2) A. Launch of Collider【模拟】 && B. One Bomb【暴力】

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值