其他分享
首页 > 其他分享> > Codeforces Global Round 15 B、D两题

Codeforces Global Round 15 B、D两题

作者:互联网

B题

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 100;
int main(){
    ios::sync_with_stdio(false);
    int t, n;
    cin >> t;
    while(t--){
        cin >> n;
        vector<vector<int>> a(n, vector<int>(5));
        for(int i=0;i<n;i++){
            for(int j=0;j<5;j++){
                cin >> a[i][j];
            }
        }
        int id = 0;
        for(int i=1;i<n;i++){
            int m = 0;
            for(int j=0;j<5;j++){
                m += (a[i][j] < a[id][j]);
            }
            if(m >= 3){
                id = i;
            }
        }
        for(int i=0;i<n;i++){
            int m = 0;
            for(int j=0;j<5;j++){
                m += (a[i][j] < a[id][j]);
            }
            if(m >= 3){
                id = -2;
                break;
            }
        }
        cout << id + 1 << '\n';
    }
    return 0;
}

D题

给出了一个数组,问能否构造一个新的数组使得原来的数组的任意一项都能由新数组的某两项作差得到

#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 100;
int Data[MAXN];
int main(){
    ios::sync_with_stdio(false);
    int n, t;
    cin >> t;
    while(t--){
        cin >> n;
        for(int i=0;i<n;i++) cin >> Data[i];
        int p = 1;
        bool found = false;
        for(int i=0;i<n;i++) p *= 3;
        for(int s=1;s<p;s++){
            int tmp = s;
            int sum = 0;
            for(int i=0;i<n;i++){
                int m = tmp % 3;
                if(m == 1) sum += Data[i];
                if(m == 2) sum -= Data[i];
                tmp /= 3;
            }
            if(sum == 0){
                found = true;
                break;
            }
        }
        cout << (found ? "YES" : "NO") << '\n';
    }
    return 0;
}

标签:15,int,Global,cin,a3,b1,两题,b3,include
来源: https://blog.csdn.net/roadtohacker/article/details/119101479