zoukankan      html  css  js  c++  java
  • Codeforces Round #604 (Div. 2)D(构造)

    构造,枚举起点,如果一个序列成立,那么将它reverse依然成立,所以两个方向(从小到大或从大到小)没有区别,选定一个方向进行探测,直到探测不到以后回头,只要所给数据能成立,那么能探测进去就能探测出来,否则就不能构造。

     1 #define HAVE_STRUCT_TIMESPEC
     2 #include<bits/stdc++.h>
     3 using namespace std;
     4 int num[7];
     5 int sum;
     6 int main(){
     7     ios::sync_with_stdio(false);
     8     cin.tie(NULL);
     9     cout.tie(NULL);
    10     int a[7]={0};
    11     for(int i=1;i<=4;++i)
    12         cin>>a[i];
    13     for(int i=1;i<=4;++i){
    14         num[i]=a[i];
    15         sum+=num[i];
    16     }
    17     for(int i=1;i<=4;++i){
    18         for(int i=1;i<=4;++i)
    19             num[i]=a[i];
    20         vector<int>v;
    21         int now=i;
    22         for(int i=1;i<=sum;++i){
    23             if(!num[now])
    24                 break;
    25             --num[now];
    26             v.push_back(now-1);
    27             if(num[now+1])
    28                 ++now;
    29             else
    30                 --now;
    31         }
    32         if(v.size()==sum){
    33             cout<<"YES
    ";
    34             for(auto it:v)
    35                 cout<<it<<" ";
    36             return 0;
    37         }
    38     }
    39     cout<<"NO";
    40     return 0;
    41 }
    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    算法:记忆化搜索算法
    Ubuntu:命令行下浏览网页
    python:socket网络编程
    ACM:读入优化
    使用JDBC连接操作数据库
    Function题解
    csps模拟测试50反思
    模拟测试49
    阶段总结20190919
    NOIP模拟测试36考试反思
  • 原文地址:https://www.cnblogs.com/ldudxy/p/12046850.html
Copyright © 2011-2022 走看看