四种约束条件。。照做就行了。。

最长路建图。

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <deque> #define rep(i, l, r) for(int i=l; i<=r; i++)
#define down(i, l, r) for(int i=l; i>=r; i--)
#define N 100000
#define MAX 1<<30 using namespace std;
int read()
{
int x=0, f=1; char ch=getchar();
while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
return x*f;
} struct node{int y, v, n;} e[N*10]; int fir[N], en;
int n, v[N], d[N], c[N];
bool b[N], ans;
char s[50]; void Add(int x, int y, int v) { en++; e[en].y=y, e[en].v=v, e[en].n=fir[x], fir[x]=en; } int main()
{
n=read(); int t=0;
while (n)
{
t++;
rep(i, 1, n) fir[i]=0; en=0; ans=true;
rep(i, 1, n) v[i]=read();
scanf("%s", s);
while (s[0] != '#')
{
int x=read(), y=read();
if (s[0]=='S' && s[2]=='S') Add(y, x, 0);
else if (s[0]=='S' && s[2]=='F') Add(y, x, v[y]);
else if (s[0]=='F' && s[2]=='S') Add(y, x, -v[x]);
else if (s[0]=='F' && s[2]=='F') Add(y, x, v[y]-v[x]);
scanf("%s", s);
}
deque <int> q;
rep(i, 1, n) b[i]=1, c[i]=1, d[i]=0, q.push_back(i);
while (!q.empty())
{
int x=q.front(), o=fir[x], y=e[o].y; b[x]=false; q.pop_front();
if (c[x] > n) { ans=false; break; }
while (o)
{
if (d[y] < d[x]+e[o].v)
{
d[y] = d[x]+e[o].v;
if (!b[y]) b[y]=1, c[y]++, !q.empty()&&d[y]>=d[q.front()] ? q.push_front(y) : q.push_back(y);
}
o=e[o].n, y=e[o].y;
}
}
printf("Case %d:\n", t);
if (!ans) printf("impossible\n"); else
{
int a=MAX; rep(i, 1, n) if (a > d[i]) a=d[i]; rep(i, 1, n) printf("%d %d\n", i, d[i]-a);
}
printf("\n"); n=read();
}
return 0;
}

  

HDU-1534 Schedule Problem的更多相关文章

  1. hdu 1534 Schedule Problem (差分约束)

    Schedule Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. HDOJ 1534 Schedule Problem 差分约束

    差分约数: 求满足不等式条件的尽量小的值---->求最长路---->a-b>=c----> b->a (c) Schedule Problem Time Limit: 2 ...

  3. HDU 3549 Flow Problem(最大流)

    HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...

  4. hdu 5106 Bits Problem(数位dp)

    题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...

  5. HDU 3374 String Problem (KMP+最大最小表示)

    HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. hdu 6180 Schedule

    Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...

  7. hdu 1534(差分约束)

    Schedule Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. hdu 5105 Math Problem(数学)

    pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...

  9. Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)

    题目链接: Hdu  5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...

  10. Cooking Schedule Problem Code: SCHEDULE(优先队列)

    Cooking Schedule Problem Code: SCHEDULE Chef is a well-known chef, and everyone wishes to taste his ...

随机推荐

  1. OpenGL小试牛刀第一季

    效果截图:代码展示:using System;using System.Collections.Generic;using System.ComponentModel;using System.Dat ...

  2. 两个有序数列,求中间值 Median of Two Sorted Arrays

    原题: There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the ...

  3. 【转】OS X 中快速调出终端

    作者:Frank Pu链接:https://www.zhihu.com/question/20692634/answer/37152883来源:知乎著作权归作者所有,转载请联系作者获得授权. 来至 M ...

  4. CPP-网络/通信:gsoap 的教程和使用

    1.1.1     gSOAP 1.1.1 .1      简介 gSOAP 编译工具提供了一个 SOAP/XML 关于 C/C++ 语言的实现,从而让 C/C++ 语言研发 web 服务或客户端程式 ...

  5. Web前端 优化方案

    1.减少Http请求  在一个页面中图片,CSS,JS可能N个,如果每个资源都去请求一次服务器的话,那么服务器就会为每个资源开一个线程来完成,这样的话对服务器的压力就很大了.所以解决的方法就是合并资源 ...

  6. 经常用到的js函数

    //获取样式 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ retu ...

  7. 如何用VS2017用C++语言写Hello world 程序?

    1,首先,打开VS2017. 2,左上角按文件——新建——项目,或按ctrl+shift+n. 3,按照图片里的选,选完按“确定”. 4,右键“源文件”,再按添加——新建项. 5,剩下的就很简单了,只 ...

  8. Mysql中反引号和单引号的区别

    反引号,一般在ESC键的下方. 它是为了区分MYSQL的保留字与普通字符而引入的符号.举个例子:SELECT `select` FROM `test` WHERE select='字段值'在test表 ...

  9. angular5 HttpInterceptor使用

    HttpInterceptor接口是ng的http请求拦截器,当需要拦截http请求,可以实现该接口. 1.创建HttpInterceptor 的实现类,并使用@Injectable()注解 @Inj ...

  10. 【linux】 服务器文件说明

    文件名 说明 /etc/resolv.conf  域名解析服务器地址文件 /etc/services 服务程序对应端口号文件 /etc/passwd 登录账号文件 /etc/hosts 本地IP域名解 ...