CFgym:Magic Artifact(概率期望 & 思维)

探讨了一个涉及游戏关卡顺序优化的问题,旨在通过合理安排关卡顺序来最小化完成所有关卡的期望时间。

"C" Magic Artifact
Time limit 2 seconds
Memory limit 256 megabytes

Maxim is playing a video game. It has n levels, numbered from 1 to n. Levels can be completed in any order, it takes Maxim ai seconds to complete the i-th level.

Maxim can find a magic artifact at one of the levels. There is exactly one magic artifact in the game, and once found it will increase the speed of Maxim's hero and reduce the time needed to complete the level. However, it is not known where the artifact is, the probability that it is at the i-th level is pi. The time needed to complete the i-th level after the artifact is found is bi second (bi ≤ ai). Note that artifact doesn't reduce the time needed to complete the level where it is found.

Maxim wants to choose the order he completes the levels, to minimize the expected time to complete the game. Help him to find the minimal possible expected time. Maxim must choose the order to complete the levels before playing the game, the order must not depend on whether the artifact was found or not at some level.

Recall that the expectation of a random variable is the sum over all possible outcomes of a product of the probability of such outcome and the value of the variable. In this problem the outcome corresponds to the level where the artifact is, and the value is the total time needed if the artifact is at that level.

Input format

Input data contains several test cases. The first line contains t — the number of test cases (1 ≤ t ≤ 1000).

Each test case is described in the following way: the first line contains integer n — the number of levels (1 ≤ n ≤ 105).

The following n lines describe levels. Each level is specified with three integers aibi and xi — the time to complete the level before the artifact was found, the time to complete it after the artifact was found, and the value that helps to find the probability to find the artifact at that level. The probability is calculated using the formula pi = xi / 107 (1 ≤ bi ≤ ai ≤ 105; 0 ≤ xi ≤ 107; the sum of all xi is 107).

The sum of values of n in all test cases of one input data is at most 5·105.

Output format

For each test case output one floating point value — the expected time to complete the game if the optimal order was chosen. The answer must have an absolute or relative error of at most 10 - 6.

Examples
Input data
2
3
10 5 10000000
5 3 0
7 3 0
4
3 1 2500000
4 1 2500000
10 1 2500000
2 1 2500000
Output data
16
10.25
题意:有N个关卡,有一个神器存在某个关卡中,每个关卡有获得神器前后的通关时间,和神器在此关卡的概率,问最合理的安排关卡顺序下完成这N关的最小期望时间。

思路:首先要知道这个期望值怎么算,令ci=ai-bi,假如是从1~N的顺序通关,有time = b1+b2+...+bn+p1*c1+p2*(c1+c2)+p3*(c1+c2+c3)+...+pn(c1+c2+...+cn)。尝试调换第i和第i+1关的顺序,发现式子的变化仅为pi+1*ci变成pi*ci+1,那么就变成贪心问题了,把pi/ci大的放到前面即可,pi=ci=0的关卡特殊处理,他会对排序造成干扰,这些关卡放到哪里都一样。

# include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+30;
typedef long long LL;
struct node
{
    int p, c;
}arr[maxn], brr[maxn];
int t, n;
bool cmp(node a, node b)
{
    if(a.c == 0) return true;
    if(b.c == 0) return false;
    return a.p*1.0/a.c > b.p*1.0/b.c;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        int a, b, c, cnt=0, cnt2=0;
        double ans = 0, sum=0;
        scanf("%d",&n);
        for(int i=1; i<=n; ++i)
        {
            scanf("%d%d%d",&a,&b,&c);
            ans += b;
            if(a-b+c) arr[cnt++] = {c, a-b};
            else brr[cnt2++] = {0, 0};
        }
        sort(arr,arr+cnt,cmp);
        for(int i=0; i<cnt2; ++i) arr[cnt++] = brr[i];
        for(int i=0; i<cnt; ++i)
        {
            sum += arr[i].c;
            ans += sum*arr[i].p*1.0/1e7;
        }
        printf("%.10f\n",ans);
    }
    return 0;
}



### Maven构建过程中出现`org.apache.maven.artifact.InvalidArtifactRTException`异常的解决方案 #### 1. 原因分析 该异常通常发生在Maven解析依赖项时出现问题。具体原因可能包括但不限于以下几种情况: - **本地仓库损坏**:某些依赖项下载不完全或者被破坏。 - **远程仓库不可达**:配置的远程仓库地址无法访问,导致依赖项无法正常拉取[^1]。 - **插件版本缺失或错误**:如`org.apache.tomcat.maven:tomcat7-maven-plugin`未找到指定版本的POM文件[^2]。 - **缺少必要的声明**:例如`&lt;version&gt;`标签遗漏可能导致`&#39;build.plugins.plugin.version&#39; for org.apache.xx.xx:xxx is missing.`类型的错误[^3]。 #### 2. 解决方法 ##### 方法一:清理并重建本地仓库缓存 如果怀疑是本地仓库中的依赖项损坏,可以尝试删除对应的目录并重新下载依赖项。执行以下命令清除旧数据并强制更新依赖项: ```bash mvn clean install -U ``` 此操作会刷新所有过期的依赖项,并重新从远程仓库获取最新版本[^4]。 ##### 方法二:验证远程仓库配置 确认项目的`settings.xml`文件中是否正确设置了可用的镜像源。例如阿里云Maven镜像是一个常见的选择,其配置如下所示: ```xml &lt;mirrors&gt; &lt;mirror&gt; &lt;id&gt;aliyun&lt;/id&gt; &lt;name&gt;Aliyun Repository&lt;/name&gt; &lt;url&gt;http://maven.aliyun.com/nexus/content/repositories/central/&lt;/url&gt; &lt;mirrorOf&gt;central&lt;/mirrorOf&gt; &lt;/mirror&gt; &lt;/mirrors&gt; ``` 通过上述方式切换到更稳定的镜像源,能够有效减少由于网络问题引起的依赖丢失现象。 ##### 方法三:补充完整的插件定义 对于类似`Could not find artifact org.apache.tomcat.maven:tomcat7-maven-plugin:pom...`这样的提示信息,需检查对应插件是否有明确的版本号设定。以下是修正后的示例片段: ```xml &lt;plugin&gt; &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt; &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt; &lt;version&gt;2.2&lt;/version&gt; &lt;!-- 明确指明版本 --&gt; &lt;configuration&gt; &lt;contextReloadable&gt;true&lt;/contextReloadable&gt; &lt;port&gt;8080&lt;/port&gt; &lt;path&gt;/&lt;/path&gt; &lt;/configuration&gt; &lt;/plugin&gt; ``` 注意这里增加了`&lt;version&gt;`字段来规避潜在冲突风险。 ##### 方法四:升级Maven工具本身 有时低版本的Maven可能存在兼容性缺陷,建议将环境变量指向较新的发行版后再试一次编译流程。官方推荐至少保持在Apache Maven 3.x系列以上运行状态。 --- ### 总结 综合来看,针对`org.apache.maven.artifact.InvalidArtifactRTException`这类问题可以从多个角度切入排查,优先考虑修复本地存储结构、优化外部资源链接以及完善XML描述文档等方面入手解决问题。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值