CCCC Preliminary l3-003 Great Wall

Source: Internet
Author: User

l3-009. Great Wall time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Deng Junhui

As we all know, the ancient Great Wall of China was built to resist the invasion of the enemy. On the Great Wall, many beacons were built. Each beacon is monitored for a specific area. Once a region has a foreign invasion, the soldiers on the corresponding Beacon will notify the enemy to the surrounding beacon, and quickly relay to the headquarters.

Now shown in 1, if the horizontal is north-south direction, perpendicular to the altitude direction, assuming the Great Wall is a series of sequentially linked line segments, and in this range any vertical line with these segments have and only a unique intersection.


Figure 1

Further, assume that the beacon can only be built at the end point of the line segment. We think the beacon itself is not high, each beacon is only responsible for the north (Figure 1 left) Lookout, and once a foreign invasion, as long as the enemy and the beacon is not obscured by the mountain, the Sentinel will immediately detect. Of course, according to this military, for the south side of the enemy beacon is not responsible. Once the Sentinel discovers the enemy, he immediately transmits an alert to its southern beacon, in the form of a smoke signals or a beacon, until it is located at the south-most headquarters.

Take the Great Wall in Figure 2 as an example, the guard of the four beacons with blue and white dots, the most south of the headquarters with a red dot signal. If there is a red star, it will be spotted by the Sentinels and routed along the red Line to the head office. Of course, in this case only two beacons of collaboration, but other locations may require more enemy. In turn, however, even if the 4 beacons here are all involved, there are still areas that cannot be covered (yellow).


Figure 2

In addition, in order to avoid ambiguity, we agreed here, and a beacon line of sight just tangent to the area is considered to be monitored by the beacon. Take the Great Wall in Figure 3, for example, if a, B, C, D points are collinear, and at D Point set a beacon, then A, B, C and the line segment BC any point is within the monitoring range of the beacon.


Figure 3

Well, if you are Qin Shihuang's Qiu, in order not to appear more Meng Jiangnu-style tragedy, how to ensure the security of the Great Wall under the premise of the consumption of Minli (built beacon) the least?

Input format:

The input gives a positive integer n (3 <= n <=105) on the first line, which is the number of polyline vertices (with start and end points) depicting the edge of the Great Wall. Then n rows, each row gives the x and y coordinates of a vertex, separated by a space. Note the vertices are given from south to north, and the first vertex is the location of the head office. The coordinates are integers within the interval [-109, 109) and have no coincident points.

Output format:

Outputs the minimum number of beacons (excluding headquarters) required to be built in a row.

Input Sample:
1067 3248-4932 5322-4419 2211 4010-65-1-23-3 31-7 59
Sample output:
2

Problem Solving Ideas:

Use a stack maintenance command to see the beacon number required for the current point.

Code:

1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5 using namespacestd;6 #defineMAXN 1000057 intN;8typedefLong Longll;9 structpoint{Ten ll X; One ll y; A } P[MAXN]; - intS[MAXN]; - intVIS[MAXN]; the BOOLJudge (Point &p1,point &p2,point &p3) { -     return(P2.Y-P3.Y) * (p1.x-p3.x) > (P1.Y-P3.Y) * (p2.x-p3.x); - } - intMainintargcConst Char*argv[]) { +scanf"%d",&n); -      for(intI=0; i<n;i++) +scanf"%lld%lld",&p[i].x,&p[i].y); As[0]=0; at     intPtr=1; -     intCnt=0; -      for(intI=1; i<n;i++){ -         if(ptr>=2){ -              while(ptr>1&&!judge (p[s[ptr-2]],p[s[ptr-1]],p[i])) { -ptr--; in             } -vis[s[ptr-1]]=1; to         } +s[ptr++]=i; -     } the      for(intI=1; i<n;i++)if(Vis[i]) cnt++; *cout<<cnt<<Endl; $     return 0;Panax Notoginseng}

CCCC Preliminary l3-003 Great Wall

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.