Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B

题链

Description

给一张方格图,对于上下移动无限制,左右移动数分别不能超过L,R,求能到多少点。

Sol

发现 新的y坐标=老坐标-左移操作数+右移操作数

所以我们只需最小化左移操作数即可,最短路。

Code

#include<bits/stdc++.h>
#define N 2007
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
char p[N][N]; pii X;
int dx[4]={0,1,-1,0},dy[4]={1,0,0,-1};
int in[N][N],ans,cao[N][N],gao;
template<class T>
inline void read(T &x){
    static char c;
    for (c=getchar();!isdigit(c);c=getchar());
    for (x=0;isdigit(c);c=getchar())x=x*10+c-48;
}
int n,m,l,r,x,y;
deque<pii> Q;
signed main() {
//    freopen("2.txt","r",stdin);
   read(n); read(m);
   read(x); read(y);
   read(l); read(r);
   memset(cao,0x12,sizeof cao);
   for (int i=1;i<=n;i++) scanf("%s",p[i]+1);
   Q.push_back(pii(x,y)); in[x][y]=1; cao[x][y]=0;
   while (!Q.empty()) {
        X=Q.front(); Q.pop_front(); in[X.fi][X.se]=0;
        if (cao[X.fi+dx[0]][X.se+dy[0]]>cao[X.fi][X.se]+1
        &&p[X.fi+dx[0]][X.se+dy[0]]==‘.‘) {
            cao[X.fi+dx[0]][X.se+dy[0]]=cao[X.fi][X.se]+1;//to right
            if (!in[X.fi+dx[0]][X.se+dy[0]]) {
              in[X.fi+dx[0]][X.se+dy[0]]=1,
               Q.push_back(pii(X.fi+dx[0],X.se+dy[0])); }
    }
        for (int i=1;i<4;i++) if (cao[X.fi+dx[i]][X.se+dy[i]]>cao[X.fi][X.se]
        &&p[X.fi+dx[i]][X.se+dy[i]]==‘.‘){
            cao[X.fi+dx[i]][X.se+dy[i]]=cao[X.fi][X.se];//to right
            if (!in[X.fi+dx[i]][X.se+dy[i]]) {
              in[X.fi+dx[i]][X.se+dy[i]]=1,
               Q.push_back(pii(X.fi+dx[i],X.se+dy[i])); }
      }

   }
   for (int i=1;i<=n;i++)
    for (int j=1;j<=m;j++) {
//        if (p[i][j]==‘*‘) continue;
        if (cao[i][j]>0x12121211) continue;
        gao=-(j-y-cao[i][j]); // to left
        if (gao<=l&&cao[i][j]<=r) ans++;
    }
    printf("%d\n",ans);
    return 0;
}

原文地址:https://www.cnblogs.com/rrsb/p/9807211.html

时间: 2024-11-08 11:22:40

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) B的相关文章

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) https://codeforces.com/contest/1064 A 1 #include<bits/stdc++.h> 2 #define pb push_back 3 using namespace std; 4 5 bool Check(int a,int b,int c){ 6 if(a+b>c&&b+c>a&&a+c>

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) D. Labyrinth

http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,-- 求的是最少的步数,所以使用bfs. step=k -> step=k+1 1.step=k 使用一次左/右 到达 step=k+1 2.step=k+1 无限使用上下,得到所有 step=k+1 的状态 用dijkstra+堆优化 / spfa 超时. 1 #include <bits/stdc++.h> 2 using namespace

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) C

题链 Description 和交互库交互,你给出n个点,交互库指定颜色,求一条直线分割颜色. Sol 分别在x轴,y轴上二分即可. Code #include<bits/stdc++.h> #define Mid (l+r>>1) using namespace std; int n,l,r; char p1[102],p2[102],p3[102]; void work(int x,int pos,int g) { l=500000000; r=1000000000; for

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) D

题链 Description 解一个线性规划(大雾) Sol 单纯形我们发现我们可以暴力枚举转的圈数,而这个东西可以数论分块优化. Code #include <bits/stdc++.h> #define LL long long using namespace std; LL n,x,k,lb,ub,l,r,ans=-1; int main() { scanf("%lld%lld%lld%lld",&n,&l,&r,&k); x=(r&g

Codeforces Round #516 (Div. 1, by Moscow Team Olympiad) E

题链 Description 给一个排列,要求每个激光打到指定的接受器上,最大化这个数量,你的手段只有在n*n的位置上放平面镜. Sol 我们发现一行要么只放‘/’要么只放‘\’,又发现answer=n||answer=n-1,这可以倒着合并. Description #include<bits/stdc++.h> #define N 1006 using namespace std; int n,a[N],last; char ans[N][N]; signed main () { scan

Codeforces Round #516 (Div. 2, by Moscow Team Olympiad) B

1 #include<bits/stdc++.h> 2 3 int n,T,cnt; 4 5 int read() 6 { 7 char ch = getchar(); 8 int num = 0; 9 bool fl = 0; 10 for (; !isdigit(ch); ch=getchar()) 11 if (ch=='-') fl = 1; 12 for (; isdigit(ch); ch=getchar()) 13 num = (num<<1)+(num<<

Codeforces Round #486 (Div. 3) A. Diverse Team

Codeforces Round #486 (Div. 3) A. Diverse Team 题目连接: http://codeforces.com/contest/988/problem/A Description There are n students in a school class, the rating of the i-th student on Codehorses is ai. You have to form a team consisting of k students

Codeforces Round #379 (Div. 2) Analyses By Team:Red &amp; Black

A.Anton and Danik Problems: 给你长度为N的,只含'A','D'的序列,统计并输出何者出现的较多,相同为"Friendship" Analysis: lucky_ji: 水题,模拟统计A和D的数目比较大小输出结果即可 Tags: Implementation B.Anton and Digits Problems: 给定k2个2,k3个3,k5个5及k6个6,可以组成若干个32或256,求所有方案中Sigma的最大值 Analysis: lucky_ji: 同

Codeforces Round #544 (Div. 3) C. Balanced Team [暴力剪枝]

You are a coach at your local university. There are n n students under your supervision, the programming skill of the i i -th student is a i ai . You have to create a team for a new programming competition. As you know, the more students some team ha