csust-8.10组队训练- 第九届福建省大学生程序设计竞赛-重现赛

目录

 

A - Uint47 calculator

B - Human life

C - Alice and Bob

D - Number theory

E - Traffic jam

F - Prefix

G - IoU

H - Chosen by god

I - Necklace

J - Mind control

K - Book


A - Uint47 calculator

 FZU - 2294 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2294

//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <map>
using namespace std;
#define IOS ios::sync_with_stdio(false)
#define ll long long
const int mac = 1e5 + 10;
const ll mod = 140737488355328;
const ll ds = 1073741824;
string s;
map<string, int>q;
ll a[mac];
ll mul(ll x, ll y);
int main()
{
	IOS;
	string p;
	int num = 0;
	ll x;
	string s1, s2;
	while (cin >> p) {
		if (p == "def") {
			cin >> s;
			cin >> x;
			q[s] = ++num;
			a[num] = x;
			cout << s << " = " << a[num] << endl;
		}
		else if (p == "add") {
			cin >> s1 >> s2;
			a[q[s1]] = (a[q[s1]] + a[q[s2]]) % mod;
			cout << s1 << " = " << a[q[s1]] << endl;
		}
		else if (p == "sub") {
			cin >> s1 >> s2;
			a[q[s1]] = (a[q[s1]] - a[q[s2]]+mod) % mod;
			cout << s1 << " = " << a[q[s1]] << endl;
		}
		else if (p == "mul") {
			cin >> s1 >> s2;
			a[q[s1]] = mul(a[q[s1]], a[q[s2]]);
			cout << s1 << " = " << a[q[s1]] << endl;
		}
		else if (p == "div") {
			cin >> s1 >> s2;
			a[q[s1]] = a[q[s1]] / a[q[s2]];
			cout << s1 << " = " << a[q[s1]] << endl;
		}
		else if (p == "mod") {
			cin >> s1 >> s2;
			a[q[s1]] = a[q[s1]] % a[q[s2]];
			cout << s1 << " = " << a[q[s1]] << endl;
		}
	}
	return 0;
}
ll mul(ll x, ll y)
{
	ll ans = 0;
	while (y)
	{
		if (y & 1) ans = (ans + x) % mod;
		y >>= 1;
		x = (x + x) % mod;
	}
	return ans;
}

B - Human life

 FZU - 2295 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2295

