牛客第六场A,D,J

A

Singing Contest

A题模拟

#include<bits/stdc++.h>
using namespace std;
const int maxn = 17000;
vector<int>song[maxn];

int L[maxn];
int main() {
	int T, n, temp;
	cin >> T;
	for (int t = 1; t <= T; ++t) {
		scanf("%d", &n);
		for (int i = 1; i <= pow(2, n); ++i) {
			song[i].clear();
			for (int j = 1; j <= n; ++j) {
				scanf("%d", &temp);
				song[i].push_back(temp);
			}
			sort(song[i].begin(), song[i].end());
			L[i] = i;
		}
		for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= pow(2, n - i + 1); j += 2) {
				if (song[L[j]].back() > song[L[j + 1]].back()) {
					L[(j + 1) / 2] = L[j];
					song[L[j]].erase(lower_bound(song[L[j]].begin(), song[L[j]].end(), song[L[j + 1]].back()));
				}
				else {
					L[(j + 1) / 2] = L[j + 1];
					song[L[j + 1]].erase(lower_bound(song[L[j + 1]].begin(), song[L[j + 1]].end(), song[L[j]].back()));
				}
			}
		}
		printf("Case #%d: %d\n",t,L[1]);
	}
	return 0;
}

D

Bulbasaur

D题根据身体来选最大的权值的头

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=LONG_LONG_MAX;
int sum[100005];
int main(){
	int t;
	scanf("%d",&t);
	ll res=0;
	for(int i=1;i<=t;++i){
		int n,m,k;
		scanf("%d%d%d",&n,&m,&k);
		memset(sum,0,sizeof(sum));
		res=0;
		int a,b,c;
		for(int j=0;j<k;++j){
			scanf("%d%d%d",&a,&b,&c);
			sum[b]=max(sum[b],c);
		}
		for(int t=1;t<=m;++t){
			res+=sum[t];
		}
		cout<<"Case #"<<i<<": "<<res<<endl; 
	}
	
	return 0;
}

J

Heritage of skywalkert

根据随机数,互质数出现的概率为3*3/PI*PI,所以选前100大就行,其实10就能过

#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
const int MaxN = 2e7 + 10;
ull num[MaxN];
unsigned x, y, z, a, b, c; 
ull gcd(ull a, ull b){
    return b ? gcd(b, a % b) : a;
}
ull lcm(ull a, ull b){
    return a / gcd(a, b) * b;
}

unsigned tang(){
    unsigned t;
    x ^= x << 16;
    x ^= x >> 5;
    x ^= x << 1;
    t = x;
    x = y;
    y = z;
    z = t ^ x ^ y;
    return z;
}
bool cmp(unsigned x, unsigned y){return x > y;}
 
int main(){
    int t;
    int k = 1;
    scanf("%d", &t);
    for(int i=1;i<=t;++i){
        int n;
 		scanf("%d%llu%llu%llu",&n,&a,&b,&c);
        x = a;
        y = b;
        z = c;
        for(int i = 0; i < n; ++i)
            num[i] = tang();
        partial_sort(num, num + min(20, n), num + n, cmp);
        n = min(20, n);
        ull Max = 0;
        for(int i = 0; i < n; ++i)
            for(int j = i + 1; j < n; ++j)
                Max = max(Max, lcm(num[i], num[j]));
        cout << "Case #" << i << ": " << Max << endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/TDD_Master/article/details/81427580
今日推荐