JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (oldest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
getting WA in IPL1 | Reply
I am getting WA in this question..
http://www.spoj.com/problems/IPL1/
pls hlp..
here is my code...

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <queue>
#include <stack>
#include <deque>
#include <cstring>
#include <cstdlib>
#include <climits>
//#include <boost>
using namespace std;

#define FOR(I,A,B) for(int I= (A); I<(B); ++I)
#define REP(I,N) FOR(I,0,N)
#define S(N) scanf("%d", &N)
#define S_String(A) scanf("%s",A)
#define SL(N) scanf("%ld", &N)
#define SLL(N) scanf("%lld", &N)
#define PR(N) printf("%d\n",N)
#define PRL(N) printf("%ld\n",N)
#define PRLL(N) printf("%lld\n",N)
#define SPACE printf(" ")
#define NEW_LINE printf("\n")

typedef long long int LL;
typedef vector<int> VI;

double dp[10][120][300];
int runs,wickets,balls,target;

void convert_over(string str)
{
int overs=0,i=0,ball;
while(str[i]!='.')
{
overs=10*overs+str[i]-'0';
i++;
}
if(str[i]=='.')
{
ball=str[++i]-'0';
}
balls=6*overs+ball;
}

void convert_score(string str)
{
int i=0;
//bool flag=false;
runs=0;
wickets=0;
while(str[i]!='/')
{
runs=10*runs+str[i]-'0';
i++;
}
if(str[i]=='/')
{
wickets=10*wickets+str[++i]-'0';
}
}


double recursion(int balls, int reqRuns, int wickets)
{
if (reqRuns<=0)
return 1;

if (balls==120||wickets==10)
return 0;

if((int)dp[wickets][balls][reqRuns]>=0)
return dp[wickets][balls][reqRuns];

dp[wickets][balls][reqRuns]=(recursion(balls+1, reqRuns,wickets)+recursion(balls+1, reqRuns-1,wickets)+
recursion(balls+1, reqRuns-2,wickets)+recursion(balls+1, reqRuns-3,wickets)+
recursion(balls+1, reqRuns-4,wickets)+recursion(balls+1, reqRuns-5,wickets)+
recursion(balls+1, reqRuns-6,wickets)+recursion(balls+1, reqRuns,wickets+1)+
2*recursion(balls, reqRuns-1,wickets))/10;

return dp[wickets][balls][reqRuns];

}

void convert_ans(string str)
{
int i=0;
string str1="";
while(str[i]!='.')
{
str1=str1+str[i];
i++;
}
if(str[i]=='.')
{
str1=str1+str[i];
i++;
str1=str1+str[i];
i++;
str1=str1+str[i];
}
cout<<str1><<endl;
}

int main()
{
int t;
string score,overs;
S(t);
while(t--)
{
memset(dp,-1,sizeof dp);
cin>>overs;
convert_over(overs);
// cout<<balls><<endl;
cin>>score;
convert_score(score);
// cout<<score><<endl;
cin>>target;

if(runs>=target)
{
cout<<"100.00"<<endl;
continue;
}

else if(wickets==10)
{
cout><<"0.00"<<endl;
continue;
}

double finalAns=recursion(balls,target-runs,wickets)*100;
stringstream s;
s><<finalAns;
string st=s.str();
//cout<<s[2]><<endl;
convert_ans(st);
// printf("%.2lf\n",finalAns);
}
}
RSS