Responsive Ads Here
Showing posts with label Contest. Show all posts
Showing posts with label Contest. Show all posts

Sunday, 28 May 2017

Team Formation For Snackdown

problem id:--https://www.codechef.com/SNCKPA17/problems/TEAMFORM


code:--

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
for(int i=1;i<=m;++i)
{
int num;
cin>>num>>num;
}
string ans[]={"yes","no"};
cout<<ans[n&1]<<'\n';
}
return 0;
}

Saturday, 27 May 2017

Prefix Inversions

problem id:--https://www.codechef.com/LTIME48/problems/PREFINVS


code:--

#include<iostream>
using namespace std;
int main()
{
string str;
cin>>str;
int l=str.length()-1,count=0;
char ch;
while(l>=0 && str[l]=='0')
{
--l;
}
if(l>=0)
do
{
if(str[l]=='0')
++count,ch=str[l];
else
++count,ch=str[l];
while(l>=0 && str[l]==ch)
{
--l;
}
}while(l>=0);
cout<<count<<'\n';
return 0;
}

Friday, 26 May 2017

Bond And Fond (codechef contest)

problem id:--https://www.codechef.com/LOCMAY17/problems/BONDFOND


code:--

#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
long long n,num,count=0,m,temp1,temp2,temp=1;
while(t--)
{
count=0;
cin>>n;
if((n&(n-1))==0)
{
cout<<0<<'\n';
continue;
}
num=n;
while(num)
{
++count;
num=num>>1;
}
temp1=n-(temp<<(count-1));
temp2=(temp<<count)-n;
m=temp1<temp2? temp1:temp2;
cout<<((temp1<temp2)? temp1:temp2)<<'\n';
}
return 0;

Wednesday, 24 May 2017

Snake Procession(codechef)

problem id:--https://www.codechef.com/SNCKQL17/problems/SNAKPROC

code:--


#include<iostream>
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
int l;
cin>>l;
string str;
cin>>str;
int i=0,flag=1;
string ans[]={"Invalid","Valid"};
while(str[i]!='\0')
{
if(str[i]!='.')
{
if(str[i]=='H' && flag==1)
flag=2;
else if(str[i]=='T' && flag==2)
flag=1;
else
{
flag=2;
break;
}
}
++i;
}
cout<<ans[(flag&1)]<<'\n';
}
return 0;
}

Temple Land(codechef)

problem id:-https://www.codechef.com/SNCKQL17/problems/TEMPLELA

code:--

  1. #include<iostream> #include<vector> using namespace std; int main() { int t; cin>>t; while(t--) { int n; cin>>n; int arr[n],flag=1; string ans[]={"no","yes"}; for(int i=0;i<n;++i) cin>>arr[i]; if((n&1)==0) flag=0; else { for(int i=1;i<=n;++i) if(i<=n/2) { if(i!=arr[i-1]) { flag=0; break; } } else { if((n-i+1)!=arr[i-1]) { flag=0; break; } } } cout<<ans[flag]<<'\n'; } return 0; }