hdoj1531

17912 단어 OJ
Problem : 1531 ( King )     Judge Status : Accepted RunId : 2661436    Language : G++    Author : huwenbiao Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta
/***************************************************************\
*Author:Hu Wenbiao
*Created Time: Thu 22 Jul 2010 04:20:35 PM CST
*File Name: main.cpp
*Description: .S[si+ni]-S[si-1]>=ki+1>ki;S[si+ni]-
*S[si-1]<=ki-1<ki. S[i]=S_1+S_2+S_3+...+S_i;
\***************************************************************/

//*========================*Head File*========================*\\

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
/*----------------------*Global Variable*----------------------*/
struct
E{
//
int s,e,len;
}
edges[
110];
int
n,m,si,ni,ki,_min,_max,dist[
110];
char
oi;

//*=======================*Main Program*=======================*//
using namespace std;

bool
Bellman_Ford(){
//Bellman-Ford
int s,e,len;
for
(int i=
0;i<_max-_min;i++){
bool
flag=
true;
for
(int j=
0;j<m;j++){
s=edges[j].s,e=edges[j].e,len=edges[j].len;
if
(dist[e]<dist[s]+len){
// if(dist[s]!=-1&&...)
// , 。

dist[e]=dist[s]+len;
flag=
false;
}
}

if
(flag)
return
true;
}

for
(int j=
0;j<m;j++){//
s=edges[j].s,e=edges[j].e,len=edges[j].len;
if
(dist[e]<dist[s]+len)
return
false;
}

return
true;
}


int
main(){

//freopen("input","r",stdin);
while((scanf("%d",&n)==1)&&n>0){
scanf(
"%d",&m);
_max=-
1;
_min=
99999999;
for
(int i=
0;i<m;i++){//
scanf("%d %d %ct %d",&si,,&oi,&ki);
if
(_min>si-
1)
_min=si-
1;
if
(_max<si+ni)
_max=si+ni;
if
(oi==
'g'){//gt
edges[i].s=si-1;
edges[i].e=si+ni;
edges[i].len=ki+
1;
}

else
{
//lt
edges[i].s=si+ni;
edges[i].e=si-
1;
edges[i].len=
1-ki;
}
}

memset(dist,-
1,sizeof(dist));
dist[_min]=
0;
if
(Bellman_Ford())
printf(
"lamentable kingdom
"
);
else

printf(
"successful conspiracy
"
);
}
}

좋은 웹페이지 즐겨찾기