2017 ACM/ICPC 广西邀请赛 题解

题目链接  Problems

HDOJ上的题目顺序可能和现场比赛的题目顺序不一样,

我这里的是按照HDOJ的题目顺序来写的。

Problem 1001

签到

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)

typedef long long LL;

LL n, f[31];
int ans;

int main(){

	f[1] = 1LL;
	for (LL i = 2; i <= 15; ++i){
		f[i] = 1LL;
		rep(j, 1, i) f[i] *= i;
	}

	while (~scanf("%lld", &n)){
		ans = 0;
		rep(i, 1, 15) if (f[i] <= n) ans = max(ans, i);
		printf("%d\n", ans);
	}	

	return 0;
}

Problem 1002

这道题的话,其实一个点上是可以有多种颜色的

因为最多只有51种颜色,所以我们维护51棵线段树即可。

我们对y坐标建立线段树,对于每个y,我们只需要最小的x在哪里即可。

因为他的询问的x坐标下界总是1,那么我们只要看看y1到y2的最小值是否小于等于给定的x即可。

询问的时候做51次子询问就可以了。

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)

typedef long long LL;

const int N = 2e6 + 10;

int X, c, d, x, y, op, ans, ret, cnt;
int root[53];
int l[N], r[N], v[N];

void update(int &i, int L, int R, int x, int val){
	if (i == 0){
		i = ++cnt;
		v[i] = val;
	}

	v[i] = min(v[i], val);
	if (L == R) return;

	int mid = (L + R) >> 1;
	if (x <= mid) update(l[i], L, mid, x, val);
	else update(r[i], mid + 1, R, x, val);
}

void query(int i, int L, int R){
	if (ret || i == 0) return;
	if (c <= L && R <= d){
		if (v[i] <= X) ret = 1;
		return;
	}

	int mid = (L + R) >> 1;
	if (c <= mid) query(l[i], L, mid);
	if (d >  mid) query(r[i], mid + 1, R);
}	

int main(){

	while (true){
		scanf("%d", &op);
		if (op == 3) break;
		if (op == 0){
			rep(i, 1, cnt) l[i] = r[i] = 0;
			memset(root, 0, sizeof root);
			cnt = 0;
		}

		if (op == 1){
			scanf("%d%d%d", &x, &y, &c);
			update(root[c], 1, 1000000, y, x);
		}

		if (op == 2){
			scanf("%d%d%d", &X, &c, &d);
			ans = 0;
			rep(i, 0, 50){
				ret = 0;
				query(root[i], 1, 1000000);
				ans += ret;
			}
			printf("%d\n", ans);
		}
	}

	return 0;
}

Problem 1003

我们对于每一条边,找到所有包含这条边的三元环,个数计为x

然后这对答案的贡献就是$C_{x}^{2}$

判断两点之间是否有边的时候要手写哈希才能过

#include <bits/stdc++.h>

const int N = 2e5 + 10;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)

namespace Hashmap{
	const int P = 1000007, seed = 2333;
	int u[N << 2], v[N << 2], nt[N << 2];
	int head[P], inum;
	inline void init(){
		inum = 0;
		memset(u, 0, sizeof u);
		memset(v, 0, sizeof v);
		memset(nt, 0, sizeof nt);
		memset(head, 0, sizeof head);
	}

	inline void add(int _u, int _v){
		int t = (_u * seed + _v) % P;
		u[++inum] = _u, v[inum] = _v, nt[inum] = head[t], head[t] = inum;
	}

	inline bool query(int _u, int _v){
		int t = (_u * seed + _v) % P;
		for (int p = head[t]; p; p = nt[p])
			if (u[p] == _u && v[p] == _v) return 1;
		return 0;
	}
}

using namespace std;
using namespace Hashmap;

typedef long long LL;

vector<int> a[N];

struct ss{ int x, y; } e[N];

int n, m;

int main(){

	while (~scanf("%d%d",&n, &m)){
		init();
		rep(i, 1, n) a[i].clear();
		rep(i, 1, m){
			int x, y;
			scanf("%d%d", &x, &y);
			e[i].x = x;
			e[i].y = y;
			a[x].push_back(y);
			a[y].push_back(x);
			add(x, y);
			add(y, x);
		}

		LL ans = 0;
		rep(i, 1, m){
			int x = e[i].x, y = e[i].y;
			if (a[e[i].y].size() < a[e[i].x].size()) swap(x, y);
			LL tot = 0;
			for (auto u: a[x]) if (query(u, y))  tot++;
			ans += tot * (tot - 1) / 2;
		}

		printf("%lld\n", ans);
	}
	return 0;
}

Problem 1004

这题规律找了半天……

$f[n] = f[n - 1] + 5f[n - 2] + f[n - 3] - f[n - 4]$

然后矩阵加速下就可以了

#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b)	for (int i(a); i <= (b); ++i)
#define dec(i, a, b)	for (int i(a); i >= (b); --i)
#define MP		make_pair
#define fi		first
#define se		second

typedef long long LL;

const LL mod = 1e9 + 7;

struct Matrix{
	LL arr[6][6];
} f, unit, a;

LL m, k;
int n;

