bzoj1027

x1*a1+x2*a2+x3*a3=Ai
x1*b1+x2*b2+x3*b3=Bi
x1*(1-a1-b1)+x2*(1-a2-b2)+x3*(1-a3-b3)=1-Ai-Bi

x1*a1+x2*a2+(1-x1-x2)*a3=Ai
x1*b1+x2*b2+(1-x1-x2)*b3=Bi

x1*(a1-a3)+x2*(a2-a3)=Ai-a3
x1*(b1-b3)+x2*(b2-b3)=Bi-b3

  1 const eps=1e-10;
2 type point=record
3        x,y:double;
4      end;
5
6 var a,b:array[0..510] of point;
7     w:array[0..510] of longint;
8     f:array[0..510,0..510] of longint;
9     ans,i,j,k,p,n,m:longint;
10     ch:boolean;
11
12 function min(a,b:longint):longint;
13   begin
14     if a>b then exit(b) else exit(a);
15   end;
16
17 procedure swap(var a,b:point);
18   var c:point;
19   begin
20     c:=a;
21     a:=b;
22     b:=c;
23   end;
24
25
26 procedure sort(l,r:longint);
27   var i,j:longint;
28       p:point;
29   begin
30     i:=l;
31     j:=r;
32     p:=a[(l+r) shr 1];
33     repeat
34       while (a[i].x<p.x) or (a[i].x=p.x) and (a[i].y<p.y) do inc(i);
35       while (p.x<a[j].x) or (a[j].x=p.x) and (p.y<a[j].y) do dec(j);
36       if not(i>j) then
37       begin
38         swap(a[i],a[j]);
39         inc(i);
40         dec(j);
41       end;
42     until i>j;
43     if l<j then sort(l,j);
44     if i<r then sort(i,r);
45   end;
46
47 function cross(a,b,c:point):double;
48   begin
49     exit((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
50   end;
51
52 function check:boolean;
53   var i,j:longint;
54   begin
55     dec(k);
56     for i:=1 to k do
57       for j:=1 to n do
58         if cross(a[w[i]],a[w[i+1]],b[j])<-eps then exit(false);
59     exit(true);
60   end;
61
62 begin
64   for i:=1 to m do
66   for i:=1 to n do
68   if n=0 then
69   begin
70     writeln(0);
71     halt;
72   end;
73   for i:=1 to m do
74   begin
75     ch:=true;
76     for j:=1 to n do
77       if (a[i].x<>b[j].x) or (a[i].y<>b[j].y) then
78       begin
79         ch:=false;
80         break;
81       end;
82     if ch then //这里特判一下
83     begin
84       writeln(1);
85       halt;
86     end;
87   end;
88   sort(1,m);
89   k:=1;
90   w[1]:=1;
91   for i:=2 to m do
92   begin
93     while (k>1) and (cross(a[w[k-1]],a[w[k]],a[i])<eps) do dec(k);
94     inc(k); w[k]:=i;
95   end;
96   j:=k;
97   for i:=m-1 downto 1 do
98   begin
99     while (k>j) and (cross(a[w[k-1]],a[w[k]],a[i])<eps) do dec(k);
100     inc(k); w[k]:=i;
101   end;
102   if check then
103   begin
104     for i:=1 to k do
105       for j:=1 to k do
106       begin
107         f[i,j]:=m;
108         if i<>j then
109         begin
110           ch:=true;
111           for p:=1 to n do
112             if cross(a[w[i]],a[w[j]],b[p])<-eps then
113             begin
114               ch:=false;
115               break;
116             end;
117           if ch then f[i,j]:=1;
118         end;
119       end;
120
121     for p:=1 to k do
122       for i:=1 to k do
123         for j:=1 to k do
124           f[i,j]:=min(f[i,j],f[i,p]+f[p,j]);
125     ans:=m;
126     for i:=1 to k do
127       ans:=min(ans,f[i,i]);
128     writeln(ans);
129   end
130   else writeln(-1);
131 end.
View Code

posted on 2015-03-07 21:40  acphile  阅读(145)  评论(0编辑  收藏  举报