Codeforces Round #590 (Div. 3) C. Pipes

链接:

https://codeforces.com/contest/1234/problem/C

题意:

You are given a system of pipes. It consists of two rows, each row consists of n pipes. The top left pipe has the coordinates (1,1) and the bottom right — (2,n).

There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:

Types of pipes
You can turn each of the given pipes 90 degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types 1 and 2 can become each other and types 3,4,5,6 can become each other).

You want to turn some pipes in a way that the water flow can start at (1,0) (to the left of the top left pipe), move to the pipe at (1,1), flow somehow by connected pipes to the pipe at (2,n) and flow right to (2,n+1).

Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:

Examples of connected pipes
Let‘s describe the problem using some example:

The first example input
And its solution is below:

The first example answer
As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at (1,2) 90 degrees clockwise, the pipe at (2,3) 90 degrees, the pipe at (1,6) 90 degrees, the pipe at (1,7) 180 degrees and the pipe at (2,7) 180 degrees. Then the flow of water can reach (2,n+1) from (1,0).

You have to answer q independent queries.

思路:

记录当前位置和上一位置, 枚举情况即可.

代码:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+10;

char Map[2][MAXN];
int n;

int main()
{
    int t;
    scanf("%d", &t);
    while (t--)
    {
        scanf("%d\n", &n);
        scanf("%s%s", Map[0], Map[1]);
        int nowx = 0, nowy = 0, lasx = -1, lasy = -1;
        bool flag = true;
        while (nowy < n)
        {
            if (lasx == -1)
            {
                lasx = nowx, lasy = nowy;
                if (Map[nowx][nowy]-'0' <= 2)
                    nowy++;
                else
                    nowx ^= 1;
                continue;
            }
            if (nowx == lasx)
            {
                if (Map[lasx][lasy]-'0' <= 2)
                {
                    lasx = nowx, lasy = nowy;
                    if (Map[nowx][nowy]-'0' <= 2)
                        nowy++;
                    else
                        nowx ^= 1;
                }
                else
                {
                    lasx = nowx, lasy = nowy;
                    if (Map[nowx][nowy]-'0' <= 2)
                        nowy++;
                    else
                        nowx ^= 1;
                }
            }
            else
            {
                if (Map[lasx][lasy]-'0' <= 2)
                {
                    flag = false;
                    break;
                }
                else
                {
                    if (Map[nowx][nowy]-'0' <= 2)
                    {
                        flag = false;
                        break;
                    }
                    else
                    {
                        lasx = nowx, lasy = nowy;
                        nowy++;
                    }
                }
            }
        }
//        cout << line << endl;
        if (!flag || nowx != 1)
            puts("NO");
        else
            puts("YES");
    }

    return 0;
}

原文地址:https://www.cnblogs.com/YDDDD/p/11618852.html

时间: 2024-10-04 18:48:50

Codeforces Round #590 (Div. 3) C. Pipes的相关文章

Codeforces Round #590 (Div. 3) Editorial

Codeforces Round #590 (Div. 3) Editorial 题目链接 官方题解 不要因为走得太远,就忘记为什么出发! Problem A 题目大意:商店有n件商品,每件商品有不同的价格,找出一个最小的可能值price,使得price * n >= sum,sum指的是原来商品价格的总和. 知识点:模拟 思路:求出sum/n向上取整即可,有两种方法.一是使用ceil()函数,但注意ceil()返回的是向上取整后的浮点数,所以要进行强制类型转换:二是直接向下取整,然后用if语句

Codeforces Round #590 (Div. 3) C——1234C Pipes

D. Distinct Characters Queries time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a system of pipes. It consists of two rows, each row consists of nn pipes. The top left pipe ha

Codeforces Round #590 (Div. 3)(e、f待补

https://codeforces.com/contest/1234/problem/A A. Equalize Prices Again 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main(){ 5 int n,a; 6 int t; 7 cin>>t; 8 ll sum = 0,ans; 9 while(t--){ 10 cin>>n;sum = 0

Codeforces Round #590 (Div. 3)

D. Distinct Characters Queries Description You are given a string ss consisting of lowercase Latin letters and qq queries for this string. Recall that the substring s[l;r]s[l;r] of the string ss is the string slsl+1…srslsl+1…sr. For example, the subs

Codeforces Round #590 (Div. 3) B2. Social Network (hard version)

链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most

Codeforces Round #590 (Div. 3) D. Distinct Characters Queries(线段树, 位运算)

链接: https://codeforces.com/contest/1234/problem/D 题意: You are given a string s consisting of lowercase Latin letters and q queries for this string. Recall that the substring s[l;r] of the string s is the string slsl+1-sr. For example, the substrings

Codeforces Round #590 (Div. 3) F

传送门 题意: 给出一个只含前\(20\)个字符的字符串,现在可以选择一段区间进行翻转,问区间中字符各不相同时,最长长度为多少. 思路: 首先,容易将题意转换为选择两个字符各不相同的区间,然后长度相加取最大: 注意到字符串中满足条件的区间长度不超过\(20*n\),那么处理出所有区间,现在任务即为找到两个区间,其字符各不想同,且长度和最大: 因为最多\(20\)个字符,将满足条件的区间转换为二进制数,任务转换为找到两个数\(a_i,a_j\)满足\(a_i\&a_j=0\)且二进制为\(1\)的

Codeforces Round #590 (Div. 3)补题

要想上2000分,先刷几百道2000+的题再说 ---某神 题目 E F 赛时是否尝试 × × tag math bitmask 难度 2000 2400 状态 ? √ 解 E 待定 F 传送门 第一次接触状态压缩dp的题.这道题转换问题的思路非常巧妙. 原问题: 已知: 一个字符串,可进行不超过一次操作 操作限定: 选择某个子串,使其在原串中翻转 目的:使原串的特征值最大 串的特征值:串任意没有重复字符的子串,其包含字符的种类数 问题的转换: 首先选定一个子串a,之后再找到另一个子串b,使得a

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i