牛可乐发红包脱单ACM赛$

题目链接

A:统计两颗生成树有多少条不相同的边即可

#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP make_pair
#define fi first
#define se second 
using namespace std;
int N;
map<Pair, bool> mp;
int main() {
	scanf("%d", &N);
	for(int i = 1, x, y; i <= N - 1; i++) {
		scanf("%d %d", &x, &y);
		mp[MP(x, y)] = 1; mp[MP(y, x)] = 1;
	}
	int ans = 0;
	for(int i = 1, x, y; i <= N - 1; i++) {
		scanf("%d %d", &x, &y);
		if(mp.find(MP(x, y)) == mp.end() && mp.find(MP(y, x)) == mp.end()) ans++;
	}
	printf("%d", ans);
	return 0;
}

B题:

暴力前几项 然后oeis。。。

#include<iostream>
#include<cstdio>
#define LL long long 
const LL mod = 100000007, inv = 50000004;
using namespace std;
inline LL read() {
    char c = getchar(); LL x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
LL N;
LL f(LL a, LL p) {
    LL base = 1;
    while(p) {
        if(p & 1) base = (base * a) % mod;
        a = (a * a) % mod; p >>= 1;
    }
    return base % mod;
}
int main() {
    cin >> N;
   	LL ans = ((-3 * f(3, N) + mod) % mod + f(4, N) - 1 + mod) * inv + f(2, N - 1) * 3 % mod;
    cout << ans % mod << endl;
    return 0;
}

C题:

不会写。。。

#include<bits/stdc++.h>
#define LL long long 
using namespace std;
const LL MAXN = 1e5 + 10;
LL T, N;
LL a[MAXN], q[MAXN];
LL solve() {
    LL h = 1, t = 0, ans = 0, sum = 0;
    for(LL i = 1; i <= N; i++) {
        while(h <= t && a[i] > a[q[t]]) sum -= a[q[t]] * (q[t] - q[t - 1]), t--;
        q[++t] = i;
        ans += a[i] * (q[t] - q[t - 1]) + sum;
        sum += a[i] * (q[t] - q[t - 1]);
    }
    return ans;
}
int main() {
    scanf("%lld", &T);
    while(T--) {
        scanf("%lld", &N);
        for(LL i = 1; i <= N; i++) scanf("%lld", &a[i]);
        LL ans = solve();
        for(LL i = 1; i <= N; i++) a[i] = -a[i];
        LL ans2 = solve();
        cout << ans + ans2 << endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值