Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- ifstream fin("infasuratoare.in");
- ofstream fout("infasuratoare.out");
- const int NMAX=120003;
- struct Punct
- {
- double x,y;
- };
- Punct a[NMAX];
- int n,st[NMAX],top;
- bool viz[NMAX];
- ///v[i]->1 <=> pct i se afla pe stiva
- ///returneaza <0 daca punctul a[p] este in semiplanul -
- ///al dreptei det. de punctele (a[i],a[j])
- /**
- <0 ->semiplanul -
- >0 ->semiplanul +
- =0 ->coliniaritate
- */
- inline double F(int i,int j,int p)
- {
- return a[p].x*(a[i].y-a[j].y)+
- a[p].y*(a[j].x-a[i].x)+
- a[i].x*a[j].y-a[j].x*a[i].y;
- }
- inline void READ()
- {
- fin>>n;
- for(int i=1; i<=n; i++)
- fin>>a[i].x>>a[i].y;
- }
- ///sortez punctele dupa y,in caz de egalitate dupa x
- inline bool Sort(const Punct A,const Punct B)
- {
- if(A.y==B.y)
- return A.x<B.x;
- return A.y<B.y;
- }
- ///algoritmul lui HILL
- inline void HILL()
- {
- sort(a+1,a+n+1,Sort);
- ///ca rezolvare folosim o stiva(de preferabil de mana)
- ++top;
- st[top]=1;
- ++top;
- st[top]=2;
- viz[2]=true;
- for(int i=3; i<=n; i++)
- {
- /**
- incercam sa punem pct i pe stiva
- scoatem punctele care se afla in semiplanul -,fata de pct i
- */
- while(top>1 && F(st[top-1],st[top],i)<0)
- {
- viz[st[top]]=false;
- top--;
- }
- ++top;
- st[top]=i;
- viz[i]=true;
- }
- for(int i=n-1; i>=1; i--)
- if(!viz[i])
- {
- while(F(st[top-1],st[top],i)<0)
- {
- viz[st[top]]=false;
- top--;
- }
- ++top;
- st[top]=i;
- viz[i]=true;
- }
- }
- inline void Solve()
- {
- fout<<(top-1)<<"\n";
- for(int i=1;i<top;i++)
- fout<<fixed<<setprecision(12)<<a[st[i]].x<<" "<<a[st[i]].y<<"\n";
- }
- int main()
- {
- READ();
- HILL();
- Solve();
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement