60pts求调
查看原帖
60pts求调
581103
liangjiaqi2021楼主2024/9/7 09:51

60pts C++ 代码见下

// #include <iostream>
#include <cstdio>
#include <algorithm>
// #define int long long
// #define abs(x) (((x)>0)?(x):-(x))
#define max(x,y) (((x)>(y))?(x):(y))
// #define min(x,y) (((x)<(y))?(x):(y))
#define isdigit(x) ((x)>='0'&&(x)<='9')
using namespace std;
// typedef long long ll;
const int N = 11451.41919810; // 哼 哼 哼 啊啊啊啊啊啊啊啊
int read() // 每天手搓快读快写 日后就能练就手搓cpu的本领
{
	int x = 0, w = 1; char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')
			w = -1;
		c = getchar(); 
	}
	while (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return x * w;
}
int readmd()
{
	int x = 0; char c = getchar();
	while (!isdigit(c))
		c = getchar(); 
	x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	if (isdigit(c))
		x = (x << 3) + (x << 1) + (c ^ 48);
	return x;
}
// void write(int x)
// {
// 	 if(x < 0)
// 		putchar('-'), x = -x;
// 	 if(x > 9)
// 		write(x / 10);
// 	 putchar(x % 10 + '0');
// }
int tdpm[15] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365}; // total days per month
int n;
int m[N]; // month
int d[N]; // day
int ld[N]; // last day
int ttd[N]; // total day
int etd[N]; // end total day
double air[N]; // annual interest rate
struct products
{
	int id;
	int end_total_day;
} pds[N];
bool cmp(products x, products y)
{
	return x.end_total_day < y.end_total_day;
}
double dp[370];
void setdp(int id, double val)
{
	// double vall = val;
	for (int i = etd[id]; i <= 366; ++i)
		dp[i] = val;
		// vall = dp[i] = max(dp[i], vall);
}
double getdp(int id)
{
	double val = dp[ttd[id]];
	val = val + val*air[id]/36500*ld[id];
	return val;
}
void solve()
{
	n = read();
	for (int i = 1; i <= n; ++i)
	{
		m[i] = readmd();
		d[i] = readmd();
		ld[i] = read();
		ttd[i] = tdpm[m[i] - 1] + d[i];
		pds[i].end_total_day = etd[i] = ttd[i] + ld[i];
		pds[i].id = i;
		scanf("%lf", &air[i]);
	}
	sort(pds + 1, pds + n + 1, cmp);
	for (int i = 0; i <= 366; ++i)
		dp[i] = 1e5;
	for (int i = 1; i <= n; ++i)
	{
		if (pds[i].end_total_day > 366)
			break;
		if (getdp(pds[i].id) < dp[etd[pds[i].id]-1])
			continue;
		setdp(pds[i].id, getdp(pds[i].id));
	}
	printf("%.2lf\n", dp[366]);
}
signed main()
{
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	// ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // iostream加速
	solve();
	return 0;
}

2024/9/7 09:51
加载中...