• Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)


    • 题意:给你两个正整数\(N\)\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不等于\(K\)\(S-K\),如果存在则输出YES,并且输出这个数组和\(K\),不存在则输出\(NO\).

    • 题解:这类题写多了其实就会发现基本上都是一连串1或2加上一个数来构造,这题也是如此.

      我们可以将这个数组构造为\(N-1\)\(1\)和一个\(S-N+1\),很明显,只要\((N-1,S-N+1)\)这个区间里面的元素个数\(>1\)即可.那么\(K\)只要取\(S-N\)就行了.

    • 代码:

      #include <iostream>
      #include <cstdio>
      #include <cstring>
      #include <cmath>
      #include <algorithm>
      #include <stack>
      #include <queue>
      #include <vector>
      #include <map>
      #include <set>
      #include <unordered_set>
      #include <unordered_map>
      #define ll long long
      #define fi first
      #define se second
      #define pb push_back
      #define me memset
      const int N = 1e6 + 10;
      const int mod = 1e9 + 7;
      using namespace std;
      typedef pair<int,int> PII;
      typedef pair<long,long> PLL;
       
      int n,s;
       
      int main() {
          ios::sync_with_stdio(false);cin.tie(0);
          cin>>n>>s;
       
          int cnt1=n-1; // 1的数目
          int cnt2=s-cnt1; //末位数字
          if(cnt1+1<cnt2){
              puts("YES");
              int tmp=cnt1;
               while(tmp--) printf("1 ");
               printf("%d\n",cnt2);
               printf("%d\n",cnt2-1);
          }
          else puts("NO");
       
          return 0;
      }
      
  • 相关阅读:
    Bootstrap 插件收集
    target和currentTarget
    微信小程序
    flex
    vue中使用icon和打包
    rem的使用
    vue中使用sass和compass
    vue父子组件传递参数
    weex
    常用软件&&网址
  • 原文地址:https://www.cnblogs.com/lr599909928/p/12905039.html
Copyright © 2020-2023  润新知