模拟赛总结(1)

abc-mx / 2023-08-03 / 原文

一.题目解析

1.遗忘的来年花期

20%:

因为序列严格递增,所以直接 cout << 0; 即可。

100%:

注意不等号和 \(i\) 的范围,之后直接模拟。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const double pi = 3.1415926535897932385;
typedef long long ll;
typedef pair<int,int> Pr;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, eps=1e3+10, maxn=1e6+100;
template <typename T> inline void read(T &x) {
	x = 0;
	bool flag = false;
	char ch = getchar();
	while (ch < '0' || ch > '9') flag = ch == '-' ? true : false, ch = getchar();
	while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch & 15), ch = getchar();
	if(flag) x = -x;
}
template <typename T> inline void write(T x) {
	if(x<0) {
		putchar('-');
		x = -x;
	}
	if(x>9) write(x / 10);
	putchar(x % 10 + '0');
}
ll n, a[maxn]; 
ll cnt;
int main() {
//	freopen("flower.in", "r", stdin);
//	freopen("flower.out", "w", stdout);
    read(n);
    for (int i = 1;i <= n; ++i) {
    	read(a[i]);
	}
	for (int i = 2;i < n; ++i) {
    	if(a[i] >= a[i-1] && a[i] >= a[i+1]) {
    		cnt++;
		}
	}
	write(cnt);
	printf("\n");
	return 0;
}

2.意外爱上黄昏来临时

20%:

\(n=2\) 的数据范围,所以直接枚举 \(k\) 即可。

80%:

由于 \(y\) 可以被 \(x\) 用桶记录,所以不用枚举 \(y\)

100%:

用字符串维护每一列的 \(01\) 数(也可以说成二进制转换),用一个 unordered_map 就行。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const double pi = 3.1415926535897932385;
typedef long long ll;
typedef pair<int,int> Pr;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, eps=1e3+10, maxn=1e6+10;
template <typename T> inline void read(T &x) {
	x = 0;
	bool flag = false;
	char ch = getchar();
	while (ch < '0' || ch > '9') flag = ch == '-' ? true : false, ch = getchar();
	while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch & 15), ch = getchar();
	if(flag) x = -x;
}
template <typename T> inline void write(T x) {
	if(x<0) {
		putchar('-');
		x = -x;
	}
	if(x>9) write(x / 10);
	putchar(x % 10 + '0');
}
int n, m, a[1005][1005];
unordered_map<string, vector <int> > mp;
int main() {
    read(n), read(m);
	string s;
	s.resize(m);
	for (int i = 1;i <= m; i++)
		for (int j = 1;j <= n; j++)
			cin >> a[i][j];
	for (int i = 1;i <= n; i++) {
		for (int j = 1;j <= m; j++) s[j-1] = a[j][i];
		mp[s].push_back(i);
	}
	pair<int, int> p = make_pair(n+1, n+1);
	for(auto &it : mp)
		if(it.second.size() >= 2)
			p = min(p, make_pair(it.second[0], it.second[1]));
	if(p.first == n+1) puts("-1");
	else printf("%d %d", p.first, p.second);
	return 0;
}

3.星空分崩离析

目前只会暴力做法

20%:

预处理每个点的 \(dis(1, u)\) 和每对点的 \(dis(u, v)\),处理完排序。
然后暴力枚举满足 \(dis(1, u) > x\) 的所有对,统计 \(dis\)

4.死在二十四岁的自己

100%:

一看题和数据范围,发现是推式子的题,合并了一下题目中的式子,发现每个数都有一个贡献公式:max(x) - a[i] - 1
之后直接加一遍就行了。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const double pi = 3.1415926535897932385;
typedef long long ll;
typedef pair<int,int> Pr;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}, eps=1e3+10, maxn=1e6+10;
template <typename T> inline void read(T &x) {
	x = 0;
	bool flag = false;
	char ch = getchar();
	while (ch < '0' || ch > '9') flag = ch == '-' ? true : false, ch = getchar();
	while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch & 15), ch = getchar();
	if(flag) x = -x;
}
template <typename T> inline void write(T x) {
	if(x<0) {
		putchar('-');
		x = -x;
	}
	if(x>9) write(x / 10);
	putchar(x % 10 + '0');
}
ll n, a[maxn];
ll cnt;
ll sum;
int main() { 
    //freopen("resurrection.in", "r", stdin);
	//freopen("resurrection.out", "w", stdout);
    read(n);
    for (int i = 1;i <= n; ++i) {
    	read(a[i]);
	}
    sort(a+1,a+n+1);
    if (n == 1) {
		write(0);
		printf("\n");
		return 0;
	}
	else if (n == 2) {
		cnt = a[2] * 2 - (a[1] + a[2]) - 2;
		if (cnt > 0) {
			write(cnt);
			printf("\n");
		}
		else {
			write(0);
			printf("\n");
		}
	}
	else {
		for (int i = 1;i <= n; ++i) {
    		sum += a[i];
		}
		cnt = a[n] * n - sum - n; 
		if (cnt > 0) {
			write(cnt);
			printf("\n");
		}
		else {
			write(0);
			printf("\n");
		}
	}
	return 0;
}

这个题的数据多少有点问题,所有数都取到就 \(100\) 了。

二.总结

这次考的还行,主要是考场上灵光乍现想出 \(T2\)\(T4\) 的正解,\(T3\) 出了个树上模拟挺意外的,多刷一些关于树的题。