「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)

题意与分析

稍微复杂一些的思维题。反正这场全是思维题,就一道暴力水题(B)。

代码

#include <bits/stdc++.h>
#define MP make_pair
#define PB emplace_back
#define fi first
#define se second
#define ZERO(x) memset((x), 0, sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define rep(i, a, b) for (repType i = (a); i <= (b); ++i)
#define per(i, a, b) for (repType i = (a); i >= (b); --i)
#define QUICKIO                      ios::sync_with_stdio(false);     cin.tie(0);                      cout.tie(0);
using namespace std;
using ll=long long;
using repType=int;

int main()
{
    int n; cin>>n;
    vector<int> vec;
    rep(i,1,n)
    {
        int tmp; cin>>tmp; vec.PB(tmp);
    }
    if(n==1)
    {
        if(vec[0]==0) {cout<<"YES"<<endl; cout<<0<<endl;}
        else cout<<"NO"<<endl;
    }
    else
    {
        if(vec[n-1]==1) cout<<"NO"<<endl;
        else if(vec[n-1]==0 && vec[n-2]==1)
        {
            cout<<"YES"<<endl;
            rep(i,0,n-1)
            {
                if(i!=0) cout<<"->";
                cout<<vec[i];
            }
            cout<<endl;
        }
        else // 0 0
        {
            rep(i,0,n-3)
            {
                if(vec[i]==0)
                {
                    cout<<"YES"<<endl;
                    rep(j,0,i-1)
                    {
                        if(j!=0) cout<<"->";
                        cout<<vec[j];
                    }
                    if(i-1>=0) cout<<"->";
                    cout<<"(0->(";
                    rep(j,i+1,n-3)
                    {
                        cout<<vec[j]<<"->";
                    }
                    cout<<"0))->0"<<endl;
                    return 0;
                }
            }
            cout<<"NO"<<endl;
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/samhx/p/cfr306d2e.html

时间: 2024-08-29 03:15:10

「日常训练」Brackets in Implications(Codeforces Round 306 Div.2 E)的相关文章

「日常训练」Regular Bridge(Codeforces Round 306 Div.2 D)

题意与分析 图论基础+思维题. 代码 #include <bits/stdc++.h> #define MP make_pair #define PB emplace_back #define fi first #define se second #define ZERO(x) memset((x), 0, sizeof(x)) #define ALL(x) (x).begin(),(x).end() #define rep(i, a, b) for (repType i = (a); i &

「日常训练」School Marks(Codeforces Round 301 Div.2 B)

题意与分析(CodeForces 540B) 代码 #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset((x), 0, sizeof(x)) #define

「日常训练」Ice Cave(Codeforces Round 301 Div.2 C)

题意与分析(CodeForces 540C) 这题坑惨了我....我和一道经典的bfs题混淆了,这题比那题简单. 那题大概是这样的,一个冰塔,第一次踩某块会碎,第二次踩碎的会掉落.然后求可行解. 但是这题...是冰塔的一层 也就是说,它只是个稍微有点限制的二维迷宫问题. 后面就好理解了,不过需要考虑下这种数据: 1 2 XX 1 1 1 1 这种数据答案是no.解决的方法可以考虑这样:分成两个数组来记录访问状态:vis数组和block数组. 代码 #include <queue> #inclu

DFS Codeforces Round #306 (Div. 2) B. Preparing Olympiad

题目传送门 1 /* 2 DFS: 排序后一个一个出发往后找,找到>r为止,比赛写了return : 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <cstring> 7 #include <cmath> 8 #include <algorithm> 9 #include <vector> 10 #include <map> 11 #include

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

Codeforces Round #306 (Div. 2) (ABCE题解)

比赛链接:http://codeforces.com/contest/550 A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and &

Codeforces Round #306 (Div. 2) D.E. 解题报告

D题:Regular Bridge 乱搞.构造 这题乱搞一下就行了.构造一个有桥而且每个点的度数都为k的无向图.方法很多,也不好叙述.. 代码如下: #include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <stack> #include <map> #include <algorithm> #define INF 0x

Codeforces Round #306 (Div. 2) (构造)

A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全,最后只能很蠢的暴力,把所有的AB和BA的位置求出来,能有一对AB和BA不重叠即可. 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 char a[100005]; 5 vector<int> ab; 6 vector<i

「日常训练」Bad Luck Island(Codeforces Round 301 Div.2 D)

题意与分析(CodeForces 540D) 代码 #include <iomanip> #include <iostream> #include <cstring> #include <algorithm> #include <vector> #define MP make_pair #define PB push_back #define fi first #define se second #define ZERO(x) memset((x