Codeforces Round #291 (Div. 2 ),

Source: Internet
Author: User
Tags greatest common divisor

Codeforces Round #291 (Div. 2 ),

B. Han Solo and Lazer Guntime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output

There areNImperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (X, Bytes,Y) On this plane.

Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (X0, average,Y0). In one shot it can be destroy all the stormtroopers, situated on some line that crosses point (X0, average,Y0 ).

Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.

The gun is the newest partition tion, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.

Input

The first line contains three integersN,X0 bytesY0 (1 digit ≤ DigitNLimit ≤ limit 1000, minimum-limit 104 limit ≤ limitX0, average,Y0 records ≤ limit 104)-the number of stormtroopers on the battle field and the coordinates of your gun.

NextNLines contain two integers eachXI,YI(Cost-limit 104 limit ≤ limitXI, Bytes,YIMemory ≤ limit 104)-the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrow.stands at the same point with the gun. Multiple stormtroopers can stand at the same point.

Output

Print a single integer-the minimum number of shots Han Solo needs to destroy all the stormtroopers.

Sample test (s) input
4 0 01 12 22 0-1 -1
Output
2
Input
2 1 21 11 0
Output
1
Note

Explain to the first and second samples from the statement, respectively:







Idea: At the beginning, I used a vector to calculate the angle one by one, to see if the vector is parallel. If it is parallel, we don't need ans ++. Then ,, in this case, we WA the percentile (percentile _ percentile) percentile. In fact, we 'd better not use vectors. Because of the floating point errors, an unknown error is returned, except for the direct calculation angle, you can also use the greatest common divisor to obtain the same online point (a point is used to represent the point in a straight line, because it is an integer, so if there is a public vector in the same line, we can obtain the common vectors by dividing them by their largest common divisor, and the common vectors on x and Y axes can be expressed .. Common vectors can be stored using set)


AC code:

# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <set> using namespace std; int gcd (int a, int B) {// calculate the maximum common approx. if (a> B) return gcd (B, a); if (B % a = 0) return a; return gcd (B %, a) ;}int main () {int n, x, y; set <pair <int, int> a; while (scanf ("% d ", & n, & x, & y )! = EOF) {for (int I = 0; I <n; I ++) {int p, q; scanf ("% d", & p, & q); p-= x, q-= y; if (p = 0). insert (make_pair (0, 1); else if (q = 0). insert (make_pair (1, 0); else {int t = gcd (abs (p), abs (q); p/= t; q/= t; if (p <0) {p =-p; q =-q;}. insert (make_pair (p, q) ;}} printf ("% d \ n",. size () ;}return 0 ;}








At the beginning, the set of templates was done.


Paste the cool code:

#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;const double PI = 4 * atan(1.0);struct Point {double x, y;Point(double x = 0, double y = 0) : x(x) , y(y) { }  };typedef Point Vector;  Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); }Vector operator - (Vector A, Vector B) { return Vector(A.x-B.x, A.y-B.y); }Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); }Vector operator / (Vector A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b) {return a.x < b.x || (a.x == b.x && a.y < b.y);} const double eps = 1e-9;int dcmp(double x) {if(fabs(x) < eps) return 0; else return x < 0 ? -1 : 1;}bool operator == (const Point& a, const Point& b) {return dcmp(a.x - b.x) == 0 && dcmp(a.y - b.y) == 0;}double Dot(Vector A, Vector B) { return A.x*B.x + A.y*B.y; } double Length(Vector A) { return sqrt(Dot(A, A)); }double Angle(Vector A, Vector B) { return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x; }double Area2(Point A, Point B, Point C) { return Cross(B-A, C-A); }Vector Rotate(Vector A, double rad) {return Vector(A.x*cos(rad) - A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad) );} Vector Normal(Vector A) {      double L = Length(A);      return Vector(-A.y/L, A.x/L);  }Point GetLineIntersection(Point P, Vector v, Point Q, Vector w) {Vector u = P - Q;double t = Cross(w, u) / Cross(v, w);return P + v * t;}  double DistanceToLine(Point P, Point A, Point B) {      Vector v1 = B-A, v2 = P - A;      return fabs(Cross(v1,v2) / Length(v1)); }  double DistanceToSegment(Point P, Point A, Point B) {      if(A==B) return Length(P-A);      Vector v1 = B - A, v2 = P - A, v3 = P - B;      if(dcmp(Dot(v1, v2)) < 0) return Length(v2);      else if(dcmp(Dot(v1, v3)) > 0) return Length(v3);      else return fabs(Cross(v1, v2)) / Length(v1);  }  Point GetLineProjection(Point P, Point A, Point B) {Vector v = B - A;return A + v * ( Dot(v, P-A) / Dot(v, v) ); }  bool SegmentProperIntersection(Point a1, Point a2, Point b1, Point b2) {double c1 = Cross(a2 - a1, b1 - a1), c2 = Cross(a2 - a1, b2 - a1),c3 = Cross(b2 - b1, a1 - b1), c4 = Cross(b2 - b1, a2 - b1);return dcmp(c1) * dcmp(c2) < 0 && dcmp(c3) * dcmp(c4) < 0;} bool OnSegment(Point p, Point a1, Point a2) {return dcmp(Cross(a1 - p, a2 - p)) == 0 && dcmp(Dot(a1 - p, a2 - p)) < 0;} double ConvexPolygonArea(Point* p, int n) {      double area = 0;      for(int i = 1; i < n-1; i++)          area += Cross(p[i] - p[0], p[i + 1] - p[0]);      return area / 2;  }  int main() {Point A, B[1005];Vector V[1005];int n;while(scanf("%d %lf %lf", &n, &A.x, &A.y) != EOF) {for(int i = 0; i < n; i++) {scanf("%lf %lf", &B[i].x, &B[i].y);V[i] = B[i] - A;}int ans = n, i, j;for(i = 1; i < n; i++) { for(j = 0; j < i; j++) {if( fabs(fabs(Angle(V[i], V[j]) ) - PI) < eps || fabs(fabs(Angle(V[i], V[j])) - 0) < eps){ ans--; break; }}}printf("%d\n", ans);}return 0;} 






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.