CodeForce 89A.Robbery

本文介绍了一种模拟钻石盗窃的算法挑战,玩家需要在限定时间内通过移动钻石来最大化个人收益,同时确保安全系统的稳定运行。

题面:

It is nighttime and Joe the Elusive got into the country’s main bank’s safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let’s make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right.

Unfortunately, Joe didn’t switch the last security system off. On the plus side, he knows the way it works.

Every minute the security system calculates the total amount of diamonds for each two adjacent cells (for the cells between whose numbers difference equals 1). As a result of this check we get an n - 1 sums. If at least one of the sums differs from the corresponding sum received during the previous check, then the security system is triggered.

Joe can move the diamonds from one cell to another between the security system’s checks. He manages to move them no more than m times between two checks. One of the three following operations is regarded as moving a diamond: moving a diamond from any cell to any other one, moving a diamond from any cell to Joe’s pocket, moving a diamond from Joe’s pocket to any cell. Initially Joe’s pocket is empty, and it can carry an unlimited amount of diamonds. It is considered that before all Joe’s actions the system performs at least one check.

In the morning the bank employees will come, which is why Joe has to leave the bank before that moment. Joe has only k minutes left before morning, and on each of these k minutes he can perform no more than m operations. All that remains in Joe’s pocket, is considered his loot.

Calculate the largest amount of diamonds Joe can carry with him. Don’t forget that the security system shouldn’t be triggered (even after Joe leaves the bank) and Joe should leave before morning.

Input
The first line contains integers n, m and k (1 ≤ n ≤ 104, 1 ≤ m, k ≤ 109). The next line contains n numbers. The i-th number is equal to the amount of diamonds in the i-th cell — it is an integer from 0 to 105.

Output
Print a single number — the maximum number of diamonds Joe can steal.

题目大意:

有n个连续的房间,每个房间里放了a[i]个钻石。一共有k分钟,每分钟能做m次操作。可以的操作有::把一颗钻石从某一堆移到另一堆 or 把一颗钻石从某一堆中装进口袋 or把一颗钻石从口袋取出放入某一堆钻石 。
要求:每分钟后,相邻两堆的钻石数量不变。问k分钟后最多可以带走多少钻石。

大致思路:

一堆钻石的数量减少,相邻的堆的钻石数量就要增加。所以易推得:偶数堆钻石无法拿走,奇数堆钻石每拿走一个,需要额外移位n/2次。所以,如果n/2+1>m则不能拿走钻石。
设奇数堆钻石数量不限制,则最多能拿走钻石的个数为m/(n/2+1)*k个,然后与实际奇数堆钻石的最小值取最小,就是结果。因为当任意一个奇数堆的钻石被取完,就无法继续拿走。

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdlib>
using namespace std;
long long n,dia[10010],m,ans=0,mis=100000,k,need=0;//用long会爆
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>m>>k;
    for(int i=1;i<=n;++i){
        cin>>dia[i];
        if(mis>dia[i]&&i%2==1)//在读取时直接取奇数堆最小值
            mis=dia[i];
    }
    need=n/2+1;
    if(n%2==0||need>m);//n为偶数直接不考虑
    else{
        ans=m/need*k;
        ans=min(mis,ans);
    }
    cout<<ans<<endl;
    return 0;
}
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕“基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究”,介绍了利用Matlab代码实现配电网可靠性的仿真分析方法。重点采用序贯蒙特卡洛模拟法对配电网进行长时间段的状态抽样与统计,通过模拟系统元件的故障与修复过程,评估配电网的关键可靠性指标,如系统停电频率、停电持续时间、负荷点可靠性等。该方法能够有效处理复杂网络结构与设备时序特性,提升评估精度,适用于含分布式电源、电动汽车等新型负荷接入的现代配电网。文中提供了完整的Matlab实现代码与案例分析,便于复现和扩展应用。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及电力行业技术人员,尤其适合从事配电网规划、运行与可靠性分析相关工作的人员; 使用场景及目标:①掌握序贯蒙特卡洛模拟法在电力系统可靠性评估中的基本原理与实现流程;②学习如何通过Matlab构建配电网仿真模型并进行状态转移模拟;③应用于含新能源接入的复杂配电网可靠性定量评估与优化设计; 阅读建议:建议结合文中提供的Matlab代码逐段调试运行,理解状态抽样、故障判断、修复逻辑及指标统计的具体实现方式,同时可扩展至不同网络结构或加入更多不确定性因素进行深化研究。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值