10684 - The jackpot
Moderator: Board moderators
CE...
Is there any reason to have CE...! This is crazy....
Any one could debug my program and suggest me that it's ok or not...
Any one could debug my program and suggest me that it's ok or not...
Code: Select all
Thank you mf I was wrong in thinking..
AC.... :wink:
Last edited by Obaida on Thu Mar 27, 2008 11:59 am, edited 1 time in total.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
WA...
Ok... I traced why CE... I was using i in both loop... But now it is getting WA.... Help me...[/code]
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- New poster
- Posts: 16
- Joined: Sun Mar 02, 2008 10:34 am
- Location: SUST , Sylhet, Bangladesh
Re: 10684 - The Jackpot
Code: Select all
he can identify patterns of consecutive wins and elaborate a win-win strategy.
A bet is an amount of money and is either winning (and this is recorded as a positive value).
rajib
sust
life is beautiful like coding
Re: 10684 - The Jackpot
well this is how my code looks like if i have found it to be coorect its the maximum sum and used dp for it can any one plz tell my errors or provide me with test case which would help me realize my error
long long i,j,arr[1001];
while(cin>>n && n!=0)
{
long long s[1001] = {0};
FOR(i,1,n+1)
cin>>arr;
s[0] = 0;
FOR(i,1,n+1)
s = MAX(s[i-1]+arr,arr);
if(s[i-1]>0)
cout<<"The maximum winning streak is "<<s[i-1]<<"."<<endl;
else
cout<<"Losing streak."<<endl;
}
** MAX & FOR are simple macros that i have used
long long i,j,arr[1001];
while(cin>>n && n!=0)
{
long long s[1001] = {0};
FOR(i,1,n+1)
cin>>arr;
s[0] = 0;
FOR(i,1,n+1)
s = MAX(s[i-1]+arr,arr);
if(s[i-1]>0)
cout<<"The maximum winning streak is "<<s[i-1]<<"."<<endl;
else
cout<<"Losing streak."<<endl;
}
** MAX & FOR are simple macros that i have used
Re: 10684 - The Jackpot
Is this problem maximum consecutive sum or maximum sum ? I have tried both, but getting WA.
For example,
5 5 -1 5 5
Is the answer 10 or 19 ?
For example,
5 5 -1 5 5
Is the answer 10 or 19 ?
Code: Select all
#include<stdio.h>
#include<vector>
using namespace std;
int main()
{
int n,re;
re = scanf("%d",&n);
while(n)
{
vector<int> input;
int a;
for(int j=1;j<=n;j++)
{
scanf("%ld",&a);
input.push_back(a);
}
int sum = 0,maxs = 0;
int i = 0,j;
while(i<input.size())
{
sum = 0;
j = i;
while(j<input.size())
{
sum = sum + input[j];
j++;
maxs = max(sum,maxs);
}
i++;
}
if(maxs>0)
printf("The maximum winning streak is %d.\n",maxs);
else
printf("Losing streak.\n");
re = scanf("%d",&n);
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10684 - The Jackpot
maximum possible gain out of a sequence of consecutive bets.
19.
Use %d when reading an int in scanf.
19.
Use %d when reading an int in scanf.
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 3
- Joined: Fri Mar 01, 2013 6:17 pm
Re: 10684 - The Jackpot
Why WA, where am I wrong?
Code: Select all
#include <stdio.h>
#include <iostream>
#include <iterator>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)&&n!=0){
std::istream_iterator<int> int_it(cin),end;
int sum=*int_it++;
for(int i=2;i<n;++i)
{
sum+=*int_it++;
if(sum<0)
sum=0;
}
sum+=*int_it;
if(sum>0)
printf("The maximum winning streak is %d.\n",sum);
else
printf("Losing streak.\n");
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10684 - The Jackpot
Try input:
1
1
0
1
1
0
Check input and AC output for thousands of problems on uDebug!
-
- New poster
- Posts: 14
- Joined: Sun Jan 20, 2013 1:58 am
Re: 10684 - The Jackpot
Hi,
today I made this problem and I found something interesting.
I sent my code and while it was in queue I realized that my code failed for this case:
1
1
0
So I sent it again, but with the correction.
The funny thing is that when I checked I had the two submissions accepted.
The firstone's output was:
today I made this problem and I found something interesting.
I sent my code and while it was in queue I realized that my code failed for this case:
1
1
0
So I sent it again, but with the correction.
The funny thing is that when I checked I had the two submissions accepted.
The firstone's output was:
and the second's:Losing streak.
How could be this possible?The maximum winning streak is 1.
Last edited by MauriWilde on Sun Jun 01, 2014 9:28 pm, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 10684 - The Jackpot
The second is correct. The judge can't test all possible inputs, so whatever was wrong with your code isn't tested by the judge's I/O.
Check input and AC output for thousands of problems on uDebug!
Re: 10684 - The Jackpot
Getting wrong answer.Need help
Code: Select all
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdio>
#include<stdlib.h>
#include <queue>
#include <stack>
#include<string>
#include<list>
#include<map>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
int n,x;
long long sum,max;
while(scanf("%d",&n) == 1 && n)
{
max = -1;
sum = 0;
while(n--)
{
scanf("%d",&x);
if(x < 0)
{
if(max < sum)
max = sum;
sum =0;
}
else
sum = sum + x;
}
if(max < sum)
max = sum;
if(max > 0)
printf("The maximum winning streak is %lld.\n",max);
else
printf("Losing streak.\n");
}
return 0;
}
Re: 10684 - The Jackpot
try this
input:
input:
output:5
12 -4
-3 4
9
0
The maximum winning streak is 18.
Re: 10684 - The Jackpot
I got TLE with this code but when I tried n=10000 it work faster than 3s.
Please help me improve my code.
Please help me improve my code.
Code: Select all
#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
int sum,n[10005],tmp[10005],big;
while(1)
{
scanf("%d",&sum);
if(sum==0)
break;
for(int i=0;i<sum;i++)
{
scanf("%d",&n[i]);
tmp[i]=n[i];
}
big=*max_element(n,n+sum);
for(int i=1;i<sum;i++)
{
for(int j=0;j<sum-i;j++)
{
tmp[j]+=n[j+i];
if(big<tmp[j])
big=tmp[j];
}
}
if(big<1)
printf("Losing streak.\n");
else
printf("The maximum winning streak is %d.\n",big);
}
}