HDU-1534 Schedule Problem
四种约束条件。。照做就行了。。
最长路建图。
#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的更多相关文章
- hdu 1534 Schedule Problem (差分约束)
Schedule Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDOJ 1534 Schedule Problem 差分约束
差分约数: 求满足不等式条件的尽量小的值---->求最长路---->a-b>=c----> b->a (c) Schedule Problem Time Limit: 2 ...
- HDU 3549 Flow Problem(最大流)
HDU 3549 Flow Problem(最大流) Time Limit: 5000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/ ...
- hdu 5106 Bits Problem(数位dp)
题目链接:hdu 5106 Bits Problem 题目大意:给定n和r,要求算出[0,r)之间全部n-onebit数的和. 解题思路:数位dp,一个ct表示个数,dp表示和,然后就剩下普通的数位d ...
- HDU 3374 String Problem (KMP+最大最小表示)
HDU 3374 String Problem (KMP+最大最小表示) String Problem Time Limit: 2000/1000 MS (Java/Others) Memory ...
- hdu 6180 Schedule
Schedule Problem Description There are N schedules, the i-th schedule has start time si and end time ...
- hdu 1534(差分约束)
Schedule Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 5105 Math Problem(数学)
pid=5105" target="_blank" style="">题目链接:hdu 5105 Math Problem 题目大意:给定a.b ...
- Hdu 5445 Food Problem (2015长春网络赛 ACM/ICPC Asia Regional Changchun Online)
题目链接: Hdu 5445 Food Problem 题目描述: 有n种甜点,每种都有三个属性(能量,空间,数目),有m辆卡车,每种都有是三个属性(空间,花费,数目).问至少运输p能量的甜点,花费 ...
- Cooking Schedule Problem Code: SCHEDULE(优先队列)
Cooking Schedule Problem Code: SCHEDULE Chef is a well-known chef, and everyone wishes to taste his ...
随机推荐
- UVA 1471 Defense Lines 防线 (LIS变形)
给一个长度为n的序列,要求删除一个连续子序列,使剩下的序列有一个长度最大的连续递增子序列. 最简单的想法是枚举起点j和终点i,然后数一数,分别向前或向后能延伸的最长长度,记为g(i)和f(i).可以先 ...
- 手机屏幕材质详解(TFT,TPS,OLED,AMOLED等)
手机屏幕概括起来就是两种,一个是LCD,一个是OLED屏幕,这两个是屏幕显示技术的两大基础. 一 . LCD:Liquid Crystal Display,这是一种介于固态和液态之间的物质,称为液晶技 ...
- Git初始化仓库
Git global setup: git config --global user.name "再见理想" git config --global user.email &quo ...
- 经常用到的js函数
//获取样式 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ retu ...
- HTML与XHTML区别
1. html超文本标记语言,xhtml可扩展超文本标记语言,xhtml是将html作为xml的应用重新定义的一个标准. 2. xhtm比html的代码规则严格很多,例如'a < b'在xhtm ...
- NOIP模拟赛 某种数列问题
众所周知,chenzeyu97有无数的妹子(阿掉!>_<),而且他还有很多恶趣味的问题,继上次纠结于一排妹子的排法以后,今天他有非(chi)常(bao)认(cheng)真(zhe)去研究一 ...
- LeetCode945-使数组唯一的最小增量
问题:使数组唯一的最小增量 给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1. 返回使 A 中的每个值都是唯一的最少操作次数. 示例 1: 输入:[1,2,2] 输出:1 ...
- Python函数的基本定义和调用以及内置函数
首先我们要了解Python函数的基本定义: 函数是什么? 函数是可以实现一些特定功能的小方法或是小程序.在Python中有很多内建函数,当然随着学习的深入,你也可以学会创建对自己有用的函数.简单的理解 ...
- 逃离迷宫 HDU - 1728(bfs)
逃离迷宫 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 水题:51Nod 1163-最高的奖励
最高的奖励 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 Description 有N个任务,每个任务有一个最晚结束时间以及一个对应的奖励.在结束时间之前完成该任 ...