Codeforces Beta Round #97 (Div. 1)

B

判矩阵的时候 出了点错 根据点积判垂直 叉积判平行 面积不能为0

  1 #include <iostream>

  2 #include<cstdio>

  3 #include<cstring>

  4 #include<algorithm>

  5 #include<stdlib.h>

  6 #include<vector>

  7 #include<cmath>

  8 using namespace std;

  9 struct node

 10 {

 11     int x,y;

 12 }p[10];

 13 int f[10];

 14 int find(node a,node b,node c,node d)

 15 {

 16     int flag = 0;

 17     if(a.x-b.x==0||c.y-b.y==0||c.x-d.x==0||d.y-a.y==0)

 18     return 0 ;

 19     if((a.x-b.x)*(b.x-c.x)+(a.y-b.y)*(b.y-c.y)==0&&(a.x-b.x)*(d.y-c.y)==(a.y-b.y)*(d.x-c.x)&&(a.x-d.x)*(b.y-c.y)==(a.y-d.y)*(b.x-c.x))

 20     flag = 1;

 21     if(flag&&abs(a.x-b.x)==abs(c.y-b.y))

 22         flag = 2;

 23     return flag;

 24 }

 25 int judge(node a,node b,node c,node d)

 26 {

 27     struct node q[10];

 28     q[1] = a;q[2] = b;

 29     q[3] = c;q[4] = d;

 30     int i,j,g,o;

 31     int flag = 0;

 32     for(i = 1; i <= 4 ; i++)

 33         for(j = 1; j <= 4; j++)

 34         {

 35             if(j==i) continue;

 36             for(g = 1; g <= 4 ; g++)

 37             {

 38                 if(g==i||g==j) continue;

 39                 for(o = 1; o <= 4 ; o++)

 40                 {

 41                     if(o==i||o==g||o==j) continue;

 42                     int gg = find(q[i],q[j],q[g],q[o]);

 43                     if(gg==2)

 44                     {

 45                         flag = 2;

 46                         return flag;

 47                     }

 48                     else if(gg==1)

 49                     {

 50                         flag = 1;

 51                     }

 52                 }

 53             }

 54         }

 55     return flag;

 56 }

 57 int main()

 58 {

 59     int i,j,k,o,g;

 60     while(cin>>p[1].x>>p[1].y)

 61     {

 62         memset(f,0,sizeof(f));

 63         int flag = 0;

 64         for(i = 2; i <= 8 ; i++)

 65         cin>>p[i].x>>p[i].y;

 66         for(i = 1 ;i <= 8 ; i++)

 67         {

 68             for(j =1 ;j <= 8 ; j++)

 69             {

 70                if(j==i) continue;

 71                for(k =1; k <= 8 ; k++)

 72                {

 73                    if(k==i||k==j) continue;

 74                     for(o = 1 ; o <= 8 ; o++)

 75                     {

 76                         if(o==k||o==j||o==i) continue;

 77                         if(judge(p[i],p[j],p[k],p[o])!=2) continue;

 78                         int kk=0;

 79                         for(g = 1 ; g <= 8 ; g++)

 80                         {

 81                             if(g!=i&&g!=j&&g!=k&&g!=o)

 82                             f[++kk] = g;

 83                         }

 84                         if(judge(p[f[1]],p[f[2]],p[f[3]],p[f[4]]))

 85                         {

 86                             flag = 1;

 87                             break;

 88                         }

 89                     }

 90                     if(flag) break;

 91                }

 92                if(flag) break;

 93             }

 94             if(flag) break;

 95         }

 96         if(flag)

 97         {

 98             puts("YES");

 99             int kk=0;

100             cout<<i<<" "<<j<<" "<<k<<" "<<o<<endl;

101             cout<<f[1]<<" "<<f[2]<<" "<<f[3]<<" "<<f[4]<<endl;

102         }

103         else

104         puts("NO");

105     }

106     return 0;

107 }
View Code

分各种情况讨论 注意左边为高位

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 #include<vector>

 7 #include<cmath>

 8 using namespace std;

 9 #define N 100010

10 char s[N],ss[N];

11 int main()

12 {

13     int i,k;

14     cin>>s;

15     k = strlen(s);

16     int num = 0,a=0,b=0,o1=-1,o2=-1,o3=-1;

17     for(i = 0 ; i < k;  i++)

18     {

19         if(s[i]=='?'){num++;o1=i;}

20         if(s[i]=='0'){a++;o2=i;}

21         if(s[i]=='1'){b++;o3 = i;}

22     }

23     int kk = (k-1)/2;

24     if(num==0)

25     {

26         if(b<=kk)

27         puts("00");

28         else if(b-kk==1)

29         {

30             if(s[k-1]=='0')

31             puts("10");

32             else

33             puts("01");

34         }

35         else

36         puts("11");

37     }

38     else

39     {

40         if(b+num<=kk)

41         puts("00");

42         else if(b+num-kk==1)

43         {

44             if(o1>o2||o3>o2)

45             {

46                 puts("00");

47                 puts("01");

48             }

49             else

50             {

51                 puts("00");

52                 puts("10");

53             }

54         }

55         else

56         {

57             if(b-kk>=2)

58                 puts("11");

59             else if(b-kk==1)

60             {

61                 if(o3>o2&&o3>o1)

62                 {

63                     puts("01");

64                     puts("11");

65                 }

66                 else

67                 {

68                     puts("10");

69                     puts("11");

70                 }

71             }

72             else

73             {

74                 if(o1>o2&&o1>o3)

75                 {

76                     puts("00");

77                     puts("01");

78                     puts("10");

79                     puts("11");

80                 }

81                 else if(o2>o3&&o2>o1)

82                 {

83                     puts("00");

84                     puts("10");

85                     puts("11");

86                 }

87                 else

88                 {

89                     puts("00");

90                     puts("01");

91                     puts("11");

92                 }

93             }

94         }

95     }

96     return 0;

97 }
View Code

 

你可能感兴趣的:(codeforces)