1466A - Bovine Dilemma - CodeForces Solution


brute force geometry math *800

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    w = [int(i) for i in input().split()]
    a = []
    for i in range(n-1):
        for j in range(n-i-1):
            if w[j+1+i] - w[j] not in a:
                a.append(w[j+i+1]-w[j])
    print(len(a))

C++ Code:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef complex<double> P;

#define pi 3.1415926
#define todegree(c) c*180.0/pi
#define torad(c) c*pi/180
#define X real()
#define Y imag()

const double eps = 1e-9;


int main()
{

    ll t;
    cin>>t;
    while(t--)
        {
            ll n;
            cin>>n;
            vector<double> v;
            for(int i=0;i<n;i++)
                {
                    double temp;
                    cin>>temp;
                    v.push_back(temp);
                }

            P tree= {0.0,1.0};
            map<ll,bool> mp;
            ll ans=0;
            for(int i=0;i<n;i++)
                {
                    for(int j=i+1;j<n;j++)
                        {
                   //         cout<<v[i]<<" "<<v[j]<<" ";
                            P point1 = {v[i],0};
                            P point2 = {v[j],0};
                            double a = abs(tree-point1);
                            double b = abs(tree-point2);
                            double c = abs(point1-point2);
                            double s = (a+b+c)/2;
                            double area = (s*(s-a)*(s-b)*(s-c));
                            area = sqrt(area);
                            area = round(area*10000);

                     //       cout<<area<<endl;
                            if(!mp[(int)area]){ans++;mp[(int)area]=1;}
                        }
                }
            cout<<ans<<endl;
        }


    return 0;
}


Comments

Submit
0 Comments
More Questions

1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph
1711D - Rain