RSLN2202-Editorial

PROBLEM LINK:

Escape Plan

Author: Shreenath
Tester: Gaurav Pratyaksh
Editorialist: Shreenath

DIFFICULTY:

EASY

PREREQUISITES:

Simple Maths

PROBLEM:

Dogesh and his entire kingdom live in a castle. Many times, they have received war threats from their neighborhood kingdom were monkeys live. To save his life and his kingdom he asks his friend, Cheems for help. Cheems suggests to construct some tunnels in the Warfield which opens up on the opposite side of the castle.

Assume that castle of Dogesh lies on the line represented as y=mx+c and a set of NN points on Warfield in the form of (Xi,Yi) for each 1≤Xi≤N, 1≤Yi≤N. You have to find out the number of pair of points which upon joining will make the tunnel that will help Dogesh to reach the opposite side of castle.

Note: Do not consider those points which lie on the castle (the given line).

EXPLANATION:

In the given problem we have to find number of pair of points which on joining makes a line segment that intersects the given line.

So we have to do very simple calculation that we have to just count number of points that are left and right of the line or up or down i.e. on opposite sides of the given line.

Once we do this we have to multiply the two values we count to get the final answer.

SOLUTIONS:

Setter's Solution / Editorialist's solution
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    int t;
    cin>>t;
    while(t--)
    {
        long int n,m,c,p=0,q=0;
        cin>>n>>m>>c;
        for(int i=0;i<n;i++)
        {
            long int a,b,l;
            cin>>a>>b;
            l=m*a-b+c;
            if(l<0)
                p++;
            else if(l>0)    
                q++;
        }
        cout<<p*q<<endl;
    }
}
Tester's Solution / Gaurav
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int test=0;
    cin>>test;
    while(test--){
        long long int n,m,c;
        cin>>n>>m>>c;
        long long int neg=0,pos=0;
        while(n--)
        {
            long long int x,y,k;
            cin>>x>>y;
            k=m*x;
            int temp=y-k-c;
            if(temp<0)
                neg++;
            else if(temp>0)
                pos++;
        }
        cout<<pos*neg<<endl;
    }
    return 0;
}
Tester's Solution / Pratyaksh
#include <bits/stdc++.h>
using namespace std;

int main() 
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    int test=0;
    cin>>test;
    while(test--){
        long long int n,m,c;
        cin>>n>>m>>c;
        long long int neg=0,pos=0;
        while(n--)
        {
            long long int x,y,k;
            cin>>x>>y;
            k=m*x;
            int temp=y-k-c;
            if(temp<0)
                neg++;
            else if(temp>0)
                pos++;
        }
        cout<<pos*neg<<endl;
    }
    return 0;
}