Answer to Question #280165 in C for Rahul Sigh

Question #280165

A university's library has been having electricity issues and students have been struggling to study during nights.


Each light source can illuminate a circle with a radius of r, and there are n tables in the library and the ith table is positioned at point (xi, yi). You have to help the university find the minimum number of light sources (k), such that each table is illuminated by at least 1 light source.



Input format


• The first line contains integers n and r respectively.


• In each of the next n lines, there are two integers representing xi and yi respectively that display the position of the ith table.


Output format


• In the first line of output, print an integer k that represents the number of light sources.


• In each of the next k lines, print two decimal numbers representing xi, yi respectively that shows the location of the ith light source.


https://drive.google.com/file/d/1wWA7nKnFWaG5XgtzzLPymfbuqiIf7WH8/view?usp=sharing




1
Expert's answer
2021-12-16T04:46:41-0500
#include <bits/stdc++.h>
using namespace std;


int main()
{
    int n,r,count = 0;
    
    cin>>n>>r;
    
    int x[n], y[n];
    
    for (int i = 0; i<n; i++)
    {
        cin>>x[i]>>y[i];
        
        if (abs(x[i] - y[i]) == r)
        {
            count += 1;
            cout<<count<<endl;
            cout<<x[i]<<" "<<y[i]<<endl;
        }
        else
        {
            count += 0;
        }
    }
    
   
    
    
    
    
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS