Brush (IV) LightOJ, brushivlightoj

Source: Internet
Author: User

Brush (IV) LightOJ, brushivlightoj

Q: there are some points on the plane. You can fl the points on the same straight line each time and ask at least a few times to fl all the points.

Method:

It is obviously a State compressed dp. Ans [S] indicates the minimum number of times the point of the S set is flushed. The first thought is that if there is only one or two vertices in S, ans [S] = 1. Otherwise, we enumerate any two points in S, I, and j, as points in a straight line, and calculate the number of other points in S that pass through the I and j straight lines, then ans [S] = min (ans [S], ans [S remove all vertices passing through the line] + 1 ). Naturally, we thought that we should pre-process the set of other vertices that have passed through the I and j points in a straight line. We only need to enumerate the I, j and another vertices and determine if they are collocated.

Here we need to use three points of collinearity: https://www.zybang.com/question/ca7778a2e315afb588629121177b6772.html

A (x1, y1), B (x2, y2), C (x3, y3), then (x2-x1) × (y3-y2) = (x3-x2) × (y2-y1)

However, the time complexity is $ O (T * n ^ 3*2 ^ n) $, which is too slow.

It can be observed that, since a collection needs to be flushed sooner or later, you only need to specify any point as the point on the straight line and then enumerate another point.

Then, the complexity is reduced to $ O (T * n ^ 2*2 ^ n) $. The complexity of a single group of data is acceptable, but it still fails because T is large.

Next we started to become stuck frequently:

1. Changing the cyclic dp into a memory search can be much faster, because the final state does not necessarily require answers in all other States.

2. All the elements of S in each set are pre-processed at the beginning, instead of checking whether the number of each enumeration is within S.

3. Regular (meiyong): Fast Read, pre-processing left shift

Error records:

1. Complexity error, $ O (T * n ^ 3*2 ^ n) $

2. The host is often stuck. The host is stuck at http://blog.csdn.net/kijamesqi/article/details/505300001.

1 # include <cstdio> 2 # include <cstring> 3 # include <algorithm> 4 using namespace std; 5 int x [30], y [30]; 6 int T, TT, n, fff; 7 int ans [140000]; 8 int tmp [30] [30]; 9 int left [30]; 10 int G [70000] [30]; 11 void read (int & x) 12 {13 x = 0; 14 char ch = getchar (); fff = 1; 15 while (ch <'0' | ch> '9') 16 {17 if (ch = '-') fff =-1; 18 ch = getchar (); 19} 20 while (ch> = '0' & ch <= '9') x = (x <1) + (x <3) + ch-'0', ch = getchar (); 21 x * = fff; 22} 23 int main () 24 {25 int I, j, k, t1, t2; 26 for (I = 0; I <30; I ++) left [I] = (1 <I); 27 for (I = 1; I <70000; I ++) 28 for (k = 0; k <17; k ++) 29 if (I & left [k]) 30G [I] [++ G [I] [0] = k; 31 read (T); 32 for (TT = 1; TT <= T; TT ++) 33 {34 read (n); 35 for (I = 0; I <n; I ++) 36 read (x [I]), read (y [I]); 37 // memset (tmp, 0, sizeof (tmp); 38 for (I = 0; I <n; I ++) 39 for (j = I + 1; j <n; j ++) 40 {41 tmp [I] [j] = 0; 42 t1 = x [j]-x [I]; 43 t2 = y [j]-y [I]; 44 for (k = 0; k <n; k ++) 45 if (t1 * (y [k]-y [j]) = (x [k]-x [j]) * t2) 46 tmp [I] [j] | = left [k]; 47 tmp [j] [I] = tmp [I] [j]; 48} 49 // memset (ans, 0x3f, sizeof (ans); 50 ans [0] = 0; 51 for (I = 1; I <left [n]; I ++) 52 {53 if (_ builtin_popcount (I) <= 2) 54 ans [I] = 1; 55 else56 {57 ans [I] = 0x3f3f3f; 58 // each point will be flushed sooner or later. Therefore, you can enumerate any point as the upper point of a straight line without enumerating two 59 j = G [I] [1]; 60 for (k = 2; k <= G [I] [0]; k ++) 61 ans [I] = min (ans [I], ans [I ^ (tmp [j] [G [I] [k] & I)] + 1); 62} 63} 64 printf ("Case % d: % d \ n ", TT, ans [left [n]-1]); 65} 66 return 0; 67}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.