Here you will find solutions of many problems on spoj. If you want solution of some problem which is not listed in blog or have doubt regarding any spoj problem (which i have solved) or any programming concept (data structure) you can mail me @ raj.nishant360@gmail.com

And my humble request to you all that don't copy the code only try to understand the logic and algorithm behind the code. I have started this because if you tried as hard as you can and still can't find any solution to the problem then you can refer to this.
You can read my answer how to start competitive programming CLICK HERE

Thursday, March 27, 2014

GSSQUNCE-Sequence

Sequence

below given code is for gssqunce spoj or sequence spoj.
easy one ... no need of explanation here only check if number is repeated more then twice then it can not form sequence .
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <sstream>
#include <fstream>
#include <climits>
#include <ctime>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main()
{
 int t;
 scanf("%d",&t);;
 while(t--)
 {
  int n;
  scanf("%d",&n);
  int a[60000],flag=1;
  map<int ,int>mp;
  map<int ,int >::iterator t;
  for(int i=0;i<n;i++)
   scanf("%d",&a[i]),mp[a[i]]+=1;
  for(t=mp.begin();t!=mp.end();t++)
   if((*t).second >2){
    flag=0;
    break;}
  if(flag==0 || n==1)
   printf("NO\n");
  else
   printf("YES\n");
 }
 return 0;
}

No comments:

Post a Comment

Your comment is valuable to us