Finding Lines
Time Limit: 20000ms, Special Time Limit:50000ms, Memory Limit:65536KB
Total submit users: 25, Accepted users: 11
Problem 13348 : No special judgement
Problem description

Annabel and Richard like to invent new games and play against each other. One day Annabel has a new game for Richard. In this game there is a game master and a player. The game master draws n points on a piece of paper. The task for the player is to find a straight line, such that at least p percent of the points lie exactly on that line. Richard and Annabel have very good tools for measurement and drawing. Therefore they can check whether a point lies exactly on a line or not. If the player can find such a line then the player wins. Otherwise the game master wins the game.

There is just one problem. The game master can draw the points in a way such that it is not possible at all to draw a suitable line. They need an independent mechanism to check whether there even exists a line containing at least p percent of the points, i.e., dn · p/100e points. Now it is up to you to help them and write a program to solve this task.



Input

The input consists of:

• one line with one integer n (1 ≤ n ≤ 10^5), the number of points the game master has drawn;

• one line with one integer p (20 ≤ p ≤ 100), the percentage of points which need to lie on the line;

• n lines each with two integers x and y (0 ≤ x,y ≤ 10^9), the coordinates of a point. No two points will coincide.



Output

Output one line containing either “possible” if it is possible to find a suitable line or “impossible” otherwise.



Sample Input
5
55
0 0
10 10
10 0
0 10
3 3
5
45
0 0
10 10
10 0
0 10
3 4
Sample Output
possible
impossible

题意:平面上个你n个点,问你一条直线能穿过最多点的比例是否大于p

思路:随机函数随机两个点,随机200次,暴力找

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<limits.h>
 4 #include<stdlib.h>
 5 #include<string.h>
 6 #include<complex>
 7 #include<cstring>
 8 #include<iomanip>
 9 #include<stdio.h>
10 #include<bitset>
11 #include<cctype>
12 #include<math.h>
13 #include<string>
14 #include<time.h>
15 #include<vector>
16 #include<cmath>
17 #include<queue>
18 #include<stack>
19 #include<list>
20 #include<map>
21 #include<set>
22 
23 #define LL long long
24 
25 using namespace std;
26 const LL mod = 1e9 + 7;
27 const double PI = acos(-1.0);
28 const double E = exp(1.0);
29 const int M = 1e5 + 5;
30 
31 int x[M];
32 int y[M];
33 
34 double calc(int i, int j)
35 {
36     return (y[i] - y[j]) / (double)(x[i] - x[j]);
37 }
38 
39 int main()
40 {
41     int n, p;
42     while( cin >> n >> p ){
43         for(int i = 0; i < n; ++i)
44             scanf("%d%d", &x[i], &y[i]);
45         if(n == 1){
46             puts("possible");
47             continue;
48         }
49         bool flag = 1;
50         for(int j = 0; j < 200; ++j){
51             int s = rand() % n;
52             int e = rand() % n;
53             while(e == s)
54                 e = rand() % n;
55             double slope;
56             bool ok = 0;
57             if(x[s] == x[e])
58                 ok = 1;
59             else
60                 slope = (y[s] - y[e]) / (double)(x[s] - x[e]);
61             int sum = 2;
62             for(int i = 0; i < n; ++i){
63                 if(i == s || i == e)
64                     continue;
65                 if(ok){
66                     if(x[i] == x[s])
67                         sum++;
68                 }
69                 else{
70                     if(calc(s, i) == slope)
71                         sum++;
72                 }
73             }
74             if(sum * 100 / n >= p){
75                 puts("possible");
76                 flag = 0;
77                 break;
78             }
79         }
80         if(flag)
81             puts("impossible");
82     }
83     return 0;
84 }

 

posted on 2015-08-03 15:25  Unico  阅读(396)  评论(0)    收藏  举报