1. 程式人生 > >團體程序設計天梯賽-L3-009 長城

團體程序設計天梯賽-L3-009 長城

src bubuko efi time str string ring cst http

https://pintia.cn/problem-sets/994805046380707840/problems/994805050277216256

題目限制:烽火臺只能向左看。

當新加入的點導致下凸,則棧頂的點一定要選擇。

技術分享圖片

技術分享圖片

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <time.h>
 6 #include <string>
 7 #include <set>
 8
#include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20
#define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 ll x[maxn],y[maxn],z[maxn]; 27 bool vis[maxn]={0}; 28 29 ll cross(ll x1,ll y1,ll x2,ll y2) 30 { 31 return x1*y2-x2*y1; 32 } 33 34 int main() 35 { 36 int n,d,i,sum=0
; 37 ll xx,yy; 38 scanf("%d",&n); 39 d=0; 40 for (i=1;i<=n;i++) 41 { 42 scanf("%lld%lld",&xx,&yy); 43 while (d>1 && cross(x[d-1]-x[d],y[d-1]-y[d],x[d]-xx,y[d]-yy)<=0) 44 d--; 45 if (i>=3) 46 vis[z[d]]=1; 47 d++; 48 x[d]=xx,y[d]=yy,z[d]=i; 49 } 50 for (i=2;i<=n;i++) 51 sum+=vis[i]; 52 cout<<sum; 53 return 0; 54 } 55 /* 56 3 57 2 1 58 1 0 59 0 1 60 61 5 62 5 0 63 4 0 64 3 0 65 2 0 66 1 0 67 */

團體程序設計天梯賽-L3-009 長城