#include <iostream> #include <cstdio> using namespace std; int arr[25000]; struct path{ int len,st,en; }; path p; int kadanesAlgo(int rd,int first) { int max_end_here=0,max_so_far=0; int begin=first,length; int finish=0,start=first; for(int i=first;i<rd;i++) { max_end_here+=arr[i]; if(max_end_here<0) { max_end_here=0; begin=i+1; } if(max_end_here>max_so_far) { max_so_far = max_end_here; start=begin; finish=i+1; length=finish-start+1; p.len=length; p.en=finish; p.st=start; } else if(max_end_here==max_so_far) { max_so_far = max_end_here; start=begin;
Author: Asif Naeem
10196
#include <iostream> #include <string> #include <cstring> #include <cstdio> using namespace std; char board[8][8]; struct IDX{ int i,j; }; bool isCheck_knight(int I,int J,int color) { int dx[8]={1,1,-1,-1,2,2,-2,-2}; int dy[8]={2,-2,2,-2,1,-1,1,-1}; int a,b; for(int i=0;i<8;i++) { a=dx[i]+I; b=dy[i]+J; if(a>=0 && a<8 && b>=0 && b<8) { if(board[a][b]=='N' && color==0) return 1; else if(board[a][b]=='n' && color==1) return 1; }
694
#include <iostream> #include <cstdio> #define ll long long using namespace std; int check(ll num,ll limit) { ll a=num,b=limit; int cnt=0; while(a<=limit) { if(a%2) { a=(a*3+1); cnt+=1; if(a>limit) return cnt-1; } else { a/=2; cnt+=1; if(a==1) return cnt; } } return cnt; } int main() { ll num,limit; int c; int kase=1; while(cin>>num) { cin>>limit; if(num==-1
11713
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int main() { int t; string st1,st2; cin>>t; while(t–) { cin>>st1; cin>>st2; if(st2.size()!=st1.size()) { cout<<"No\n"; continue; } bool f=0; for(int i=0;i<st1.size();i++) { if(st1[i]!=st2[i]) { char a=st1[i]; char b=st2[i]; if(a!='a' && a!='e' && a!='i' && a!='o' && a!='u') { f=1; } else if(b!='a' && b!='e'
455
#include <iostream> #include <cstdio> #include <string> using namespace std; string str; bool check(string p,string s) { int ll=s.size(); int k=0; while(k!=ll) { for(int i=0;i<p.size();i++) { if(p[i]!=s[k++]) return 0; } } return 1; } int main() { int t; bool line=0,done=0; bool f; string blnk,p; cin>>t; getline(cin,blnk); getline(cin,blnk); //addxascc //abcsabcxsabcs while(t–) { if(line) cout<<endl; line=1; getline(cin,str);
10048
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #define INF 1000000 using namespace std; int gr[105][105]; int _mn(int a,int b) { if(a>b) return b; return a; } int _mx(int a,int b) { if(a>b) return a; return b; } int main() { bool f=0; int kase=1; int C,S,Q; int a,b,d; while(cin>>C) { cin>>S>>Q; if(C+S+Q==0) break; for(int
10168
Golbach’s Conjecture: Any even number can be expressed as a summation of two prime numbers. This idea is used to solve the problem. if the number is odd then .ie 49 thn 2,3 and goldbach conjechture of (49-5) can be expressed as sum of 2 primes. if the number is even then 2,2 and goldbach
729
Using Back Track Algorithm: #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <algorithm> using namespace std; int N,H; int backtrack(int idx,int cnt,int a[20]) { if(cnt==N-H) { for(int i=1;i<=N;i++) cout<<a[i]; cout<<"\n"; return 0; } for(int i=idx;i<=N;i++) { a[i]=0; backtrack(i+1,cnt+1,a); a[i]=1; } return 0; } int main() { int t; string s; cin>>t; getchar(); getline(cin,s); int
138
Theory: Perfect square problem.Problem is to determine a pair of numbers where the small (lower_num) number divides the numbers from 1 up to higher_num into two groups in a way that summation of 1 to (lower_num-1) is equal to summation of the numbers from (lower_num+1) to higher_num. Expanation: first pair 6 8 summation of 1
10193
#include <iostream> #include <cstring> #include <cstdio> #include <string> #include <algorithm> using namespace std; int gcd(int a,int b) { if(a%b==0) return b; else return gcd(b,a%b); } int main() { int t,kase=1,num1,num2; string s1,s2; // cin>>num1>>num2; // cout<<gcd(num1,num2)<<"\n"; cin>>t; while(t–) { cin>>s1; cin>>s2; num1=0; num2=0; int prev=1; for(int i=s1.size()-1;i>=0;i–) { num1=num1+(s1[i]-'0')*prev; prev*=2; } prev=1; for(int i=s2.size()-1;i>=0;i–) {