Matrix Add(Matrix a, Matrix b){
	Matrix c;
	rep(i, 1, n) rep(j, 1, n){
		c.arr[i][j] = (a.arr[i][j] + b.arr[i][j]) % mod;
	}
	return c;
}

Matrix Mul(Matrix a, Matrix b){
	Matrix c;
	rep(i, 1, n) rep(j, 1, n){
		c.arr[i][j] = 0;
		rep(k, 1, n) (c.arr[i][j] += (a.arr[i][k] * b.arr[k][j] % mod)) %= mod;
	}
	return c;
}

Matrix Pow(Matrix a, LL k){
	Matrix ret(unit); for (; k; k >>= 1, a = Mul(a, a)) if (k & 1) ret = Mul(ret, a); return ret;
}

int main(){

	n = 4;

	memset(f.arr, 0, sizeof f.arr);
	memset(a.arr, 0, sizeof a.arr);
	memset(unit.arr, 0, sizeof unit.arr);

	rep(i, 1, n) unit.arr[i][i] = 1;
	f.arr[1][1] = 1;
	f.arr[1][2] = 5;
	f.arr[1][3] = 1;
	f.arr[1][4] = 1000000006;
	f.arr[2][1] = 1;
	f.arr[3][2] = 1;
	f.arr[4][3] = 1;

	a.arr[1][1] = 36;
	a.arr[2][1] = 11;
	a.arr[3][1] = 5;
	a.arr[4][1] = 1;

	while (~scanf("%lld", &m)){
		if (m == 1LL){ puts("1");  continue;}
		if (m == 2LL){ puts("5");  continue;}
		if (m == 3LL){ puts("11"); continue;}
		if (m == 4LL){ puts("36"); continue;}
		if (m == 5LL){ puts("95"); continue;}

		k = m - 4;

		Matrix b = Pow(f, k);
		Matrix c = Mul(b, a);
		printf("%lld\n", c.arr[1][1]);
	}

	return 0;
}

Problem 1005

Problem 1006

Problem 1007

Problem 1008

Problem 1009

Problem 1010

Problem 1011

Problem 1012

时间: 2025-01-16 00:09:58

2017 ACM/ICPC 广西邀请赛 题解的相关文章

2017 ICPC 广西邀请赛1004 Covering

Covering Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 187    Accepted Submission(s): 107 Problem Description Bob's school has a big playground, boys and girls always play games here after sch

hdu6206 Apple 2017 ACM/ICPC Asia Regional Qingdao Online

地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6206 题目: Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 530    Accepted Submission(s): 172 Problem Description Apple is Taotao's favouri

2017 ACM/ICPC Asia Regional Shenyang Online spfa+最长路

transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/132768 K (Java/Others)Total Submission(s): 1496    Accepted Submission(s): 723 Problem Description Kelukin is a businessman. Every day, he travels arou

2017 acm icpc 沈阳(网络赛)5/12 题解

比赛中较...能做的5道题 hdoj6195. cable cable cable 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6195 题目大意 : 略 规律 : 答案 = k+(m-k)*k hdoj6198. number number number 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6198 题目大意  : 给你一个整数n.问你n个斐波那契数(可重复)不能构成哪些数,输出

2017 ICPC 广西邀请赛1005 CS Course

CS Course Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 0    Accepted Submission(s): 0 Problem Description Little A has come to college and majored in Computer and Science. Today he has learne

2017 ACM/ICPC Asia Regional Shenyang Online E number number number 题解

分析: 当n=1时ans=4=f(5)-1; n=2,ans=12=f(7)-1; n=3,ans=33=f(9)-1; 于是大胆猜想ans=f(2*k+3)-1. 之后用矩阵快速幂求解f(n)即可,O(logn). AC code: 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 typedef vector<ll> vec; 5 typedef vector<vec>

HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting

Brute Force Sorting Time Limit: 1 Sec  Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=6215 Description Beerus needs to sort an array of N integers. Algorithms are not Beerus's strength. Destruction is what he excels. He can destr

hdu6201 transaction transaction transaction(from 2017 ACM/ICPC Asia Regional Shenyang Online)

最开始一直想着最短路,不过看完题解后,才知道可以做成最长路.唉,还是太菜了. 先上图: 只要自己添加两个点,然后如此图般求最长路即可,emmm,用SPFA可以,迪杰斯特拉也可以,或者别的都ok,只要通过一次即可. 上代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <vector> 4 #include <queue> 5 #include <algorithm> 6 using na

2017 acm / icpc shenyang 双十一单身狗温馨重现赛

上午做实验老师看错时间来晚了,20与非门一侧坏掉..于是做完实验就,光荣迟到了!!!QAQ... 一开始..看B题...喵喵喵??? J题...窝只会暴力..算了算了.. 刷新~ I题AC ratio 好像还可以!戳进去一看,a+b+c+d...一克斯Q斯咪?哭叽叽写了个大数加法,piapiapia乱敲一气竟然没崩,AC~~~是个好开头吖有木有~o(* ̄▽ ̄*)ブ~ K题就是小兔子跳啊跳~piapiapia求和然后选择一下从哪一端起跳,紫欣sama1A~ L题一开始对题意有误解,看懂样例之后就发