poj3683 pascal题解
2014-11-27 20:59
169 查看
Priest John's Busiest Day
DescriptionJohn 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 toget 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 beforethe 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.InputThe 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.OutputThe 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
Time Limit: 2000MS | Memory Limit: 65536K | |||
Total Submissions: 8237 | Accepted: 2801 | Special Judge |
2 08:00 09:00 30 08:15 09:00 20Sample Output
YES 08:00 08:30 08:40 09:00
vara: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;beginreadln(m);for i:=1 to m dobeginreadln(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 dojj:=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;beginfor i:=1 to m dobeginif belong[i]>belong[i+m] thenbegina1:=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 elsebegina1:=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;beginf[st[t]]:=false;dec(t);exit(st[t+1]);end;procedure add(x,y:longint);begininc(c[x]);a[x,c[x]]:=y;end;procedure check1;vari:longint;beginfor i:=1 to m doif belong[i]=belong[m+i] thenbeginfff:=false;exit;end;end;function min(x,y:longint):longint;beginif x>y thenexit(y);exit(x);end;procedure check(x,y:longint);beginif not ((ff[x,2]<=ff[y,1]) or (ff[x,1]>=ff[y,2])) thenbeginadd(y+m,x);add(x+m,y);end;if not ((ff[x,4]<=ff[y,3]) or (ff[x,3]>=ff[y,4])) thenbeginadd(y,x+m);add(x,y+m);end;if not ((ff[x,3]>=ff[y,2]) or (ff[x,4]<=ff[y,1])) thenbeginadd(x,y);add(y+m,m+x);end;if not ((ff[x,2]<=ff[y,3]) or (ff[x,1]>=ff[y,4])) thenbeginadd(y,x);add(x+m,y+m);end;end;procedure tarjan(x:longint);vari,y:longint;begininc(d);low[x]:=d;dfn[x]:=d;inc(t);st[t]:=x;f[x]:=true;for i:=1 to c[x] dobeginif not v[a[x,i]] thenbeginv[a[x,i]]:=true;tarjan(a[x,i]);low[x]:=min(low[x],low[a[x,i]]);end elsebeginif f[a[x,i]] thenlow[x]:=min(low[x],dfn[a[x,i]]);end;end;if dfn[x]=low[x] thenbegininc(p);belong[x]:=p;y:=x-1;while x<>y dobeginy:=pp;belong[y]:=p;end;end;end;begininput1;for i:=1 to m dofor j:=i+1 to m docheck(i,j);for i:=1 to 2*m doif not v[i] thenbeginv[i]:=true;tarjan(i);end;fff:=true;check1;if fff thenwriteln('YES') elsebeginwriteln('NO');halt;end;output1;end.
相关文章推荐
- leetcode_题解_Pascal's Triangle_easy
- NOIP2016普及组复赛第二题60分程序加题解pascal大神求帮忙!!!———回文日期
- 【LeetCode】【Python题解】Pascal's Triangle
- NOIP 2000 单词接龙ACC pascal程序加题解。
- NOIP2016普及组复赛第一题的ACC程序加题解pascal
- 题解:等差数列Pascal
- poj3734--pascal题解
- LeetCode题解:Pascal's Triangle II
- Leetcode题解 118. Pascal's Triangle
- [题解][LeetCode][Pascal's Triangle II]
- 美元汇率Pascal题解
- 笨小猴pascal题解
- 题解:Pascal计算2^n次方
- Yemaster摘苹果题解 Pascal
- 题解:Pascal数字统计
- 石头剪子布Pascal题解
- Leetcode题解 119. Pascal's Triangle II
- 级数求和ACC程序加题解PASCAL
- 题解:统计字符pascal
- Pascal题解