10067

#include <iostream> #include <queue> using namespace std; bool visit[10][10][10][10]; int arr[3]={0,1,-1}; struct states{ int a,b,c,d; int step; }; int main() { int t,n,stp; states tmp; int tw,tx,ty,tz; int a,b,c,d,x,y,w,z; cin>>t; while(t–) { states src,trgt,tmp; for(int i=0;i<10;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++) for(int l=0;l<10;l++) visit[i][j][k][l]=0; cin>>a>>b>>c>>d; src.a=a; src.b=b; src.c=c; src.d=d; src.step=0; cin>>a>>b>>c>>d; trgt.a=a; trgt.b=b; trgt.c=c; trgt.d=d; trgt.step=-1;

10047

#include <iostream> #include <queue> #define Green 0 #define Black 1 #define Red 2 #define Blue 3 #define White 4 #define N 0 #define W 1 #define S 2 #define E 3 using namespace std; struct states{ int ro,col,wt,direction,wheelcolr; }; int m,n,ans; bool bfs(states src,states trgt,char gr[30][30]) { int r,c,d,colr,weight; states tmp; queue<states> q; q.push(src); bool

1645

#include <iostream> #include <cstdio> #define ll long long using namespace std; ll dp[1010]; int main() { int n,kase=1; dp[1]=1; for(int i=2;i<1001;i++) { for(int j=1;j<i;j++) { if((i-1)%j==0) { dp[i]+=dp[j]; dp[i]%=1000000007; } } } while(scanf("%d",&n)!=EOF) { cout<<"Case "<<kase++<<": "<<dp[n]<<"\n"; } return 0; }  

11340

#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <map> using namespace std; map<char,int> mp; int main() { int t,n,k,val; char c; cin>>t; getchar(); while(t–) { cin>>n; getchar(); mp.clear(); while(n–) { scanf("%c %d",&c,&val); getchar(); mp=val; } cin>>k; getchar(); double ans=0; while(k) { c=getchar(); if(c=='\n') k–; else ans+=mp; } printf("%.2lf$\n",ans/100); } return 0; }  

1636

Probability: Probability of survival without spin = (total number of adjacent pair of zeros)/(total number of empty + bullets ); Probability of survival with spin/rotation = (total number of zeros)/(total number of empty + bullets ); SO, P_s_without_spin = total adjacent zero/length; P_s_with_spin  = total zero/length; if(P_s_without_spin == P_s_with_spin) total adjacent zero/length = P_s_with_spin  =

1644

#include <iostream> #include <cstdio> #include <cmath> #include <vector> using namespace std; int n; int arr[1300000]; vector<int> v; int main() { int lo,hi,mid; for(int i=0;i<1300000;i++) { arr[i]=0; } for(int i=2;i<sqrt(1300000);i++) { if(arr[i]==0) { for(int j=i+i;j<1300000;j+=i) { arr[j]=1; } } } for(int i=2;i<1300000;i++) { if(arr[i]==0) { v.push_back(i); } } //cout<<v.size()<<"\n"; while(scanf("%d",&n),n) { if(arr[n]==0) { cout<<0<<"\n"; continue; }

10679

KMP algo solution* */ /* #include<stdio.h> #include<string.h> #include<stdlib.h> #include <iostream> using namespace std; void computeLPSArray(char *pat, int M, int *lps); bool KMPSearch(char *pat, char *txt) { int M = strlen(pat); int N = strlen(txt); // create lps[] that will hold the longest prefix suffix values for pattern int *lps = (int *)malloc(sizeof(int)*M); int j =

Pattern Search Problem

There are several algorithm to solve pattern search from a provided string problem. To solve such problem using Naive method(for all the char of the provided string check whether the pattern  contains or not ). It takes O(m*n),here m = string length of pattern and n= string length of the text. There are several algorithm to solve