第四届辽宁省大学生程序设计竞赛

A - 欢迎来到辽宁省赛

#include <bits/stdc++.h>

using namespace std;


int main(){
	cout << "27\n";
	return 0;
}

B - 胜率

首先如果参加了 10000 局比赛,则一定会有当前胜率的情况出现。

所以我们枚举一下分母就好了

#include <bits/stdc++.h>

using namespace std;

int main(){
	double A;
	cin >> A, A /= 100.0;
	for(int x , y = 1; y <= 100000; y ++) {
		x = A * y;
		for(int i = max(x - 10 , 0) , v; i <= min(x + 10 , y); i ++){
			v = (double(i) / double(y) * 1e5 + 5) / 10;
			//v /= 1000;
			if(abs(A * 100 - double(v) / 100) == 0) {
				cout << y << "\n";
				return 0;
			}
		}
	}
	return 0;
}

C - 连环爆炸

先删掉所有无法被炸死的怪,然后贪心的删除爆炸伤害高的。

#include <bits/stdc++.h>

using namespace std;

using pii = pair<int,int>;

bool cmp(const pii &x , const pii &y) {
	if(x.second != y.second) return x.second < y.second;
	return x.first < y.first;
}

int main() {
	int n, res = 0, sum = 0;
	cin >> n;
	vector<pii> f(n);
	for(auto &[a,b] : f) cin >> a >> b , sum += b;

	{ // 删掉无法被炸死的
		vector<pii> g;
		queue<int> q;
		q.push(0);
		for(auto it : f){
			if( it.first > sum - it.second) res ++, q.back() += it.second;
			else g.push_back(it);
		}
		f = move(g);
		while(not q.empty()) {
			int x = q.front();
			q.pop();
			vector<pii> g;
			for(auto &it : f){
				it.first -= x;
				if(it.first <= 0) q.push(it.second);
				else g.push_back(it);
			}
			f = move(g);
		}
	}
	while(not f.empty()) {
		res ++;
		queue<int> q;
		sort(f.begin(), f.end(), cmp);
		q.push(f.back().second), f.pop_back();
		while(not q.empty()) {
			int x = q.front();
			q.pop();
			vector<pii> g;
			for(auto &it : f){
				it.first -= x;
				if(it.first <= 0) q.push(it.second);
				else g.push_back(it);
			}
			f = move(g);
		}
	}
	cout << res << "\n";

	return 0;
}

F - 隔板与水槽

枚举中间点,贪心

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64


using vi = vector<int>;


i32 main(){
	int n;
	cin >> n;
	vi h(n + 1);
	for(int i = 1 ; i <= n; i ++)
		cin >> h[i];
	int res = 0;
	for(int mid = 2 , l , r ; mid < n ; mid ++) {
		l = r = 0;
		for(int i = 1; i < mid ; i ++)
			l = max(l, (mid - i) * min(h[i], h[mid]));
		for(int i = mid + 1; i <= n; i ++) 
			r = max(r, (i - mid) * min(h[i], h[mid]));
		res = max(res, l + r);
	}
	cout << res << "\n";
	return 0;
}

H - 取石子

打表找规律,发现结果之和奇偶有关,因为 Alice 和 Bob 都只能取奇数个。

#include <bits/stdc++.h>

using namespace std;

void solve() {
	int a,b,c;cin >> a >> b >> c;

	a %= 2,b %= 2,c %= 2;

	int ans = (a << 2) + (b << 1) + (c << 0);
	if (ans % 2) cout << "Alice\n";
	else
		cout << "Bob\n";

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int TC;
	
	for(cin >> TC; TC; TC --)
		solve();
	
	return 0;
}

M - 让二追三

每个位置出现复合条件字符串的是独立的。

#include <bits/stdc++.h>

using namespace std;


using i32 = int32_t;

#define int long long

const int mod = 1e9+7;

int power(int x, int y) {
    int ans = 1;
    while(y) {
        if(y & 1) ans = ans * x % mod;
        x = x * x % mod, y /= 2;
    }
    return ans;
}

int inv(int x) {
    return power(x, mod - 2);
}

void solve(){
    int n, a, b;
    cin >> a >> b >> n;
    if(n < 5) {
        cout << "0\n";
        return;
    }
    int p = a * inv(b) % mod;
    p = (1 - p + mod ) % mod * (1 - p + mod) % mod * p % mod * p %mod * p % mod; 
    cout << (n - 4) * p % mod << "\n";
}

i32 main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int TC;
    for(cin >> TC; TC; TC -- )
        solve();
	return 0; 
}

L - 区间与绝对值

队友写的莫队

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int N = 1e5 + 7;

template<class T>
struct Fenwick{
	vector<T> c;
	int n;
	Fenwick(int _n){
		n = _n;
		c.resize(n + 1);
	}
	T sum(int x){
		T res = 0;
		for (; x ; x -= x & (-x)){
			res += c[x];
		}
		return res;
	}
	void modify(int x,T d){
		for (; x <= n ;x += x & (-x)){
			c[x] += d;
		}
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n,m;cin >> n >> m;

	vector<int> a(n + 1);
	vector<ll> res(m + 1);

	Fenwick<ll> pre(N);
	Fenwick<ll> siz(N);

	for (int i = 1;i <= n;i++){
		cin >> a[i];
	}

	vector<array<int,3>> qury;

	for (int i = 1;i <= m;i++){
		int l,r;cin >> l >> r;
		qury.push_back({l,r,i});
	}

	int B = 500;

	sort(qury.begin(),qury.end(),[&](array<int,3> a,array<int,3> b){
		int c = a[0] / B;
		if (a[0] / B != b[0] / B) return a[0] / B < b[0] / B;
		return c % 2 ? a[1] < b[1] : a[1] > b[1];
	});

	int l = 1,r = 0;
	ll ans = 0;

	auto add = [&](int x)->void{
		ll p = a[x] * (siz.sum(a[x])) - pre.sum(a[x]);
		ll s = (pre.sum(1e5) - pre.sum(a[x])) - (siz.sum(1e5) - siz.sum(a[x])) * a[x];
		ans += p + s;
		pre.modify(a[x],a[x]);
		siz.modify(a[x],1);
		//cout << ans << endl;
	};

	auto del = [&](int x)->void{
		ll p = a[x] * (siz.sum(a[x])) - pre.sum(a[x]);
		ll s = (pre.sum(1e5) - pre.sum(a[x])) - (siz.sum(1e5) - siz.sum(a[x])) * a[x];
		ans -= p + s;
		siz.modify(a[x],-1);
		pre.modify(a[x],-a[x]);
	};

	for (int i = 0;i < m;i++){
		while (r < qury[i][1]) r++,add(r);
		while (l > qury[i][0]) l--,add(l);
		while (r > qury[i][1]) del(r),r--;
		while (l < qury[i][0]) del(l),l++;
		res[qury[i][2]] = ans;
	}


	for (int i = 1;i <= m;i++){
		cout << 2 * res[i] << "\n";
	}


	return 0;
}
posted @ 2024-05-14 17:50  PHarr  阅读(22)  评论(0编辑  收藏  举报