当前位置:   article > 正文

KYOCERA Programming Contest 2021(AtCoder Beginner Contest 200)D - Happy Birthday! 2_atcoder beginner contest 200 d - happy birthday! 2

atcoder beginner contest 200 d - happy birthday! 2

传送门

我们可以看出,B©序列的所有情况一共有2^n - 1种(就是每个数取或者不取),直接枚举肯定是不行。

再继续观察题目给出的条件,求和后要对200取模,也就是说取模后的结果有200种情况。我们所有序列的情况一共2^n - 1种,取极限情况,当前200种情况所得的结果都不相同时,第201种情况必定出现重复,因此只要情况总数超过200时必定有解。我们可以取n = 8(2 ^ 8-1 > 201)然后找到两种相同的情况即可。当n < 8 时,我们也可以采用同样的方法枚举。

不知道为什么开200的时候会越界,开300的时候就不会了。。。。。

#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;         
typedef pair<int, int> P;
 
const int maxn = 200 + 10;        
const int M_MAX = 10;
const int mod = 1e9 + 7;
const LL INF = 0x3f3f3f3f;    
const double eps = 1e-6;      

int n;
int arr[maxn];
vector<int> ans[300];

void out(vector<int> &t) {
    cout << t.size();
    for(auto i : t) {
        cout << " " << i;
    }
    cout << endl;
}

void solve() {
    cin >> n;
    for(int i = 0; i < n; i++) cin >> arr[i];
    int cnt = min(n, 8);
    for(int i = 0; i < 1 << cnt; i++) {
        LL sum = 0;
        vector<int> s;
        for(int j = 0; j < cnt; j++) {
            if(1 << j & i) {
                s.emplace_back(j + 1);
                sum += arr[j];
            }
        }
        sum %= 200;
        if(!ans[sum].empty()) {
            cout << "YES\n";
            out(ans[sum]);
            out(s);
            return ;
        }
        else {
            ans[sum] = s;
        }
    }
    cout << "NO\n";
}
 
int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/72719
推荐阅读
  

闽ICP备14008679号