// # CODE: TREE2
// first line of input contains the testcases
// next line contains number of sticks (n) and the next line
// contains height of the sticks
//     logic:
//         we input the heights of sticks into a list (sticks)
//         then we extract all the unique elements of the sticks
//         and append them to a new list (uniqueHeight) the length
//         of the unique list will be number of passes required to
//         cut the sticks because the number of passes will be equal
//         to the number of unique elements in the list. The cut part
//         should be equal i.e., h - H should be equal for all the sticks
//         being cut.
#include <iostream>
#include <algorithm>
using namespace std ;
int remove_duplicates(long int a[], long int temp1){
    if (temp1 == 0 || temp1 == 1)
        return  temp1 ;
    long int temp2[temp1];
    long int j = 0 ;
    for (long int i = 0; i < temp1 - 1; ++i) {
        if (a[i] != a[i+1]){
            temp2[j++] = a[i];
        }
    }
    temp2[j++] = a[temp1 - 1];
    for (long int i = 0; i < j; ++i) {
        a[i] = temp2[i];
    }
    return  j ;
}
int main(){
    long int t ;
    cin >> t ;
    while (t > 0){
        long int n ;
        cin >> n ;
        long int a[n];
        for (long int i = 0; i < n; ++i) {
            cin >> a[i] ;
        }
        sort(a,a+n);
        long int temp1 = sizeof(a)/sizeof(a[0]);
        temp1 = remove_duplicates(a, temp1);
        if (a[0] == 0){
        temp1 -- ;
        cout << temp1 << '\n' ;
        } else{
            cout << temp1 << '\n';
        }
        t-- ;
    }
    return 0 ;
}
 
bro i am not geting coronavirus spread 2 . when will u share solution?
ReplyDeleteI have already post the solution.
DeleteIt is giving segmentation fault
ReplyDeletehow to solvw the below error:
ReplyDeleteexpression must have a constant value -- the value of parameter "temp1" (declared at line 5) cannot be used as a constantC/C++(28)
bro ,sub task 1 (of 20 points ) is failing ,but ive got AC and 80 points in the subtask 2 .(orignal constraints). can you help me? I don`t know if there is any special test case ,which is failing for N<50.
ReplyDeleteThanks. :)