ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1640. Circle of Winter

#8 Any Help please
Posted by prog_islam 18 Apr 2015 01:50
#include<iostream>
#include<cmath>
#include<iomanip>
#include<vector>
using namespace std;
struct p
{
      double rec1;
     double rec2;
};
int main()
{
    vector<int> v;
    int n;
    cin>>n;
    if(1<=n&&n<=100)
    {
        int *ptr=new int[n*2];
        for(int i=0;i<(n*2);i++)
            cin>>ptr[i];
        if(n==1)
        {
            if(ptr[0]==0)
                cout<<ptr[0]+1<<" "<<ptr[1]<<" "<<1;
            else
            cout<<ptr[0]-1<<" "<<ptr[1]<<" "<<1;
        system("pause");
            return 0;
        }
            int lessx=0,highx=0,lessy=1,highy=1;
        for(int i=2;i<(n*2);i+=2)
        {
            if(ptr[i]<ptr[lessx])
                lessx=i;
            if(ptr[i]>ptr[highx])
            highx=i;
            if(ptr[i+1]<ptr[lessy])
                lessy=i+1;
            if(ptr[i+1]>ptr[highy])
            {

                v.clear();
                highy=i+1;
                v.push_back(i+1);
            }
            else if(ptr[i+1]==ptr[highy])
                v.push_back(i+1);



            }

        int point[2];
        point[0]=(ptr[lessx]+ptr[highx])/2.0;
        point[1]=(ptr[lessy]+ptr[highy])/2.0;
        for(int i=0;i<(n*2);i=i+2)
        {
            if(ptr[i]==point[0])
            {
                if(ptr[i+1]==point[1])
                {
                point[1]++;

                }
            }
        }

        cout<<point[0]<<" "<<point[1]<<" ";
        int p1,p2,max,min;
        if(v.size()>=2)
        {
         p1=highy;max=v[0]-1;p2=highy;min=v[0]-1;
        for(int i=1;i<v.size();i++)
        {
            if(ptr[v[i]-1]>point[0])
            {
                if(ptr[v[i]-1]>ptr[max])
                    p1=v[i];
            }
            else if(ptr[v[i]-1]<ptr[min])
                p2=v[i];
        }
        }
        int highp_y[2];
        if(v.size()>=2)
   {
        if((ptr[p1-1]-point[0])>(point[0]-ptr[p2-1]))
        {
            highp_y[0]=ptr[p1-1];
            highp_y[1]=ptr[p1];
        }
        else
        {
            highp_y[0]=ptr[p2-1];
            highp_y[1]=ptr[p2];
        }
    }
        else
        {
            highp_y[0]=ptr[highy-1];
            highp_y[1]=ptr[highy];
        }



        int lessp_x[2];
        lessp_x[0]=ptr[lessx];
        lessp_x[1]=ptr[lessx+1];
    double longr[2];
        p s;
        for(int i=1;i<=2;i++)
        {
            if(i==1)
            {
                s.rec2=point[0]-lessp_x[0];
            if(lessp_x[1]>point[1])
                s.rec1=lessp_x[1]-point[1];
            else
                s.rec1=point[1]-lessp_x[1];

                longr[0]=sqrt((s.rec1*s.rec1)+(s.rec2*s.rec2));

            }
            else
            {
                s.rec1=highp_y[1]-point[1];
                if(point[0]==highp_y[0])
                {
                    longr[1]=s.rec1;
                    break;
                }
                else
                {
                    if(point[0]>highp_y[0])
                        s.rec2=point[0]-highp_y[0];
                    else
                        s.rec2=highp_y[0]-point[0];
                    longr[1]=sqrt((s.rec1*s.rec1)+(s.rec2*s.rec2));
                }
            }
        }
        cout<<fixed<<setprecision(9);
        if(longr[0]>longr[1])
            cout<<longr[0];
        else
            cout<<longr[1];

        system("pause");
return 0;

    }
    system("pause");
return 0;

    }