ZOJ 2770 Burn the Linked Camp(最短路+SPFA+差分约束系统)

微信小程序 - 引入并使用 Fly.js 请求库(超级详细的教程及运行示例)提供 Fly.js 源码源文件下载,贴心的配置示例及注释,优雅快速的发起 http 网络请求 fly.js请求库官方教程文档,微信小程序封装fly.js请求,在小程序/mpvue中使用flyio发起网络请求的方法,微信小程序中如何使用flyio封装网络请求,微信小程序中如何使用flyio封装网络请求,最好的教程,fly最好的文档教程,微信小程序使用fly接口请求框架,引入fly.js报错,微信小程序中如何使用flyio封装网络请求,微信小程序引入Fly.js请求库,如何在fly中配置请求/响应拦截器,如何在微信小程序中优雅地发送异步请求,请求/响应拦截器,微信小程序-引入并使用F 阅读详情

Burn the Linked Camp

Time Limit: 2 Seconds Memory Limit: 65536 KB

It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the Wu Empire. The defeat was due to Liu Bei's wrong decision that he divided his large troops into a number of camps, each of which had a group of armies, and located them in a line. This was the so-called "Linked Camps".

Let's go back to that time. Lu Xun had sent many scouts to obtain the information about his enemy. From his scouts, he knew that Liu Bei had divided his troops into n camps, all of which located in a line, labeled by 1..n from left to right. The ith camp had a maximum capacity of Ci soldiers. Furthermore, by observing the activities Liu Bei's troops had been doing those days, Lu Xun could estimate the least total number of soldiers that were lived in from the ith to the jth camp. Finally, Lu Xun must estimate at least how many soldiers did Liu Bei had, so that he could decide how many troops he should send to burn Liu Bei's Linked Camps.

Input:

There are multiple test cases! On the first line of each test case, there are two integers n (0<n<=1,000) and m (0<=m<=10,000). On the second line, there are n integers C1��Cn. Then m lines follow, each line has three integers i, j, k (0<i<=j<=n, 0<=k<2^31), meaning that the total number of soldiers from the ith camp to the jth camp is at least k.

Output:

For each test case, output one integer in a single line: the least number of all soldiers in Liu Bei's army from Lu Xun's observation. However, Lu Xun's estimations given in the input data may be very unprecise. If his estimations cannot be true, output "Bad Estimations" in a single line instead.

Sample Input:

3 2
1000 2000 1000
1 2 1100
2 3 1300
3 1
100 200 300
2 3 600

Sample Output:

1300
Bad Estimations


Author: ZHOU, Yuan
Source: ZOJ Monthly, October 2006

思路:典型差分约束。c[i]代表第I个营地最多容量。s[i]代表1-i的总容量

           求s[x]-s[0]的最小值。

            (k,k-1)<=c[k],   (k-1,k)<=0;

            (a-1,b)<=-c,  (b,a-1)<=s[b]-s[a-1]

       spfa(0)求最短路。

#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
const int mm=1010;
const int oo=1e9;
class node
{
  public:int v,c;
};
int dis[mm],n,m,c[mm],s[mm],id[mm],pos;
vector<node>e[mm];
bool vis[mm];
queue<int>q;
bool spfa(int x)
{ memset(id,0,sizeof(id));
  memset(vis,0,sizeof(vis));
  for(int i=0;i<=n;i++)
    dis[i]=oo;
  dis[x]=0;int u,v,c;
  q.push(x);int z;vis[x]=1;++id[x];
  while(!q.empty())
  {
    z=q.front();q.pop();vis[z]=0;
    for(int i=0;i<e[z].size();i++)
    { u=z;v=e[z][i].v;c=e[z][i].c;
      if(dis[v]>dis[u]+c)
      {
        dis[v]=dis[u]+c;
        if(!vis[v])
        { ++id[v];
          if(id[v]>n)return 1;
          vis[v]=1;q.push(v);
        }
      }
    }
  }
  return 0;
}
int main()
{
  while(cin>>n>>m)
  { memset(e,0,sizeof(e));
    c[0]=0;s[0]=0;node z;
    for(int i=1;i<=n;i++)
    {
      cin>>c[i];s[i]=s[i-1]+c[i];
      z.v=i-1;z.c=c[i];e[i].push_back(z);///0为源点,(i,i-1)<=s[i]-s[i-1]
      z.v=i;z.c=0;e[i-1].push_back(z);///(i,i-1)<=0
    }
    int a,b,c;
    for(int i=0;i<m;i++)
    {
      cin>>a>>b>>c;
      z.v=b;z.c=-c;e[a-1].push_back(z);///(b,a-1)>=c -> (a-1,b)<=-c
      z.v=a-1;z.c=s[b]-s[a-1];e[b].push_back(z);///(b,a-1)<=s[b]-s[a-1];
    }
    bool flag=spfa(0);
    if(flag)cout<<"Bad Estimations\n";
    else cout<<dis[0]-dis[n]<<"\n";
  }
}


             



