团体程序设计天梯赛(CCCC) L3009 长城 方法证明

 

团体程序设计天梯赛代码。体现代码技巧,比赛技巧。  https://github.com/congmingyige/cccc_code

 

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <algorithm>
 6 #include <set>
 7 #include <map>
 8 #include <queue>
 9 using namespace std;
10 
11 #define ll long long
12 
13 const int maxn=1e5+10;
14 const int inf=1e9;
15 const double eps=1e-8;
16 
17 
18 
19 struct node
20 {
21     ll x,y;
22     void init()
23     {
24         scanf("%lld%lld",&x,&y);
25     }
26     ///不要返回void,这妨碍了连续赋值操作(study from https://bbs.csdn.net/topics/330085641)
27     node operator==(node b)
28     {
29         return b;
30     }
31 }d[maxn],x,y;
32 
33 bool cross(node d1,node d2,node d3)
34 {
35     return (d2.y-d1.y)*(d2.x-d3.x) - (d2.x-d1.x)*(d2.y-d3.y) > 0;
36 }
37 
38 int main()
39 {
40     int n,i,g=0,w;
41     scanf("%d",&n);
42     d[1].init();
43     x.init();
44     w=1;
45     for (i=3;i<=n;i++)
46     {
47         y.init();
48         if (cross(d[w],x,y))
49             g++,d[++w]=x;
50         else
51         {
52             while (w>=2 && !cross(d[w-1],d[w],y))
53                 w--;
54         }
55         x=y;
56     }
57     printf("%d",g);
58     return 0;
59 }
60 /*
61 5
62 5 100
63 4 5
64 3 -100
65 2 0
66 0 -6
67 output 1
68 */

 

posted @ 2019-04-16 22:08  congmingyige  阅读(368)  评论(0编辑  收藏  举报