题目链接:https://cn.vjudge.net/contest/276233#problem/I

题目大意:输入k和n,然后输入n行,每一次输入两个数,代表开端和结尾,如果这个区间内点的个数大于等于k,那么就要求这个区间至少有k个点被圈起来,如果这个区间内的点的个数小于k,就要求这个区间内的点全部被包括起来,然后问你最多需要多少点?

具体思路:正常的建图方式,为了使得路径输出的时候,方便利用数组,我们可以直接在原来的基础上加上10000,这样的化就可以用数组记录到底有还是没有了。路径输出的时候判断条件(dis[i+1]-dis[i]>=1).

AC代码:

 #include<iostream>
#include<cstring>
#include<stack>
#include<iomanip>
#include<cmath>
#include<queue>
#include<algorithm>
#include<stdio.h>
using namespace std;
# define ll long long
# define inf 0x3f3f3f3f
const int maxn = +;
const int maxedge = 5e6+;
struct node
{
int to;
int nex;
int cost;
} edge[maxedge];
vector<int>w;
int head[maxn],pre[maxn],dis[maxn],vis[maxn];
int num;
void init()
{
num=;
for(int i=; i<=maxn; i++)
{
pre[i]=-inf;
dis[i]=inf;
head[i]=-;
}
}
void addedge(int fr,int to,int cost)
{
edge[num].to=to;
edge[num].cost=cost;
edge[num].nex=head[fr];
head[fr]=num++;
}
int spfa(int st,int ed)
{
queue<int>q;
vis[st]=;
dis[st]=;
q.push(st);
while(!q.empty())
{
int tmp=q.front();
q.pop();
vis[tmp]=;
for(int i=head[tmp]; i!=-; i=edge[i].nex)
{
int u=edge[i].to;
if(dis[u]>dis[tmp]+edge[i].cost)
{
dis[u]=dis[tmp]+edge[i].cost;
pre[u]=tmp;
if(vis[u])
continue;
vis[u]=;
q.push(u);
}
}
}
return dis[ed];
}
int main()
{
int k,n;
scanf("%d %d",&k,&n);
int u,v;
init();
int minx=inf,maxy=;
for(int i=; i<=n; i++)
{
scanf("%d %d",&u,&v);
if(u>v)
swap(u,v);
u+=;
v+=;
int len=v-u+;
addedge(v,u-,len);
addedge(u-,v,-min(len,k));
minx=min(minx,u-);
maxy=max(maxy,v);
}
for(int i=minx; i<maxy; i++)
{
addedge(minx-,i,);
addedge(i,i+,);
addedge(i+,i,);
}
addedge(minx,maxy,);
int ans=spfa(minx,maxy);
for(int i=minx+; i<=maxy; i++)
{
if(dis[i]!=dis[i-])
{
w.push_back(i);
}
}
int len=w.size();
printf("%d\n",len);
sort(w.begin(),w.end());
for(int i=; i<len; i++)
{
cout<<w[i]-<<endl;
} return ;
}

差分约束系统+输出路径(I - Advertisement POJ - 1752 )的更多相关文章

  1. 差分约束系统 + spfa(A - Layout POJ - 3169)

    题目链接:https://cn.vjudge.net/contest/276233#problem/A 差分约束系统,假设当前有三个不等式 x- y <=t1 y-z<=t2 x-z< ...

  2. POJ 3159 Candies (图论,差分约束系统,最短路)

    POJ 3159 Candies (图论,差分约束系统,最短路) Description During the kindergarten days, flymouse was the monitor ...

  3. 【POJ 1716】Integer Intervals(差分约束系统)

    id=1716">[POJ 1716]Integer Intervals(差分约束系统) Integer Intervals Time Limit: 1000MS   Memory L ...

  4. 【POJ 1275】 Cashier Employment(差分约束系统的建立和求解)

    [POJ 1275] Cashier Employment(差分约束系统的建立和求解) Cashier Employment Time Limit: 1000MS   Memory Limit: 10 ...

  5. 【POJ 2983】Is the Information Reliable?(差分约束系统)

    id=2983">[POJ 2983]Is the Information Reliable? (差分约束系统) Is the Information Reliable? Time L ...

  6. 【POJ 1201】 Intervals(差分约束系统)

    [POJ 1201] Intervals(差分约束系统) 11 1716的升级版 把原本固定的边权改为不固定. Intervals Time Limit: 2000MS   Memory Limit: ...

  7. POJ 3169 Layout (差分约束系统)

    Layout 题目链接: Rhttp://acm.hust.edu.cn/vjudge/contest/122685#problem/S Description Like everyone else, ...

  8. POJ 3169 Layout 差分约束系统

    介绍下差分约束系统:就是多个2未知数不等式形如(a-b<=k)的形式 问你有没有解,或者求两个未知数的最大差或者最小差 转化为最短路(或最长路) 1:求最小差的时候,不等式转化为b-a>= ...

  9. (poj)3414 Pots (输出路径的广搜)

    Description You are given two pots, having the volume of A and B liters respectively. The following ...

随机推荐

  1. Django知识总汇

    基础 Django基础 Django基本命令 model系统 ORM基础 ORM字段和参数 ORM对数据库操作 ORM中介模型 ORM之其他骚操作 templates系统 模板语言 views系统 视 ...

  2. List<Map> 进行求和

    public class Main { public static void main(String[] args) { List<Map> lists = new ArrayList&l ...

  3. Html5 web 本地存储 (localStorage、sessionStorage)

    HTML5 提供了两种在客户端存储数据的新方法localStorage,sessionStorage sessionStorage(临时存储) :为每一个数据源维持一个存储区域,在浏览器打开期间存在, ...

  4. UVA11027_Palindromic Permutation

    此题不错.给你一些字字符,要求你用这些字符构成一个回文串,求字典序第k大的回文串. 首先通过给定的字符,我们可以直接判断能否构成回文串(奇数的字符不超过一种),其次可以统计每个字符在回文串的左边应该出 ...

  5. Alpha,Beta,RC,RTM,EVAL,CTP,OEM,RTL,VOL

    微软的一个系统(如Win 7)或开发工具(VS系列),往往会对应很多种版本,下面就介绍一下这些版本的含义:   Alpha (阿尔法,希腊字母的第一位'α',代表最初的版本) Alpha是内部测试版, ...

  6. 【刷题】洛谷 P3573 [POI2014]RAJ-Rally

    题目描述 An annual bicycle rally will soon begin in Byteburg. The bikers of Byteburg are natural long di ...

  7. Typhoon-v1.02 靶机入侵

      0x01 前言 Typhoon VM包含多个漏洞和配置错误.Typhoon可用于测试网络服务中的漏洞,配置错误,易受攻击的Web应用程序,密码破解攻击,权限提升攻击,后期利用步骤,信息收集和DNS ...

  8. centos去下载mysql应该怎么选择linux版本

    centos , 本质上和red hat 是一个公司的,差别不大. 你可以选择 red hat那个,或者选择 linux-generic这个,后者这个是通用的. 其实内部差别不大.2个任选一个都可.

  9. android:onClick="xxx"

    一般监听OnClickListener事件,我们都是通过Button button = (Button)findViewById(....); button.setOClickLisener....这 ...

  10. 团体程序设计天梯赛 L1-049. 天梯赛座位分配(测试数据+不同方法)

    Data: /*33 2 1#11 4 7 10 13 16 19 22 25 2831 33 35 37 39 41 43 45 47 4951 53 55 57 59 61 63 65 67 69 ...