2019ccpc女生赛 复现

本文分享了作者准备2020年女生编程比赛的经历,并通过实战案例详细介绍了多种算法题目的解决思路,包括折扣计算、数学优化、几何计算、时间差计算等。适合于对算法竞赛感兴趣的学习者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在准备2020的女生赛,所以和队友一起打了一下重现赛!下周一起冲冲冲!

A

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 1e3 + 20;
int a[maxn];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	double ans = 0;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		if (sum >= 100 && sum < 150)
			ans += a[i] * 0.8;
		else if (sum >= 150 && sum < 400)
			ans += a[i] * 0.5;
		else
			ans += a[i];
		sum += a[i];
	}
	printf("%.2lf\n", ans);
}

B

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 1e3 + 20;
int a[maxn];

int main() {
	int n;
	cin >> n;
	int sum = (n + 1) * n / 2;
	int ans = 0;
	for (int i = sqrt(sum); i < sum; i++)
		if (sum % i == 0)
			ans = i;
	cout << ans << endl;
}

G

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 1e3 + 20;
int a[maxn];
const double PI = acos(-1);

int main() {
	double n;
	while (scanf("%lf", &n) != EOF) {
		double ans = (n - 1.0) / 2.0 * sin((360.0 / n) * PI / 180.0) + sin((180.0 / n) * PI / 180.0);
		printf("%.6lf\n", ans);
	}
}

J

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	ll n;
	while (scanf("%lld", &n) != EOF) {
		ll sum = 7;
		sum = sum + 6 * n + n * (n - 1) / 2;
		printf("%lld\n", sum);
	}
}

H

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

const int maxn = 1e5 + 20;
struct Time {
	int h, m, s;
	Time() {
		h = m = s = 0;
	}
	Time(int hh, int mm, int ss) {
		h = hh, m = mm, s = ss;
	}
};
Time times[maxn];

bool before(Time a, Time b) {
	if (a.h < b.h)
		return true;
	else if (a.h > b.h)
		return false;
	else {
		if (a.m < b.m)
			return true;
		else if (a.m > b.m)
			return false;
		else {
			if (a.s < b.s)
				return true;
			else
				return false;
		}
	}
}

double cal(Time a, Time b) { // a-b (a在b前)
	if (!before(a, b))
		swap(a, b);
	double res = 0;
	if (b.h > a.h) {
		res += ((double)b.h - a.h) * 60.0 * 60.0;
		res += b.m * 60.0;
		res -= a.m * 60.0;
		res += (double)b.s;
		res -= (double)a.s;
	}
	else {
		if (b.m > a.m) {
			res += b.m * 60.0;
			res -= a.m * 60.0;
			res += (double)b.s;
			res -= (double)a.s;
		}
		else {
			if (b.s > a.s) {
				res += (double)b.s;
				res -= (double)a.s;
			}
		}
	}
	return res;
}

double ans = 0;

int main() {
	int t;
	scanf("%d", &t);
	Time now;
	scanf("%d%d%d", &now.h, &now.m, &now.s);
	int pos = 0;
	vector<Time> be;
	vector<Time> en;
	be.clear(); en.clear();
	Time begin(24, 60, 60), end;
	while (t--) {
		int h, m, s;
		scanf("%d%d%d", &h, &m, &s);
		times[++pos] = Time(h, m, s);
		if (before(times[pos], now))
			be.push_back(times[pos]);
		if (before(now, times[pos]))
			en.push_back(times[pos]);
	}
	for (int i = 0; i < be.size(); i++)
		if (be[i].h >= 12) be[i].h -= 12;
	begin = be[0];
	for (int i = 0; i < be.size(); i++)
		if (cal(now, be[i]) > cal(now, begin))
			begin = be[i];
	for (int i = 0; i < en.size(); i++)
		if (en[i].h >= 12) en[i].h -= 12;
	end = en[0];
	for (int i = 0; i < en.size(); i++)
		if (cal(now, en[i]) > cal(end, en[i]))
			end = en[i];
	if (be.empty()) {
		if (now.h >= 12) now.h -= 12;
		if (end.h >= 12) end.h -= 12;
		ans = cal(now, end);
		ans *= 6;
		printf("%.2lf\n", ans);
		return 0;
	}
	if (en.empty()) {
		if (begin.h >= 12) begin.h -= 12;
		if (now.h >= 12) now.h -= 12;
		ans = cal(begin, now);
		ans *= 6;
		printf("%.2lf\n", ans);
		return 0;
	}
	if (now.h >= 12) now.h -= 12;
	//if (!before(begin, end))
	//	swap(begin, end);
	//if (!before(now, end))
	//	swap(now, end);
	//if (!before(begin, now))
	//	swap(begin, now);
	ans = cal(begin, now) + cal(now, end);
	ans *= 6;
	printf("%.2lf\n", ans);
	return 0;
}

K

#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <string>
#include <cstdio>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#define inf 0X3f3f3f3f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF) {

		if (n == 4 && m == 4) {
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
		}
		else if (n == 4 && m == 8) {
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
		}
		else if (n == 8 && m == 4) {
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
		}
		else if (n == 8 && m == 8) {
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
		}
		else if (n == 12 && m == 4) {
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
			cout << "1113" << endl;
			cout << "2133" << endl;
			cout << "2243" << endl;
			cout << "2444" << endl;
		}
		else if (n == 4 && m == 12) {
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
		}
		else if (n == 12 && m == 8) {
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
			cout << "11131113" << endl;
			cout << "21332133" << endl;
			cout << "22432243" << endl;
			cout << "24442444" << endl;
		}
		else if (n == 8 && m == 12) {
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
		}
		else if (n == 12 && m == 12) {
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
			cout << "111311131113" << endl;
			cout << "213321332133" << endl;
			cout << "224322432243" << endl;
			cout << "244424442444" << endl;
		}
		else
			printf("no response\n");
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值