//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define ll long long
const int inf = 4e8 + 10;
const int mac = 1e5 + 10;
int s, t, dis[mac], head[mac], num = 0, cur[mac];
struct Edge
{
	int to, w, next;
};
Edge eg[mac << 1];
int cost[mac], earn[mac], vis[mac];
struct node
{
	int f, e;
}a[mac];
vector<int>g[mac], gg[mac];
void add(int u, int v, int w);
int bfs();
int dfs(int u, int flow);
int dinic(int n);
int main()
{
	IOS;
	int tt, n, m, k, x, np;
	cin >> tt;
	while (tt--) {
		cin >> n >> m >> k;
		for (int i = 1; i <= max(n, m); i++) g[i].clear(), gg[i].clear();
		for (int i = 1; i <= n; i++) {
			cin >> cost[i] >> np;
			for (int j = 1; j <= np; j++) {
				cin >> x;
				g[i].push_back(x);
			}
		}
		for (int i = 1; i <= m; i++) {
			cin >> earn[i] >> np;
			for (int j = 1; j <= np; j++) {
				cin >> x;
				gg[i].push_back(x);
				for (int k = 0; k < g[x].size(); k++) {
					int v = g[x][k];
					gg[i].push_back(v);
				}
			}
		}
		int ans = 0;
		for (int i = 1; i <= k; i++) cin >> a[i].f >> a[i].e;
		s = 0, t = n + m + 1;
		for (int sta = 0; sta < (1 << k); sta++) {
			memset(vis, 0, sizeof(vis));
			for (int i = 0; i < k; i++) {
				if (vis[a[i+1].f] && vis[a[i+1].e]) continue;
				if ((sta >> i) & 1) vis[a[i+1].e] = 1;
				else vis[a[i+1].f] = 1;
			}
			memset(head, -1, sizeof(head));
			num = 0; 
			int sum = 0;
			for (int i = 1; i <= m; i++) {
				if (vis[i]) continue;
				sum += earn[i];
				add(s, i, earn[i]); add(i, s, 0);
				for (int j = 0; j < gg[i].size(); j++) {
					int v = gg[i][j];
					add(i, v + m, inf); add(v + m, i, 0);
				}
			}
			for (int i = 1; i <= n; i++) {
				add(i + m, t, cost[i]); add(t, i + m, 0);
				for (int j = 0; j < g[i].size(); j++) {
					int v = g[i][j];
					add(i + m, v + m, inf); add(v + m, i + m, 0);
				}
			}
			int flow = dinic(t);
			ans = max(ans, sum - flow);
		}
		cout << ans << endl;
	}
	return 0;
}
void add(int u, int v, int w)
{
	eg[num].to = v; eg[num].w = w;
	eg[num].next = head[u]; head[u] = num++;
}
int dinic(int n)
{
	int sum = 0;
	while (bfs()) {
		for (int i = 0; i <= n; i++)
			cur[i] = head[i];
		sum += dfs(s, inf);
	}
	return sum;
}
int bfs()
{
	queue<int>q;
	memset(dis, 0, sizeof(dis));
	dis[s] = 1;
	q.push(s);
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int i = head[u]; i != -1; i = eg[i].next) {
			int v = eg[i].to;
			if (eg[i].w > 0 && dis[v] == 0) {
				dis[v] = dis[u] + 1;
				if (v == t) return 1;
				q.push(v);
			}
		}
	}
	return 0;
}
int dfs(int u, int flow)
{
	if (u == t) return flow;
	int sum = 0, x = 0;
	for (int i = cur[u]; i != -1; i = eg[i].next) {
		int v = eg[i].to;
		if (eg[i].w > 0 && dis[v] == dis[u] + 1) {
			x = dfs(v, min(flow - sum, eg[i].w));
			eg[i].w -= x;
			eg[i ^ 1].w += x;
			if (eg[i].w) cur[u] = i;
			sum += x;
			if (sum == flow) return flow;
		}
	}
	if (sum == 0) dis[u] = 0;
	return sum;
}

C - Alice and Bob

FZU - 2296

题目链接http://acm.fzu.edu.cn/problem.php?pid=2296

D - Number theory

 FZU - 2297 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2297

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 7;
long long mod;
struct node
{
	int  l, r;
	int val;
}e[maxn << 2];

void build(int rt, int l, int r) {
	e[rt].l = l, e[rt].r = r;
	e[rt].val = 1;
	if (l == r) return;
	int mid = (l + r) >> 1;
	build(rt << 1, l, mid);
	build(rt << 1 | 1, mid + 1, r);
}

void update(int rt, int l, int val) {
	if (e[rt].l == e[rt].r)
	{
		e[rt].val = val;
		return;
	}
	int mid = (e[rt].l + e[rt].r) >> 1;
	if (l <= mid) update(rt << 1, l, val);
	else update(rt << 1 | 1, l, val);
	e[rt].val = 1ll * e[rt << 1].val * 1ll * e[rt << 1 | 1].val % mod;
}

int main(int argc, char const* argv[])
{
	int t;
	scanf("%d", &t);
	while (t--) {
		int n, m;
		scanf("%d %d", &n, &m);
		build(1, 1, maxn);
		mod = m;
		for (int i = 1; i <= n; i++) {
			char s[2];
			int x;
			scanf("%s %d", s, &x);
			if (s[0] == 'M') {
				update(1, i, x);
				printf("%d\n", e[1].val);
			}
			else {
				update(1, x, 1);
				printf("%d\n", e[1].val);
			}
		}
	}
	return 0;
}

E - Traffic jam

 FZU - 2298 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2298