VCS NLP 低功耗验证系列(六):功耗分析与优化——SAIF 报告与验证效率提升 本文是VCS NLP低功耗验证系列的第六篇,主要解决功耗数据采集和验证效率优化问题。文章首先介绍了SAIF(Switching Activity Interchange Format)文件在功耗分析中的作用,详细讲解了VCS的Region-Based SAIF功能,包括三个关键系统任务($saif_region_create、$saif_region_exclude、$saif_region_monitor)的使用方法和工程实践建议。接着从编译侧、运行侧和方法学侧三个维度提出了NLP验证效率优化策略,特别强 阅读详情

相关推荐

C# WPF多页面间的数据共享(经典)

实现页面间的数据共享有很多方法,比如:①事件的发布订阅 ②委托③ioc容器④静态类等,这节主要通过静态的集合实现数据的添加和获取。

sf315418的博客 639

zoj 2770 Burn the Linked Camp 差分约束

It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the

kongming_acm的专栏 785

Arnold Denoise流程

参考:https://support.solidangle.com/display/ARP/Removing+Noise+Workflow Arnold生来不是一个以单帧渲染速度见长的渲染器,但这并不能作为一个简单场景渲染时间长达几个小时的借口。 个人认为高品质生产级渲染结果中,Unbiased renderer在渲染时最耗计算时间的其实就是降噪,以至于降噪专门成了一门灯光师必备的技术

机器猫的CG空间 5084

zoj 2770 Burn the Linked Camp

Bellman_Ford实现:点击打开http://blog.youkuaiyun.com/hearthougan/article/details/17631941 差分约束系统的SPFA实现:SPFA速度比Bellman_Ford快多了。链表实现,表头不存数据。 #include #include #include #include using namespace std; const in

Abner 1238

在Windows 11上用VirtualBox搞定WRF-Hydro 5.2.0:一个水文模型小白的Ubuntu 22.04虚拟机避坑实录

本文详细记录了在Windows 11上使用VirtualBox和Ubuntu 22.04虚拟机成功编译安装WRF-Hydro 5.2.0水文模型的全过程。从虚拟环境配置、依赖库安装到环境变量设置,作者分享了针对Linux新手的实用避坑技巧和关键命令,帮助科研人员高效完成水文模型的环境搭建。

weixin_30733003的博客 354

在 Ubuntu 22.04 上配置 SonarQube 与 CI/CD 流水线实现自动化代码审查

本文详细介绍了在Ubuntu 22.04系统上配置SonarQube并与CI/CD流水线集成的完整流程,实现自动化代码审查。从环境准备、数据库配置到核心参数调优,再到与Jenkins和GitHub Actions的深度集成,提供了实战技巧和性能优化建议,帮助团队提升代码质量监控效率。

weixin_28829325的博客 258

ZOJ 2770 Burn the Linked Camp

Burn the Linked CampTime Limit:2 Seconds Memory Limit:65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a ge...

weixin_30782293的博客 227

基于ESP32和OV5640的目标检测系统

本文详细介绍了基于ESP32-S3和OV5640摄像头构建目标检测系统的完整方案。系统采用YOLOv8-Nano轻量级模型,通过INT8量化实现边缘部署,在UXGA分辨率下达到25fps帧率。文章从硬件选型、图像采集优化、模型量化部署、实时推理流水线构建等维度展开,重点解决了内存管理、电源稳定性和异常处理等嵌入式系统关键问题。该方案在资源受限条件下实现了150ms以内的端到端延迟,为物联网视觉应用提供了低成本、低功耗的解决方案,适用于智能家居、工业检测等多个场景。

reset2021的博客 329

zju 2770 Burn the Linked Camp

<br />挺容易转化的差分约束系统,wa的我心都碎了,最后终于ac了,一边bloging,一边流泪啊。<br />转化的思想和下面的文章大体相同:http://www.cnblogs.com/sysuwhj/archive/2011/01/26/1945786.html,只是这个条件( s[i] >= 0 (1 <= i <= n) , 即 s[i] – s[0] >= 0)我没有考虑也是对的,因为我感觉这是一个重复条件。我错就错在gragh[0]没有赋初值。wa了10几次啊,我疯狂的搜解题报告,看别人的

a_new 562

软考中级-软件设计师 知识点整理(一篇就过了 建议收藏)

软考中级-软件设计师上午题知识点总结

片言可决讼,半纸能缚龙 17万+

优化dalsa相机检测界面

