poj1201 差分约束系统/system of different contraints

本文介绍了一个区间问题的求解算法,通过Bellman-Ford算法计算最小集合大小,使得该集合与每个给定区间至少有ci个公共元素。适用于解决特定类型的最优化问题。

用s[i]表示小于等于i的元数个数

可得约束条件为:s[node.from]-s[node.to]<-c,隐含的为0<=s[i]-s[i-1]<=1

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN=50010;
struct cnode
{
  int from;
  int to;
  int w;
}node[MAXN];
int d[MAXN];
int n;
 int mmin;
  int mmax;
 bool bellman_ford()
{
  memset(d,0,sizeof(d));
  bool flag=1;
  bool f;
  int i;
  while(flag)
    {
      flag=0;
      for(i=0;i<n;i++)
    {
      if(d[node[i].from]>d[node[i].to]+node[i].w)//from-to<c
        {
          d[node[i].from]=d[node[i].to]+node[i].w;
          flag=1;
        }
    }
     
 
      for(i=mmin;i<=mmax;i++)
    {
      if(d[i-1]+1<d[i])//0<=d[i]-d[i-1]<=1
    {
      d[i]=d[i-1]+1;
      f=1;
    }
    }
     
 
  for(i=mmax;i>=mmin;i--)
    {
      if(d[i-1]>d[i])
    {
      d[i-1]=d[i];
      f=1;
    }
    }
 
    }
  return true;

 
}
int main()
{
    int FROM,TO,W;
  int i;
  while(scanf("%d",&n)!=EOF)
    {
      mmin=800000000;
      mmax=-100;
      for(i=0;i<n;i++)
    {
      scanf("%d %d %d",&FROM,&TO,&W);
      node[i].from=FROM-1;
      node[i].to=TO;
      node[i].w=-W;
      if(FROM<mmin)
        {
          mmin=FROM;
        }
      if(TO>mmax)
        {
          mmax=TO;
        }
     
    }
      bellman_ford();
      printf("%d/n",d[mmax]-d[mmin-1]);
      return 0;
    }
 
  return 0;
}

附题目:

Intervals
Time Limit: 2000MSMemory Limit: 65536K
Total Submissions: 13145Accepted: 4860

Description

You are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn.
Write a program that:
reads the number of intervals, their end points and integers c1, ..., cn from the standard input,
computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai, bi], for each i=1,2,...,n,
writes the answer to the standard output.

Input

The first line of the input contains an integer n (1 <= n <= 50000) -- the number of intervals. The following n lines describe the intervals. The (i+1)-th line of the input contains three integers ai, bi and ci separated by single spaces and such that 0 <= ai <= bi <= 50000 and 1 <= ci <= bi - ai+1.

Output

The output contains exactly one integer equal to the minimal size of set Z sharing at least ci elements with interval [ai, bi], for each i=1,2,...,n.

Sample Input

5
3 7 3
8 10 3
6 8 1
1 3 1
10 11 1

Sample Output

6
基于可靠性评估序贯蒙特卡洛模拟法的配电网可靠性评估研究(Matlab代码实现)内容概要:本文围绕基于序贯蒙特卡洛模拟法的配电网可靠性评估展开研究,重点介绍了利用Matlab代码实现该方法的技术路径。文中详细阐述了序贯蒙特卡洛模拟的基本原理及其在配电网可靠性分析中的应用,包括系统状态抽样、时序模拟、故障判断与修复过程等核心环节。通过构建典型配电网模型,结合元件故障率、修复时间等参数进行大量仿真,获取系统可靠性指标如停电频率、停电持续时间等,进而评估不同运行条件或规划方案下的配电网可靠性水平。研究还可能涉及对含分布式电源、储能等新型元件的复杂配电网的适应性分析,展示了该方法在现代电力系统评估中的实用性与扩展性。; 适合人群:具备电力系统基础知识和Matlab编程能力的高校研究生、科研人员及从事电网规划与运行的技术工程师。; 使用场景及目标:①用于教学与科研中理解蒙特卡洛模拟在电力系统可靠性评估中的具体实现;②为实际配电网的可靠性优化设计、设备配置与运维策略制定提供仿真工具支持;③支撑学术论文复现与算法改进研究; 阅读建议:建议读者结合提供的Matlab代码逐段理解算法流程,重点关注状态转移逻辑与时间序列模拟的实现细节,并尝试在IEEE标准测试系统上进行验证与扩展实验,以深化对方法机理的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值