求助卡常
查看原帖
求助卡常
487199
white_carton楼主2025/1/18 21:07

RT,写了一晚上然后发现过不了。 但是理论应该能过的/ll

#include<bits/stdc++.h>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a<b)?a:b)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define eps (1e-8)
#define endl '\n'
#define fir first
#define sec second
#define file(__a) freopen(__a".in","r",stdin),freopen(__a".out","w",stdout);
#define look_time cerr<<(clock()-Time)/1000.0<<"s"<<endl
#define look_memory cerr<<(&b2-&b1)/1024.0/1024.0<<"MB"<<endl
using namespace std;
bool b1;
time_t Time = clock();
int T = 1;
template<typename T>
inline void read(T &s) {
	T f = 1, c = 0;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') {
			f = -1;
		}
		ch = getchar();
	}
	while (isdigit(ch)) {
		c = (c << 1) + (c << 3) + (ch ^ 48);
		ch = getchar();
	}
	s = f * c;
}
template<typename T, typename ...Args>
inline void read(T &s, Args &...args) {
	read(s), read(args...);
}
namespace white_carton {
char ch[1001000], s[2001000];
int n, m;
double dp[2001000][2];
bool check(double mid) {
	for (int i = 1; i <= m; i++) {
		dp[i][0] = dp[i][1] = -inf;
	}
	dp[0][0] = 0, dp[0][1] = -mid;
	for (int i = 1; i <= m; i++) {
		dp[i][0] = max(dp[i][0], dp[i - 1][1] + (s[i] == 'R') * 100 - mid);
		dp[i][1] = max(dp[i][1], dp[i - 1][0] + (s[i] == 'L') * 100 - mid);
		dp[i][0] = max(dp[i][0], dp[i][1] - mid);
		dp[i][1] = max(dp[i][1], dp[i][0] - mid);
	}
	return dp[m][0] > 0;
}
void Solve() {
	cin >> (ch + 1);
	n = strlen(ch + 1);
	if (ch[1] == ch[n] && ch[1] == 'R') {
		s[++m] = 'X';
	}
	for (int i = 1; i <= n; i++) {
		s[++m] = ch[i];
		if (i != n && ch[i] != 'X' && ch[i] == ch[i + 1]) {
			s[++m] = 'X';
		}
	}
	if (ch[1] == ch[n] && ch[1] == 'L') {
		s[++m] = 'X';
	}
	// for (int i = 1; i <= m; i++) {
	// 	cout << s[i];
	// }
	// cout << endl;
	double l = 0, r = 100, ans = 0;
	while (r >= l + eps) {
		double mid = (l + r) / 2.0;
		if (check(mid)) {
			ans = mid, l = mid + eps;
		} else {
			r = mid - eps;
		}
	}
	printf("%.6lf", (int)(ans * 10000000) * 1.0 / 10000000.0);
}
}
bool b2;
signed main() {
	// file("dis");
	// cin>>T;
	while (T--)white_carton::Solve();
}
//日拱一卒,功不唐捐

大部分手段都试过了,交了25发

2025/1/18 21:07
加载中...