跳到正文

题解

【题解】P9740 「KDOI-06-J」ION 比赛

shengmin约 6 分钟
原文
文章信息与版本

文章信息

发布
2023年10月20日
收录
2026年2月19日
更新
2026年11月7日
篇幅
约 6 分钟

版本

  1. v2当前
  2. v1

题目

传送门

思路

20pts20pts

暴力:

C++
#include<bits/stdc++.h>
using namespace std;
int n, a[15], b[15], au;
int zong;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> n;
	for (int i = 1; i <= n ; i++) {
		cin >> a[i] >> b[i];
		zong += 100 / a[i] * b[i];
	}
	cin >> au;
	if (zong >= au) {
		cout << "Already Au.\n";
		return 0;
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] == b[i])cout << "NaN\n";
		else {
			int t = zong - au;
			int tt = 100 / a[i] * b[i];
			int ans = 1;
			for (int i = 1; ; i++) {
				t -= tt;
				if (tt < 0)break;
				ans++;
			}
			cout << ans << endl;
		}
	}
}

30pts30pts

写着写着就写出来了这奇奇怪怪的代码。。。

C++
#include<bits/stdc++.h>
using namespace std;
int n, a[15], b[15], au;
int zong;
int c[15];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> n;
	for (int i = 1; i <= n ; i++) {
		cin >> a[i] >> b[i];
		c[i] = 100 / a[i];
		zong += c[i] * b[i];
	}
	cin >> au;
	if (zong >= au) {
		cout << "Already Au.\n";
		return 0;
	}
	for (int i = 1; i <= n; i ++) {
		if (a[i] == b[i])cout << "NaN\n";
		else {
			int  t = au - zong;
			int ans = 1;
			ans += t / c[i];
			cout << ans << endl;
		}
	}
}

40pts40pts

经过某位大佬指引,把这个 30pts30pts 改成了 40pts40pts。

就是,在 else 里面加一个 if(t%c[i]==0) 那么 ans 不需要 ++。

C++
#include<bits/stdc++.h>
using namespace std;
int n, a[15], b[15], au;
int zong;
int c[15];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> n;
	for (int i = 1; i <= n ; i++) {
		cin >> a[i] >> b[i];
		c[i] = 100 / a[i];
		zong += c[i] * b[i];
	}
	cin >> au;
	if (zong >= au) {
		cout << "Already Au.\n";
		return 0;
	}
	for (int i = 1; i <= n; i ++) {
		if (a[i] == b[i])cout << "NaN\n";
		else {
			int  t = au - zong;
			int ans = 1;
			if(t%c[i] !=0)ans += t / c[i];
			cout << ans << endl;
		}
	}
}

100pts100pts

在 40pts40pts 的情况下没有想通,于是就换了一种思路,就 ACAC 了

C++
#include<bits/stdc++.h>
using namespace std;
int n, au;
int a[15], b[15];
int fz[15];//分值
int df[15];//得分
int zong;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		fz[i] = 100 / a[i];
		df[i] = fz[i] * b[i];
		zong += df[i];
	}
	cin >> au;
	if (zong >= au) {
		cout << "Already Au.\n";
		return 0;
	}
	for (int i = 1; i <= n ; i++) {
		if (a[i] == b[i])cout << "NaN\n";
		else {
			int t = zong;
			int ans = 1;
			bool flag = 0;
			for (int j = 1; j <= a[i] - b[i]; j++) { //a[i]-b[i]还: 要a[i]-b[i]次数才能AC
				t += fz[i];
				if (t >= au) {
					cout << ans << endl;
					flag = 1;
					break;
				}
				ans++;
			}
			if (flag == 1) continue;
			else cout << "NaN\n";
		}
	}
}
原文