设为首页 加入收藏

TOP

POJ训练计划1201_Intervals(差分约束)
2015-07-20 17:50:40 来源: 作者: 【 】 浏览:2
Tags:POJ 训练 计划 1201_Intervals 差分 约束

解题报告

题目传送门

思路:

解方程组:

(a-1)-b<-c

0<=i-(i-1)<=1

Max-Min>=m

源点为Max,求出dis[Max]-dis[Min]

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        #define N 100001 #define M 550000 #define inf 0x3f3f3f3f using namespace std; int head[N],dis[N],vis[N]; int cnt,n,m; int maxx=0,minn=inf; struct node { int v,w,next; } edge[M]; void add(int u,int v,int w) { edge[cnt].v=v,edge[cnt].w=w; edge[cnt].next=head[u],head[u]=cnt++; } void SF() { stack
       
        Q; memset(dis,inf,sizeof(dis)); memset(vis,0,sizeof(vis)); dis[maxx]=0,vis[maxx]=1; Q.push(maxx); while(!Q.empty()) { int u=Q.top(); Q.pop(); vis[u]=0; for(int i=head[u]; i!=-1; i=edge[i].next) { int v=edge[i].v; if(dis[v]>dis[u]+edge[i].w) { dis[v]=dis[u]+edge[i].w; if(!vis[v]) { vis[v]=1; Q.push(v); } } } } } int main() { int i,j,u,v,w; while(~scanf("%d",&n)) { cnt=0; memset(head,-1,sizeof(head)); for(i=1; i<=n; i++) { scanf("%d%d%d",&u,&v,&w); if(v>maxx) maxx=v; if(u
        
         

Intervals
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 21736 Accepted: 8180

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

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇POJ 2983 Is the Information Rel.. 下一篇hdu-3635 Dragon Balls

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: