poj3683 pascal题解
来源:互联网 发布:private java中的作用 编辑:程序博客网 时间:2024/06/06 17:37
Description
John is the only priest in his town. September 1st is the John's busiest day in a year because there is an old legend in the town that the couple who get married on that day will be forever blessed by the God of Love. This year N couples plan to get married on the blessed day. The i-th couple plan to hold their wedding from time Si to time Ti. According to the traditions in the town, there must be a special ceremony on which the couple stand before the priest and accept blessings. The i-th couple need Di minutes to finish this ceremony. Moreover, this ceremony must be either at the beginning or the ending of the wedding (i.e. it must be either from Si to Si + Di, or from Ti - Di to Ti). Could you tell John how to arrange his schedule so that he can present at every special ceremonies of the weddings.
Note that John can not be present at two weddings simultaneously.
Input
The first line contains a integer N ( 1 ≤ N ≤ 1000).
The next N lines contain the Si, Ti and Di. Si and Ti are in the format of hh:mm.
Output
The first line of output contains "YES" or "NO" indicating whether John can be present at every special ceremony. If it is "YES", output another N lines describing the staring time and finishing time of all the ceremonies.
Sample Input
208:00 09:00 3008:15 09:00 20
Sample Output
YES08:00 08:3008:40 09:00
var a:array [1..3010,0..3010] of longint; v,f:array [1..3010] of boolean; low,dfn,st,belong,c:Array [1..3010] of longint; ff:array [1..3010,1..4] of longint; a1,a2,a3,a4,i,j,m,n,x,y,mm,nn,p,ii,s2,len,s1,d,jj,t,k:longint; ch:char; fff:boolean; s:string;procedure input1;begin readln(m); for i:=1 to m do begin readln(s); len:=length(s); jj:=0; x:=ord(s[1])*10+ord(s[2])-ord('0')*11; y:=ord(s[4])*10+ord(s[5])-ord('0')*11; mm:=ord(s[7])*10+ord(s[8])-ord('0')*11; nn:=ord(s[10])*10+ord(s[11])-ord('0')*11; for j:=13 to len do jj:=jj*10+ord(s[j])-ord('0'); s1:=x*60+y; s2:=mm*60+nn; ff[i,1]:=s1; ff[i,2]:=s1+jj; ff[i,3]:=s2-jj; ff[i,4]:=s2; end;end;procedure output1;begin for i:=1 to m do begin if belong[i]>belong[i+m] then begin a1:=ff[i,1] div 60; a2:=ff[i,1] mod 60; a3:=ff[i,2] div 60; a4:=ff[i,2] mod 60; writeln(a1 div 10,a1 mod 10,':',a2 div 10,a2 mod 10,' ',a3 div 10,a3 mod 10,':',a4 div 10,a4 mod 10); end else begin a1:=ff[i,3] div 60; a2:=ff[i,3] mod 60; a3:=ff[i,4] div 60; a4:=ff[i,4] mod 60; writeln(a1 div 10,a1 mod 10,':',a2 div 10,a2 mod 10,' ',a3 div 10,a3 mod 10,':',a4 div 10,a4 mod 10); end; end;end;function pp:longint;begin f[st[t]]:=false; dec(t); exit(st[t+1]);end;procedure add(x,y:longint);begin inc(c[x]); a[x,c[x]]:=y;end;procedure check1;var i:longint;begin for i:=1 to m do if belong[i]=belong[m+i] then begin fff:=false; exit; end;end;function min(x,y:longint):longint;begin if x>y then exit(y); exit(x);end;procedure check(x,y:longint);begin if not ((ff[x,2]<=ff[y,1]) or (ff[x,1]>=ff[y,2])) then begin add(y+m,x); add(x+m,y); end; if not ((ff[x,4]<=ff[y,3]) or (ff[x,3]>=ff[y,4])) then begin add(y,x+m); add(x,y+m); end; if not ((ff[x,3]>=ff[y,2]) or (ff[x,4]<=ff[y,1])) then begin add(x,y); add(y+m,m+x); end; if not ((ff[x,2]<=ff[y,3]) or (ff[x,1]>=ff[y,4])) then begin add(y,x); add(x+m,y+m); end;end;procedure tarjan(x:longint);var i,y:longint;begin inc(d); low[x]:=d; dfn[x]:=d; inc(t); st[t]:=x; f[x]:=true; for i:=1 to c[x] do begin if not v[a[x,i]] then begin v[a[x,i]]:=true; tarjan(a[x,i]); low[x]:=min (low[x],low[a[x,i]]); end else begin if f[a[x,i]] then low[x]:=min(low[x],dfn[a[x,i]]); end; end; if dfn[x]=low[x] then begin inc(p); belong[x]:=p; y:=x-1; while x<>y do begin y:=pp; belong[y]:=p; end; end;end;begin input1; for i:=1 to m do for j:=i+1 to m do check(i,j); for i:=1 to 2*m do if not v[i] then begin v[i]:=true; tarjan(i); end; fff:=true; check1; if fff then writeln('YES') else begin writeln('NO'); halt; end; output1;end.
- poj3683 pascal题解
- poj3683
- poj3683
- poj3905 pascal题解
- 笨小猴pascal题解
- poj3734--pascal题解
- LeetCode题解:Pascal's Triangle
- 求细胞数量pascal题解
- 【2-SAT任意解】POJ3683[Priest John's Busiest Day]题解
- [题解][LeetCode][Pascal's Triangle II]
- 【LeetCode】【Python题解】Pascal's Triangle
- LeetCode题解:Pascal's Triangle II
- LeetCode 题解(218) : Pascal's Triangle II
- LeetCode题解:Pascal's Triangle II
- Leetcode题解 118. Pascal's Triangle
- Leetcode题解 119. Pascal's Triangle II
- uva1601题解,pascal留守儿童的血泪
- 级数求和ACC程序加题解PASCAL
- 实现微信好友列表
- Android:应用程序(APK)的编译打包过程
- poj3468(A Simple Problem with Integers)线段树实现
- 【图文笔记】初识uGUI(四)
- 05关于两种context的区别
- poj3683 pascal题解
- 多媒体基础学习
- shell转换IP
- Hduoj3068【manacher算法】
- xshell 如何添加快捷方式
- 使用Part上传附件
- 第十四周OJ项目——杨辉三角
- poj 3468线段树 成段更新
- Codeforces Round #279 (Div. 2)