A set of a set of points over a straight line is defined as correlative to some k if the absoute difference between any two point is multiple of k given n (2<=n=100000) points and some integer k (1<=k=1000) your task to find the largest set exists. n and k will be in first line of the input n line will follow each one single integer representing the location of the one point which is correlated to k in the first line of input remaing line will contain the points of the set one per line in increasing order
Answers
Answer:
set of points over a straight line is defined as correlative to some k if the absoute difference between any two point is multiple of k given n (2<=n=100000) points and some integer k (1<=k=1000) your task to find the largest set exists. n and k will be in first line of the input n line will follow each one single integer representing the location of the one point which is correlated to k in the first line of input remaing line will contain the points of the set one per line in increasing orderset of points over a straight line is defined as correlative to some k if the absoute difference between any two point is multiple of k given n (2<=n=100000) points and some integer k (1<=k=1000) your task to find the largest set exists. n and k will be in first line of the input n line will follow each one single integer representing the location of the one point which is correlated to k in the first line of input remaing line will contain the points of the set one per line in increasing order.
Answer:
#include <bits/stdc++.h>
using namespace std;
// function to find remainder set
int findSet(int arr[], int n, int k, int m) {
vector<int> remainder_set[k];
// calculate remainder set array
// and push element as per their remainder
for (int i = 0; i < n; i++) {
int rem = arr[i] % k;
remainder_set[rem].push_back(arr[i]);
}
// check whether sizeof any remainder set
// is equal or greater than m
for (int i = 0; i < k; i++) {
if (remainder_set[i].size() >= m) {
cout <<m<< "\n";
for (int j = 0; j < m; j++){
cout << remainder_set[i][j] << "\n";
}
return 1;
}
}
return 0;
}
// driver program
int main() {
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
int z;
int m = sizeof(arr)/sizeof(int);
for(int i=m;i>0;i--)
{
z=findSet(arr, n, k, i);
if(z==1)
break;
}
}
Explanation: