QUADCNT - Editorial

PROBLEM LINK:

Practice
Contest

Author: Dheeraj Bhagchandani
Tester: Nipun khandelwal
Editorialist: Dheeraj Bhagchandani

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

SHIZUKA has N points that lie in a 2D plane and she wants to find no. of points in 1st , 2nd, 3rd, and 4th quadrant Help SHIZUKA in finding the points in each quadrant

QUICK EXPLANATION:

You are given Four points N points p1, p2, p3, . . . . . pN than you check every point that point belongs to which quadrant 1st, 2nd,3rd, or 4th. and then we Increase the count by 1 of that quadrant. And at last print it.

EXPLANATION:

let 1st quadrant is a, 2nd quadrant is b, 3rd quadrant is c,4th quadrant is d. Initially, all are zero. Then Every point we check that point belongs to which quadrant and then we found the quadrant we increase the count by one that quadrant.

Let Point is (x,y)

we check if( x> 0 && y > 0)a++;

if( x< 0 && y < 0)b++;

if( x< 0 && y < 0)c++;

if( x> 0 && y < 0)d++;

and than Print a,b,c,d.

See the Code for more Info.

SOLUTIONS:

Tester's Solution
 #include <bits/stdc++.h>
typedef long long ll;
#define vi vector<ll>
#define pi pair<ll,ll>
#define st  set<ll> 
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define fo(i,a,b)  for(ll i = a; i <= b; i++)
#define Rfo(i,a,b) for(ll i = a; i >= b; i--)
#define FOREACH(it, l) for (auto it : l)
#define sortVi(v) sort(v.begin(),v.end())
#define sortViR(v) sort(v.begin(),v.end(), greater<ll>())
#define sortArr(arr)  sort(arr,arr+n)
#define sortArrR(arr) sort(arr,arr+n greater<ll>())
#define Sq(a)  (a)*(a)
#define mod 1000000007
using namespace std;
ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    fo(i,1,sqrt(n)) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
bool prime(ll n){
    if(n<2) return false;
    ll cnt = 0;
    fo (i,2,sqrt(n)) {
        if (n % i == 0){
            return false;
        }
    }
    return true;
}
 
ll modPower(ll x,ll b,ll m)
{
    if (b == 0) return 1;
    if (b == 1) return x;
 
    ll r = modPower(x, b / 2,m);
    r=(r*r)%m;
 
    if (b%2 != 0) r = (r * x)%m;
 
    return r;
}
bool solve(ll A, ll B, ll K) 
{ 
    ll count = 0; 
  
    // since, the numbers are less than 2^31 
    // run the loop from '0' to '31' only 
    for (int i = 0; i < 32; i++) { 
  
        // right shift both the numbers by 'i' and 
        // check if the bit at the 0th position is different 
        if (((A >> i) & 1) != ((B >> i) & 1)) { 
            count++; 
            if(count>K)
                return false;
        } 
    }
 
    if(count<=K)
        return true;
    return false;
} 
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >>n;
    ll x, y,quad1=0,quad2=0,quad3=0,quad4=0;
    ll arr[n];
    ll arr2[n];
    fo(i,0,n-1){
        cin >> x >> y;
        if(x>0&&y>0){
            quad1++;
        }
        if(x>0&&y<0){
            quad4++;
        }
        if(x<0&&y>0){
            quad2++;
        }
        if(x<0&&y<0){
            quad3++;
        }
 
    }
    cout << quad1 << " " << quad2 << " " << quad3 << " " << quad4 << "\n";
 
    return 0;
} 
Setter's Solution
import java.io.*;
import java.math.*;
import java.util.*;


public class E {

    public static void main(String[] args) throws IOException {
         
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int a = 0,b = 0,c = 0,d = 0;
        while(n-- != 0) {
            long x = sc.nextLong(),y = sc.nextLong();
            if(x > 0 && y>0)a++;
            if(x>0 && y<0)d++;
            if(y<0 && x<0)c++;
            if(x<0 && y>0)b++;
        }
        out.println(a+" "+b+" "+c+" "+d);
        out.close();
 
    }

}
1 Like