codeforces 725F

两姐妹Alice和Bonnie因家庭照片分配发生争执,决定通过轮流选取照片来解决,每张照片给两人带来的快乐值不同,她们的目标是使自己比对方更快乐。在最优策略下,探究最终快乐值的差异。

F. Family Photos

time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Alice and Bonnie are sisters, but they don’t like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.

There are n stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.

Each photo is described by two non-negative integers a and b, indicating that it is worth a units of happiness to Alice and b units of happiness to Bonnie. Values of a and b might differ for different photos.

It’s allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.

The players don’t act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister’s. Assuming both players play optimal, find the difference between Alice’s and Bonnie’s happiness. That is, if there’s a perfectly-played game such that Alice has x happiness and Bonnie has y happiness at the end, you should print x - y.

Input
The first line of input contains a single integer n (1 ≤ n ≤ 100 000) — the number of two-photo stacks. Then follow n lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers a1, b1, a2 and b2, each not exceeding 109. a1 and b1 describe the top photo in the stack, while a2 and b2 describe the bottom photo in the stack.

Output
Output a single integer: the difference between Alice’s and Bonnie’s happiness if both play optimally.

Examples
input
2
12 3 4 7
1 15 9 1
output
1
input
2
5 4 8 8
4 12 14 0
output
4
input
1
0 10 0 10
output
-10

题目大意:

有n对照片,A和B轮流取,获得不同的喜悦值,每对照片只有当第一张照片被取走后才能取第二张,当轮到一个人时,他可以选择不取,当所有照片都被取完或当连续两个人都不取时,游戏结束。A和B都希望自己的喜悦值和对方的喜悦值差值最大,假设两人都采用最佳策略,求A和B的喜悦值的差值。

解题思路:

分三种情况:
1.a1<=b2&&b1<=a2,负收益可忽略
2.a1>b2或b1>a2,且a1+b1<=a2+b2;保证正收益选择先手
3.其余情况,物品价值a1+b1(第二轮a2+b2),优先队列贪心

#include<iostream>
#include<queue>
using namespace std;
typedef long long LL;

int n;
struct node
{
    int a1, b1, a2, b2;
    int tag;
};

bool operator< (const node& a, const node& b)
{
    return a.a1+a.b1<b.a1+b.b1;//大的先出队
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    priority_queue<node> pq;
    while(cin>>n)
    {
        while(!pq.empty())
        pq.pop();
        LL ans=0;
        int a1, b1, a2, b2;
        for(int i=1;i<=n;i++)
        {
            cin>>a1>>b1>>a2>>b2;
            if(a1<=b2&&b1<=a2) continue;
            else if(a1+b1<a2+b2)
            {
                if(a1>b2) ans+=a1-b2;
                else ans+=a2-b1;
            }
            else
            {
                node tmp;
                tmp.a1=a1, tmp.b1=b1, tmp.a2=a2, tmp.b2=b2;
                tmp.tag=1;
                pq.push(tmp);
            }
        }
        int cnt=0;
        while(!pq.empty())
        {
            cnt++;
            node tmp=pq.top();
            pq.pop();
            if(cnt%2)
            {
                ans+=tmp.a1;
            }
            else ans-=tmp.b1;
            if(tmp.tag==1)
            {
                tmp.tag=2;
                tmp.a1=tmp.a2;
                tmp.b1=tmp.b2;
                tmp.a2=0;
                tmp.b2=0;
                pq.push(tmp);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
【博士论文复现】【阻抗建模、验证扫频法】光伏并网逆变器扫频与稳定性分析(包含锁相环电流环)(Simulink仿真实现)内容概要:本文档围绕“博士论文复现”主题,重点介绍了光伏并网逆变器的阻抗建模与扫频法稳定性分析,涵盖锁相环和电流环的Simulink仿真实现。文档旨在通过完整的仿真资源和代码帮助科研人员复现相关技术细节,提升对新能源并网系统动态特性和稳定机制的理解。此外,文档还提供了大量其他科研方向的复现资源,包括微电网优化、机器学习、路径规划、信号处理、电力系统分析等,配套MATLAB/Simulink代码与模型,服务于多领域科研需求。; 适合人群:具备一定电力电子、自动控制或新能源背景的研究生、博士生及科研人员,熟悉MATLAB/Simulink环境,有志于复现高水平论文成果并开展创新研究。; 使用场景及目标:①复现光伏并网逆变器的阻抗建模与扫频分析过程,掌握其稳定性判据与仿真方法;②借鉴提供的丰富案例资源,支撑博士论文或期刊论文的仿真实验部分;③结合团队提供的算法与模型,快速搭建实验平台,提升科研效率。; 阅读建议:建议按文档目录顺序浏览,优先下载并运行配套仿真文件,结合理论学习与代码调试加深理解;重点关注锁相环与电流环的建模细节,同时可拓展学习其他复现案例以拓宽研究视野。
内容概要:本文系统解析了嵌入式通信协议栈系列项目的实践路径,围绕通信原理与工程实现,阐述在资源受限的嵌入式环境中构建稳定、可扩展通信能力的方法。文章从通信基础模型出发,强调分层设计思想,涵盖物理层到应用层的职责划分,并依次讲解通信驱动、数据收发机制、帧格式解析、状态机控制、错误处理等核心技术环节。项目实践注重底层可靠性建设,如中断响应、缓冲区管理与数据校验,同时关注上层应用对接,确保协议栈支持设备配置、状态上报等实际业务。文中还突出性能优化与资源管理的重要性,指导开发者在内存与处理效率间取得平衡,并通过系统化测试手段(如异常模拟、压力测试)验证协议栈的健壮性。; 适合人群:具备嵌入式系统基础知识,有一定C语言和硬件接口开发经验,从事或希望深入物联网、工业控制等领域1-3年工作经验的工程师。; 使用场景及目标:①掌握嵌入式环境下通信协议栈的分层架构设计与实现方法;②理解状态机、数据封装、异常处理等关键技术在真实项目中的应用;③提升在资源受限条件下优化通信性能与稳定性的工程能力; 阅读建议:建议结合实际嵌入式平台动手实践,边学边调,重点关注各层接口定义与模块解耦设计,配合调试工具深入分析通信流程与异常行为,以全面提升系统级开发素养。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值