Mock Problem 3 Management and Development (exploit.cpp/c/pas)

Problem 3 Operation and Development (exploit.cpp/c/pas)

【Title description】

The 4X concept system refers to a fairly popular and mature system concept in PC strategy games, named after four English words that also start with "EX".

eXplore (Explore)

eXpand (expansion and development)

eXploit (Operations and Development)

eXterminate (Conquer)

--Wikipedia

 

This time we focus on the exploit part and simplify its model:

You drive a spaceship with a drill (initial ability value w) and fly over n planets in sequence according to a predetermined route.

 

Planets are generally divided into two categories: resource-based and maintenance-based. (p is the current ability value of the drill bit)

1. Resource type: mineral content a[i], if you choose to mine, you will get a[i]*p money, and then the drill bit will lose k%, that is, p=p*(1-0.01k)

2. Maintenance type: maintenance cost b[i], if you choose maintenance, you will pay b[i]*p, and then the drill will be repaired by c%, that is, p=p*(1+0.01c)

    Note: The ability value of the drill bit can exceed the initial value after repair (you can think of it as refurbishment + upgrade)

 

Please choose carefully as the captain to maximize your income.

 

【Input format】

The first line has 4 integers n, k, c, w.

The following n lines, each with 2 integers type, x.

If type is 1, it means that it is a resource-type planet, and x is its mineral content a[i];

A type of 2 means it is a maintenance planet, and x is its maintenance cost b[i];

 

【Output format】

A real number (with 2 decimal places) representing the maximum income.

 

【Sample input】

5 50 50 10

1 10

1 20

2 10

2 20

1 30

【Example output】

375.00

【data range】

For 30% of the data n<=100

Another 20% of the data n<=1000; k=100

For 100% of the data n<=100000; 0<=k,c,w,a[i],b[i]<=100; the answer is guaranteed not to exceed 10^9

Ideas: dp. It can be found that the current decision only affects the subsequent mining, and the remaining durability is proportional to the subsequent mining revenue. If this problem is considered backwards, the maximum benefit that can be obtained by 1 point of durability of the planet in is, from Then go forward dp, get the maximum value and finally multiply w is the answer.

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100001
using namespace std;
int n,w;
int t[MAXN],a[MAXN];
double k,c,ans;
int main(){
    freopen("exploit.in","r",stdin);
    freopen("exploit.out","w",stdout);
    scanf("%d%lf%lf%d",&n,&k,&c,&w);
    k=1-0.01*k;c=1+0.01*c;
    for(int i=1;i<=n;i++)
        scanf("%d%d",&t[i],&a[i]);
    for(int i=n;i;i--)
        if(t[i]==1)
            ans=max(ans,ans*k+a[i]);
        else
            ans=max(ans,ans*c-a[i]);
    printf("%.2lf\n",ans*w);
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325020116&siteId=291194637