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

本文分享了一段团体程序设计天梯赛的代码,详细解析了代码中涉及的数据结构和算法技巧,如长整型变量处理、结构体定义、输入输出优化等,适合对算法竞赛感兴趣的学习者参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

团体程序设计天梯赛代码。体现代码技巧,比赛技巧。  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.youkuaiyun.com/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 */

 

转载于:https://www.cnblogs.com/cmyg/p/10720406.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值