Tree Recursion #include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; // A utility function to search x in arr[] of size n int search(char arr[], char x, int n) { for (int i = 0; i < n; i++) if (arr[i] == x) return i; return -1; } // Prints postorder traversal
Year: 2014
10334
Its a fibonicci series solution. I dont know why….But found that it shows the similiarity. #include <iostream> #include <vector> using namespace std; int fib[2000][5000]; vector<int> vb[2001]; int main() { fib[0][0]=1; fib[1][0]=2; fib[2][0]=3; int c=0; for(int i=3;i<2000;i++) { for(int j=0;j<5000;j++) { int t=fib[i-1][j]+fib[i-2][j]+c; fib[i][j]=t%10; c=t/10; } } //cout<<fib[3][0]; vb[0].push_back(1); vb[1].push_back(2); vb[2].push_back(3); for(int i=3;i<2000;i++) { int f=0;
12289
#include <iostream> #include <string> #include <vector> #include <string.h> using namespace std; int main() { int n; string str; cin>>n; while(n–) { cin>>str; if(str.size()==5) { cout<<"3"<<"\n"; continue; } int cnt=0; if(str[0]=='o'|| str[0]=='n' || str[0]=='e') { cnt++; } if((str[1]=='o'|| str[1]=='n' || str[1]=='e') && str[1]!=str[0]) { cnt++; } if((str[2]=='o'|| str[2]=='n' || str[2]=='e') && str[1]!=str[2] && str[2]!=str[0]) { cnt++;
10183
#include <iostream> #include <string> #include <vector> #include <string.h> using namespace std; int fib[600][1000]; vector <int> fibo[600]; int iSBig(int i,string s) { if(fibo[i].size()>s.size()) return 1; if(fibo[i].size()<s.size()) return 0; for(int j=0;j<s.size();j++) { if((s[j]-'0')<fibo[i][j]) { return 1; } if((s[j]-'0')>fibo[i][j]) { return 0; } } return 1; } int iSSmall(string s,int i) { if(fibo[i].size()>s.size()) return 0; if(fibo[i].size()<s.size()) return 1;
10088
[highlight]Theory[/highlight] Picks formulae ::: ans=area of polygon-B/2+1; Given a polygon whose vertices are of integer coordinates (lattice points), count the number of lattice points within that polygon.Pick’s theoreom states that where; is the area of the polygon. is the number of lattice points on the exterior Area of a polygon: First, number the vertices in
846
#include <iostream> #include <math.h> using namespace std; //long long diff[10001]; long long int m,n,d; int main() { int t; cin>>t; while(t–) { cin>>m>>n; d= m-n; if(d<0) d=d*(-1); if(d==0) { cout<<0<<"\n"; continue; } if(d==1) { cout<<1<<"\n"; continue; } if(d==2) { cout<<2<<"\n"; continue; } if(d==3) { cout<<3<<"\n"; continue; } long long int r= sqrt(d); if(r<0) r*=-1; if(d==r*r)
10023
[highlight]Solution[/highlight] /* import java.math.BigInteger; import java.util.Scanner; public class Main {public static void main(String[] args) { Scanner scanf = new Scanner(System.in); int time; time = scanf.nextInt(); System.out.println(""); for(int i = 0; i<time; i++){ BigInteger input = scanf.nextBigInteger(); if(i > 0) System.out.println(""); BigInteger previous = input; BigInteger distance, post, Two = BigInteger.valueOf(2), Negative = BigInteger.valueOf(-1); if(input.equals(BigInteger.ZERO)){ System.out.println("0");
10036
Modular Problem: Mod of a negative number ..llike -16%3 = 2 It is DP problem. such input of data is in p[]; divident is k; let , s=a[0]%k; and s=-a[0]%k; if any of s <0 then s =s+k [see mod of a negative number] keep track in 2D array in a[0][s]=1. s=s+p[1]%k, for each s check
10002
[highlight]Solution:[/highlight] Centroid of polygon The centroid of a non-self-intersecting closed polygon defined by n vertices (x0,y0), (x1,y1), …, (xn−1,yn−1) is the point (Cx, Cy), where Cx= 1/6A *sumof((X_i+X_i+1)*(X_i*Y_i+1 – X_i+1 * Y_i)); fori=0 to n-1 Cy= 1/6A *sumof((Y_i+Y_i+1)*(X_i*Y_i+1 – X_i+1 * Y_i));for i=0 to n-1 and where A is the polygon’s signed area, A =
10078
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point{ int x; int y; }P; vector<Point> vb,vb1; int used[100]; bool cmp(Point a,Point b) { if(a.x!=b.x) return a.x<b.x; else return a.y<b.y; } int ccw(Point a,Point b,Point c) { int p = a.x*b.y – a.x*c.y – a.y*b.x + a.y*c.x + b.x*c.y – c.x * b.y; if(p>0)