Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- int n;
- ifstream f("hotar.in");
- f>>n;
- struct varf
- {
- float x,y;
- };
- varf v[16];
- for(int i=1;i<=n;++i)
- f>>v[i].x>>v[i].y;
- f.close();
- float x,y;
- ofstream g("hotar.out");
- if(n==3)
- {
- x=(v[2].x+v[3].x)/2.0;
- y=(v[2].y+v[3].y)/2.0;
- x=(int)(x*1000);
- x/=1000;
- y=(int)(y*1000);
- y/=1000;
- g<<fixed<<setprecision(3)<<x<<' '<<y<<'\n';
- return 0;
- }
- long double s=0; /// suprafata poligonului
- float term;
- for(int i=1;i<=n;++i) /// Calculam suprafata poligonului
- {
- if(i<n)
- term=v[i].x*v[i+1].y-v[i+1].x*v[i].y;
- else
- term=v[i].x*v[1].y-v[1].x*v[i].y;
- s+=term;
- }
- s/=4; /// jumatate din suprafata s/2 a poligonului
- long double sp=0,k; /// s=suprafata poligonului pana in varful p; k= raportul suprafetelor
- for(int i=1;i<=3;++i) /// Calculam suprafata poligonului format din primele 3 puncte
- {
- if(i<3)
- term=v[i].x*v[i+1].y-v[i+1].x*v[i].y;
- else
- term=v[i].x*v[1].y-v[1].x*v[i].y;
- sp+=term;
- }
- sp/=2;
- for(int p=4;p<=n;++p)
- {
- if(sp==s)
- {
- g<<v[p-1].x<<".000 "<<v[p-1].y<<".000\n";
- return 0;
- }
- long double sp1=0; /// suprafata poligonului pana in varful p
- float term;
- for(int i=1;i<=p;++i) /// Calculam suprafata poligonului pana in varful p
- {
- if(i<p)
- term=v[i].x*v[i+1].y-v[i+1].x*v[i].y;
- else
- term=v[i].x*v[1].y-v[1].x*v[i].y;
- sp1+=term;
- }
- sp1/=2;
- if(s>sp&&s<sp1)
- {
- k=(sp1-s)/(s-sp);
- x=(v[p].x+k*v[p-1].x)/(k+1),y=(v[p].y+k*v[p-1].y)/(k+1);
- x=(int)(x*1000);
- x/=1000;
- y=(int)(y*1000);
- y/=1000;
- g<<fixed<<setprecision(3)<<x<<' '<<y<<'\n';
- return 0;
- }
- sp=sp1;
- }
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement