URAL 1969. Hong Kong Tram

有一个trick就是没想到,枚举第二段时间后,要检测该火车能否继续跑一圈来判断,不能先检测前半圈能不能跑加进去后在检测后半段;

// **** 部分不能放在那个位置;

最近代码导致的错误总是找不出,贴下代码权当提醒吧!!

 1 #include<cstdio>

 2 #include<cstring>

 3 #include<iostream>

 4 #include<cmath>

 5 #include<cstdlib>

 6 #include<vector>

 7 #include<algorithm>

 8 using namespace std;

 9 int us[180000];

10 int ID[180000];

11 vector<int> pr[5100];

12 int ti[5100];

13 int n;

14 void FIND(int i,int x,int nn,int y){

15     int pt = ti[i] - x;

16     pr[nn].clear();

17     pr[nn].push_back(ti[i] - x);

18     while ( true )

19     {

20         int nt = pt + x;

21         if ( ID[nt] == -1 ) break;

22         us[nt] = 1;

23        //  pr[nn].push_back(pt + x + y); ****

24         nt = nt + y + y;

25         if (ID[nt] == -1) break;

26         us[nt] = 1;

27        

28         pr[nn].push_back(pt + x + y);

29         pr[nn].push_back(pt + x + y + y + x);

30         pt = pt + y * 2 + x + x;

31     }

32 }

33 int work(int x,int y) {

34     memset(us, 0, sizeof us);

35     pr[0].clear();

36     int mm = 0;

37     us[ti[1]] = 1;

38     FIND(1,x,0,y);

39     int nn = 1;

40     mm = pr[0].size();

41     if ( (mm - 1) % 2 ) return 0;

42     for ( int i = 2; i < n; i ++ )

43     {

44         if ( us[ti[i]] ) continue;

45         us[i] = 1;

46         FIND(i,x,nn,y);

47         nn ++;

48         if ( pr[nn-1].size() != mm ) return false;

49     }

50      if (pr[0][2] <= pr[nn-1][0]) return 0;

51 

52     for (int i = 0; i < nn; i++) {

53         int sz = pr[i].size();

54         for (int j = 0; j < sz; j++) {

55             int hh,mm,ss;

56             hh = pr[i][j] / 3600;

57             mm = pr[i][j] % 3600 / 60;

58             ss = pr[i][j] % 3600 % 60;

59             printf("%02d:%02d:%02d%c",hh,mm,ss, j == sz-1 ? '\n':' ');

60         }

61     }

62     return 1;

63 }

64 void solve(){

65     for (int k = 2; k < n; k++) {

66         int tx = ti[1] - ti[0], ty = ti[k] - ti[1];

67         if (ty % 2) continue;

68         if (work(tx,ty/2)) return;

69     }

70   //  cout<<" ** "<< endl;

71 }

72 int main(){

73    // freopen("in.txt","r",stdin);

74     n = 0;

75     int hh,mm,ss;

76     memset(ID,-1,sizeof(ID));

77     while (~scanf("%d:%d:%d",&hh,&mm,&ss)) {

78         ti[n++] = hh * 3600 + mm * 60 + ss;

79         ID[ti[n-1]] = n-1;

80     }

81    // cout<<" ** "<<endl;

82     solve();

83     return 0;

84 }
View Code

 

你可能感兴趣的:(tr)