//#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define ll long long
#define IOS ios::sync_with_stdio(false)
const int mac = 5e5 + 10;
const ll inf = 1e16 + 10;
struct node
{
	int to, next;
	ll w;
};
struct node1
{
	int id;
	ll d;
	bool operator < (const node1& a)const {
		return d > a.d;
	}
};
node eg[mac << 1];
int num = 0, head[mac], vis[mac], a[mac];
ll dis[mac];
void init(int n);
void add(int u, int v, int w);
void Dij(int s);
int main()
{
	IOS;
	int n, m, s;
	int tt, t;
	cin >> tt;
	while (tt--) {
		int n, m;
		cin >> n >> m;
		init(n);
		for (int i = 1; i <= n; i++) cin >> a[i];
		for (int i = 1; i <= m; i++) {
			int u, v, w;
			cin >> u >> v >> w;
			add(u, v, w); add(v, u, w);
		}
		cin >> s >> t;
		Dij(s);
		cout << dis[t] << endl;
	}
	return 0;
}
void init(int n)
{
	for (int i = 1; i <= n; i++) dis[i] = inf;
	memset(head, -1, sizeof(head));
	num = 0;
}
void add(int u, int v, int w)
{
	eg[++num].to = v; eg[num].w = w; eg[num].next = head[u];
	head[u] = num;
}
void Dij(int s)
{
	memset(vis, 0, sizeof(vis));
	dis[s] = 0;
	priority_queue<node1>q;
	node1 f;
	f.id = s; f.d = 0;
	q.push(f);
	while (!q.empty()) {
		node1 now = q.top();
		q.pop();
		int u = now.id;
		if (vis[u]) continue;
		vis[u] = 1;
		int x = now.d / a[u];
		if (x & 1) now.d = (x + 1) * a[u];
		for (int i = head[u]; i != -1; i = eg[i].next) {
			int v = eg[i].to, w = eg[i].w;
			if (dis[v] > now.d + w) {
				dis[v] = now.d + w;
				node1 f;
				f.id = v; f.d = dis[v];
				q.push(f);
			}
		}
	}
}

F - Prefix

FZU - 2299

题目链接http://acm.fzu.edu.cn/problem.php?pid=2299

G - IoU

 FZU - 2300 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2300

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int x1, y1, w1, h1, x2, y2, w2, h2;
int main()
{
    int t;
    cin >> t;
    while (t--)
    {
        cin >> x1 >> y1 >> w1 >> h1;
        cin >> x2 >> y2 >> w2 >> h2;
        int sum; 
        if(min(x1+w1, x2+w2) - max(x1, x2) > 0 && min(y1+h1, y2+h2) - max(y1, y2) > 0)
        sum = (min(x1 + w1, x2 + w2) - max(x1, x2))
            * (min(y1 + h1, y2 + h2) - max(y1, y2));
        else 
            sum = 0;
        double ans;
        if(w1 * h1 + w2 * h2 - sum > 0)
            ans = (double)sum / (w1 * h1 + w2 * h2 - sum);
        else 
            ans = 0;
        printf("%.2f\n", ans);
    }
    return 0;
}

H - Chosen by god

 FZU - 2301 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2301

//#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
using namespace std;
const int mac = 2e5 + 10;
#define IOS ios::sync_with_stdio(false)
#define ll long long
int c[1200][1200];
const int mod = 1e9 + 7;
ll cc(ll a, ll b) {
	ll ans = 1;
	a = a % mod;
	while (b > 0) {
		if (b % 2 == 1)
			ans = (ans * a) % mod;
		b = b / 2;
		a = (a * a) % mod;
	}
	return ans;
}
int main()
{
	IOS;
	memset(c, 0, sizeof(c));
	for (int i = 0; i <= 1100; i++) {
		c[i][0] = 1;
		for (int j = 1; j <= i; j++)
			c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
	}
	int t, n, m;
	cin >> t;
	while (t--) {
		cin >> n >> m;
		ll sum = 0;
		ll tot = cc(2ll, (ll)n);
		for (int i = m; i <= n; i++) sum = (sum + c[n][i]) % mod;
		ll ans = (sum * cc(tot, mod - 2)) % mod;
		cout << ans << endl;
	}
	return 0;
}

I - Necklace

FZU - 2302

题目链接http://acm.fzu.edu.cn/problem.php?pid=2302

J - Mind control

 FZU - 2303 

题目链接http://acm.fzu.edu.cn/problem.php?pid=2303

K - Book

FZU - 2304

题目链接http://acm.fzu.edu.cn/problem.php?pid=2304

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值