上节实现了使用qt结合dalsa相机显示检测到缺陷的画面,由于窗口过于简陋,本节将进行一个界面优化。

A1983Z的博客 987

ZOJ 2770--Burn the Linked Camp 【差分约束】

Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu

_阿阿阿阿欢 737

HighTec安装使用

HighTec安装使用

qq_43552564的博客 3835

【ZOJ 2770】Burn the Linked Camp 差分约束 Bellman_Ford

Burn the Linked Camp Time Limit:2 Seconds Memory Limit:65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a ge...

天才小熊猫的博客 286

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

zoj 2770 Burn the Linked Camp 【差分约束】

 Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by L

世界很大 820

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

zoj 2770 Burn the Linked Camp(火烧连营)

题意:陆逊已知刘备的每个大营最多能容纳Ci个士兵,并且可以估计到第i个大营到第j个大营至少有多少士兵,求刘备最少有多少个士兵。 分析:根据给出的数据我们可以得到一系列不等式组,考虑采用差分约束系统求解。以第一组测试数据解释差分约束系统及构造求解。 设三个军营的人数分别为A1,A2,A3,容量为C1,C2,C3,前n个军营的总人数为Sn,则可以列出以下不等式组。 ⑴第i个大营到第j个大

mxc的专栏 731

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

ZOJ2770Burn the Linked Camp(差分约束+SPFA)

Burn the Linked CampTime Limit: 2 Seconds      Memory Limit: 65536 KBIt is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a genera...

nka_kun的博客 253

Burn the Linked Camp ZOJ - 2770 (差分约束,条件限制+好题)

传送门 题意:刘备有n个连续的军营,现在给出每个军营最多的人数,然后给出从第i个军营到第j个军营的总人数至少有w人,现在问这种情况是否存在。 题解:直接就能看出用差分约束,但是我刚开始太弱了 ,我就建了两个条件,第一个条件是那个最明显的条件,用s[i]表示从第1个军营到第i个军营的总人数,然后s[r]-s[l-1]&gt;=w,然后又建了个所有的s[i]都必须大于等于0,之后再判断s[i]-s...

肘子的博客 249

ZOJ2770 Burn the Linked Camp(差分约束系统)

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2770 题意:陆逊准备烧刘备的连营,现在已经打探到刘备有n个营地排成一条线,编号1到n,每个营地有一个人数上限Ci。他还打探到了m条情报,每条情报包括i,j,k三个数字,表示从i营到j营的人数至少有k个。现在让你根据情报求出刘备所以的营地加起来最少有多少个士兵。有可能情报有...

hcx11333的博客 249

ZOJ 2770 Burn the Linked Camp(裸差分约束)

ZOJ 2770 Burn the Linked Camp(裸差分约束) ZOJ 2770 Burn the Linked Camp Time Limit: 2 Seconds Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the ...

qq_37804582的博客 174

Burn the Linked Camp ZOJ - 2770(差分约束系统)

Burn the Linked Camp ZOJ - 2770It is well known that, in the period of The Three Empires, Liu...

codeswarrior的博客 454

ZOJ 2770 Burn the Linked Camp 差分约束系统

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1770 题意是陆逊能根据动静看到刘备某几个连续大营里至少有多少士兵,并且给出每个营的容纳极限,问刘备阵营至少有多少兵。 是一道标准的差分约束的题。建立一个虚拟兵营零,容纳是零,作用是把所有的大营人数连接起来。判断能否建立连通图只需要先在输入时判断是否有某段最少士兵数超过

看曙光 1254

Burn the Linked Camp ZOJ 2770 差分约束系统 SPFA

这个题是建立一个差分约束系统的模型,设前i个营的实际总人数为si,则根据题意,可得每个营的人数s[i] - s[i-1] <= c[i], i = 1,2......n他会给m个估计,s[j] - s[i-1] >= k,即s[i-1] - s[j] <= -k.然后还有一个约束就是每个营的人数要大于等于0, 即s[i] - s[i-1] >= 0,也就是说 s[i-1]...

weixin_30487701的博客 122

zoj 2770 Burn the Linked Camp 差分约束

最近状态太散漫,一天才写了这一题,很基础的差分约束,直接写出关系式即可。注意边数开大点 /* author:jxy lang:C/C++ university:China,Xidian University **If you need to reprint,please indicate the source** */ #include #include #include #i

弱弱的jxy 640

ZOJ2770 Burn the Linked Camp(差分约束)

Burn the Linked Camp Time Limit: 2 Seconds      Memory Limit: 65536 KB It is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun,

一点一滴,从不止步! 730
上一篇: poj 2263 Heavy Cargo(最短路+floyd)
下一篇: poj 1201 Intervals(最短路+spfa+差分约束系统)
剑不飞
博客等级 码龄15年 86粉丝 505原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值