2024CCPC东北四省赛赛后补题

前言:如果能重来,我要狠狠暴力

J.Breakfast

签到题,无需多言,甚至只要一个输出。

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(){
//	IO;
	int n, m;
	cin >> n >> m;
	printf("%.2f", 0.6 * n + m);
	return 0;
}

A.Paper Watering

经典题目简单但爽吃罚时(带着队伍直接开WA

对于每一个数来说,可以一直进行平方操作,即贡献度就是剩余的K本身加上自己,注意对1特判。

对于开方操作,只要被开数不是完全平方数,新产生的数满足上述条件。

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(){
	IO;
	ll n, k;
	cin >> n >> k;
	if (n == 1 || k == 0) {
		cout << 1 << endl;
		return 0;
	}
	ll cnt = 1 + k, tmp = n;
	for (int i = 1; i <= k; ++i) {
		ll t = sqrt(tmp);
		if (t == 1) {
			cnt++;
			break;
		}
		if (t * t != tmp) cnt += k - i + 1;
		else cnt += 1;
		tmp = t;
	}
	cout << cnt << endl;
	return 0;
}

D.nIM gAME

第一念头是简单的Nim游戏,后面推先手胜利条件,必须满足偶数次取相同的数,但后手总可以破坏先手。磨蹭了半小时还是决定赌一把lose。

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
void solve() {
	int n;
	cin >> n;
	cout << "lose\n";
}
int main(){
	IO;
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}

E. Checksum

本次比赛写出的最后一题,花了大量时间在找规律上面,队伍沟通出了些问题。

首先k的范围只到20,我的思路是纯暴力枚举B字符串,看看得出的D满不满足条件,赛时没想起来进制转换的函数,只得自己写。结果我的思路还是想岔了。

正解是枚举B字符串1的个数,二进制保留k位相当于十进制模 2^k(这个转换很重要,当时就是没转过弯来才去找规律),这样就可以得到B,检查是否满足条件,最后不要忘了前导零。

#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

string f(int d) {
	string s = "";
	if (d == 0) return "0";
	while (d) {
		s = (d % 2 == 0 ? "0" : "1") + s;
		d >>= 1;
	}
	return s;
}
void solve() {
	int n, k, ok = 0;
	cin >> n >> k;
	string a, t1;
	cin >> a;
	int num_a = count(a.begin(), a.end(), '1');
	for (int i = 0; i <= k; ++i) {
		int d = num_a + i;
		d %= (1 << k);  //二进制保留 k位,相当于十进制模 2^k
		t1 = f(d);
		if (count(t1.begin(), t1.end(), '1') == i) {
			ok = 1;
			break;
		}
	}
	if (ok) {
		for (int i = k - t1.size() - 1; i >= 0; --i) cout << "0";
		cout << t1 << endl;
	}
	else cout << "None" << endl;
}
int main(){
	IO;
	int t;
	cin >> t;
	while (t--) solve();
	return 0;
}

M. House

计算几何入门基础检测般的题目,叉积早用早享受,构造几何思维、点积、叉积,这些计算几何的基础都用上了。

建议使用官方题解,枚举DC射线,对于位于射线左侧(叉积<0)的点判断能否成为房顶,对于位于射线右侧(叉积>0)的点判断能否成为底部(满足垂直DC射线的点用map维护点到DC的距离),最后左右满足的点数相乘即是答案。

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e3 + 5;
struct Point {
	ll x, y;
	ll operator^(Point b) const {
		return x * b.y - y * b.x;
	}
	ll operator*(Point b) const {
		return x * b.x + y * b.y;
	}
}p[N];
Point operator-(Point x, const Point &y) {  //构造向量 
	x.x -= y.x, x.y -= y.y;
	return x;
}
ll dis(Point x, Point y) {
	return (x.x - y.x) * (x.x - y.x) + (x.y - y.y) * (x.y - y.y);
}
int n;
ll f(Point A, Point B) {
	Point V = (B - A);  //向量DC
	ll L = 0, R = 0;
	map<ll, ll> mp1, mp2;
	for (int i = 1; i <= n; ++i) {
		Point M = (p[i] - A);  //向量DX
		if ((V ^ M) == 0) continue;  //平行
		if ((V ^ M) < 0) {  //DC左侧 
			if (dis(p[i], A) == dis(p[i], B)) L++;
		}
		else {  //DC右侧 
			Point Q = (p[i] - B), P = (p[i] - A);
			if (Q * V == 0) mp2[dis(p[i], B)]++;   //CX垂直DC 
			if (V * P == 0) mp1[dis(p[i], A)]++;   //DX垂直DC 
		}
	}
	for (auto i : mp1) {
		if (mp2[i.first]) R++;
	}
	return L * R;
}
void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i) cin >> p[i].x >> p[i].y;
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			if (i == j) continue;
			ans += f(p[i], p[j]);
		}
	}
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int _ = 1;
//	cin >> _;
	while (_--) solve();
	return 0;
}

L.Bracket Generation

很熟悉的感觉,但蒟蒻写不出来。

简单的做法是根据给出的序列,先构造一个操作序列。因为大括号在任意时间、任意合法区间都能执行操作,因此我们可以先把操作1执行完毕(即先把小括号填完),之后从右边开始,在任意合适位置执行操作2。

相当于从右边开始执行我们事先构造出来的操作序列,对于每个操作2,都有一个可执行位置。

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using i64 = int64_t;
#define ll long long
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1;
const int MOD = 998244353;
void solve() {
	string s;
	cin >> s;
	stack<int> st;
	vector<int> ve;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '(') {
			st.push(i);
		}
		else {
			if (st.top() + 1 == i)
				ve.push_back(1);
			else
				ve.push_back(2);
			st.pop();
		}
	}
	reverse(ve.begin(), ve.end());
	ll ans = 1, cnt = 0;
	for (int i = 0; i < ve.size(); ++i) {
		cnt++; 
		if (ve[i] == 2)
			ans = ans * cnt % MOD;
	}
	cout << ans << endl; 
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int _ = 1;
//	cin >> _;
	while (_--) solve();
	return 0;
}

posted @ 2024-08-26 11:27  clockleaf  阅读(138)  评论(0)    收藏  举报