TopCoder SRM Matches


                                                      TopCoder SRM 532 Solution

 mr. Dengklek lives in the Kingdom of Ducks, where humans and ducks live together in peace and harmony.
The ducks are numbered by distinct positive integers from A to B, inclusive, where A <= B.  Last night, Mr. Dengklek could not sleep, so he tried to count all the ducks in the kingdom. (It is known that counting ducks can help people to fall asleep.) When counting the ducks, Mr. Dengklek walked across an imaginary meadow and whenever he saw a new duck, he called out its number. He only called out actual duck numbers, i.e., numbers from A to B. He never called the same number twice. The numbers he called out are not necessarily in the numeric order.  You are given a vector <int> ducks. The elements of ducks are the numbers
 Mr. Dengklek called out when counting the ducks last night. It is possible that he
 missed some of the ducks. Obviously, the number of ducks he missed depends on
the values A and B. The values of A and B are unknown to you.
Compute and return the smallest possible number of ducks Mr. Dengklek might have missed.

ALTHOUGH THIS QUESTION WS VERY EASY...I HAVE SOLVED THIS IN A VERY EASY WAY...


#include<iostream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<list>
#define show(x) copy(x.begin(),x.end(),output)
#include<iterator>
#define sort(x) sort(x.begin(),x.end())
#include<string>
#define vs vector<string>
#define vi vector<int>
#define pb push_back
#include<map>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<cstring>
#include<iomanip>
#include<cctype>
using namespace std;
class DengklekTryingToSleep
{
public:
int minDucks ( vector <int> ducks)
{
sort(ducks.begin(),ducks.end());
int flag = 0;
int A = ducks[0];
int B = ducks[ducks.size() - 1];
int ret = 0;
while(A < B )
{
flag = 0;
for(int i = 0 ; i <ducks.size() ; i++)
{
if(A == ducks[i])
{
flag++;
break;
}
}
if(flag == 0)
{
ret++;
}
A++;
}
return ret;
}
};