2022ICPC济南D - Frozen Scoreboard大模拟DFS

题意:

输入封榜后评测前最终的榜单

输出评测后最终的榜单(答案不唯一 任选一种输出)

思路:

暴力DFS

代码:

#define NDEBUG
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using std::cin, std::cout;
using ll = long long;
using db = double;
void Main(void);
int main(void)
{
	std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#if defined(TEXT_IO) and defined(LOCAL) and not defined(ONLINE_JUDGE)
	freopen("mine.in", "r", stdin);
	freopen("mine.out", "w", stdout);
#endif
	Main();
	return 0;
}
/**************************************************/
namespace my
{
#if defined(LOCAL) and not defined(ONLINE_JUDGE)
#include "D:\VScodeFile\LOCAL\debug.h"
#define DBG(x) cout << "! " #x " = " << x << std::endl
#else
#define dbg(...) ((void)0)
#define DBG(...) ((void)0)
#endif
#define VE std::vector
#define STR std::string
#define HEAP std::priority_queue
#define PLL std::pair<ll, ll>
#define fi first
#define se second
#define EDL '\n'
#define WS ' '
#define SDP(x) fixed << setprecision(x)
#define SZ(x) ((ll)x.size())
#define FOR(i, l, r) for (ll i = (l); i <= (r); ++i)
#define ROF(i, r, l) for (ll i = (r); i >= (l); --i)
	constexpr int inf = 0x3f3f3f3f;
	constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
}
using namespace my;
/**************************************************/
constexpr db EPS = 1.0e-9;
constexpr ll MOD = 998244353LL;
constexpr ll SZ = 1e1 + 5;
constexpr ll UK = -1;
constexpr ll NO = 0;
constexpr ll AC = 1;
constexpr ll WA = 2;
ll p_cnt;
ll tot_ac, tot_time;
ll f[SZ], wa[SZ], ac_time[SZ], uk[SZ], sb[SZ];
ll sure_ac, sure_time, use_time;
VE<ll> ve;
bool ok;

void DFS(ll vid, ll now_ac, ll now_time, ll may_wa)
{
	if (ok)
		return;
	if (now_ac > tot_ac)
		return;
	if (now_time > tot_time)
		return;
	if (vid == SZ(ve))
	{
		if (now_ac < tot_ac)
			return;
		ll max_use_time = may_wa * 20 + (tot_ac - sure_ac) * 59;
		if (now_time <= tot_time and tot_time <= now_time + max_use_time)
		{
			use_time = tot_time - now_time;
			ok = true;
		}
		return;
	}
	ll pid = ve[vid];
	f[pid] = AC;
	DFS(vid + 1,
		now_ac + 1,
		now_time + (sb[pid] - uk[pid]) * 20 + 60 * 4,
		may_wa + uk[pid] - 1);
	if (ok)
		return;
	f[pid] = WA;
	DFS(vid + 1,
		now_ac,
		now_time,
		may_wa);
	return;
}
void Work(void)
{
	ll rem_time = use_time;
	for (const auto &pid : ve)
	{
		if (f[pid] == AC)
		{
			ll lim = std::min(rem_time / 20, uk[pid] - 1);
			rem_time -= lim * 20;
			wa[pid] = lim + sb[pid] - uk[pid];
		}
		else if (f[pid] == WA)
			wa[pid] = sb[pid];
	}
	for (const auto &pid : ve)
	{
		if (f[pid] != AC)
			continue;
		ll lim = std::min(rem_time, 59LL);
		rem_time -= lim;
		ac_time[pid] = 60 * 4 + lim;
	}
	return;
}
void Run(void)
{
	ve.clear();
	cin >> tot_ac >> tot_time;
	sure_ac = 0;
	sure_time = 0;
	FOR(i, 1, p_cnt)
	{
		char c;
		cin >> c;
		if (c == '+')
		{
			f[i] = AC;
			cin >> wa[i];
			--wa[i];
			char tmp;
			cin >> tmp;
			cin >> ac_time[i];
			++sure_ac;
			sure_time += wa[i] * 20 + ac_time[i];
		}
		else if (c == '-')
		{
			f[i] = WA;
			cin >> wa[i];
		}
		else if (c == '.')
			f[i] = NO;
		else if (c == '?')
		{
			f[i] = UK;
			cin >> uk[i] >> sb[i];
			ve.push_back(i);
		}
	}

	ok = false;
	DFS(0, sure_ac, sure_time, 0);
	Work();

	if (ok)
	{
		cout << "Yes" << EDL;
		FOR(i, 1, p_cnt)
		{
			if (f[i] == AC)
				cout << "+ " << wa[i] + 1 << '/' << ac_time[i] << EDL;
			else if (f[i] == WA)
				cout << "- " << wa[i] << EDL;
			else if (f[i] == NO)
				cout << '.' << EDL;
		}
	}
	else
		cout << "No" << EDL;
	return;
}
void Main(void)
{
	ll t_cnt;
	cin >> t_cnt >> p_cnt;
	FOR(i, 1, t_cnt)
	Run();
	return;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值