Codeforces 183 B zoo-computational ry + Enumeration

Source: Internet
Author: User
/* Question: there are n telescopes placed on the X axis 1 ~ In the N position, there are m birds. The telescope can observe at any angle to see all the birds in that line, ask the sum of the numbers of birds seen by all telescopes to calculate ry + violence */# include <stdio. h> # include <string. h> int n, m; int num [1000010]; struct line // edge structure {__ int64 a, B, c ;}; struct point // point {__ int64 X, y;} niao [300]; line ppline (point P1, point P2) // calculates the line of the two points {Line L; L. A = p2.y-p1.y; L. B = p1.x-p2.x; L. C = p1.y * p2.x-p1.x * p2.y; return l;} int online (point P, line L) // determine whether the point is in a straight line {If (P. x * L. A + P. y * L. B + L. C = 0) return 1; return 0;} int xofline (I NT y, line L) // calculates the intersection with the X axis {If (L. A = 0) Return-1; if (L. C % L.! = 0) Return-1; double ret; ret =-(L. C * 1.0/L. a); If (Ret> 1000099 | RET <-100) Return-1; Return-L. c/L. a;} int main () {int I, J, K, RET; while (scanf ("% d", & N, & M )! = EOF) {memset (Num, 0, sizeof (Num); for (I = 1; I <= m; ++ I) scanf ("% d ", & niao [I]. x, & niao [I]. y); for (I = 1; I <= m; I ++) {for (j = I + 1; j <= m; j ++) // enumerate the straight lines with bird I and J {Line L = ppline (niao [I], niao [J]); int you = 2; for (k = J + 1; k <= m; ++ K) // judge whether the bird behind it is in this line {If (online (niao [K], L) You ++ ;} int x = xofline (0, L); If (x> = 1 & x <= N & num [x] <You) num [x] = You ;}} ret = 0; for (I = 1; I <= N; ++ I) if (Num [I]) RET + = num [I]; else RET + = 1; // The above is based on two points to determine a straight line, some telescopes can only see one bird printf ("% d \ n", RET);} 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.