Page 1 of 2

11608 - No Problem

Posted: Sat May 16, 2009 10:41 pm
by kcode
I am getting TLE for this problem. I think it is because of (if I am not semantically wrong!) an infinite loop in the code, which is as a result of not specifying the test cases before the program starts. (Hope you get it) That is, I cant terminate the program.
Here is the code:

Code: Select all

#include <iostream>
#include <vector>

using namespace std;

vector<int> probs_created(12), probs_required(12);
int S;
int probs_available, flag;

void get_input()
{
    int i;
    cin >> S;
    probs_available = S;
    for (i=0; i<12; i++) cin >> probs_created[i];
    for (i=0; i<12; i++) cin >> probs_required[i];
    cin >> flag;
}

int main()
{
    int cse = 0,j;

    while(true){
        get_input();
        cout << "Case " << cse+1 << ":" << endl;
        for (j=0; j<12; j++){
            if (probs_available >= probs_required[j]){
                probs_available -= probs_required[j];
                probs_available += probs_created[j];
                cout << "No Problem! :D" << endl;
            }
            else{
                probs_available += probs_created[j];
                cout << "No Problem. :(" << endl;
            }
        }
        if (flag < 0) break;
        cse += 1;
    }
}

Re: 11608 - No Problem

Posted: Mon May 18, 2009 9:08 am
by sohel
I don't think you are reading the input in the correct format.
Run your code for inputs like this, and see if you are printing the correct output.

Code: Select all

5
3 0 3 5 8 2 1 0 3 5 6 9
0 0 10 2 6 4 1 0 1 1 2 2
5
3 0 3 5 8 2 1 0 3 5 6 9
0 0 10 2 6 4 1 0 1 1 2 2
-3

Re: 11608 - No Problem

Posted: Mon May 18, 2009 11:38 pm
by kcode
Got it, thanks.

11608 - No Problem-getting wa ??why??

Posted: Tue May 19, 2009 9:57 pm
by bm_anas
hi,i m getting wa in this input.i dont understand my fault.could anybody check my prog.

#include<stdio.h>

int main()
{
int a[13],n,total[14],k=1,i;
bool flag[13];

while(scanf("%d",&n)==1)
{
if(n<0)
break;

total[1]=n;
for(i=1;i<13;i++)
{
scanf("%d",&a);
total[i+1]=total+a;
flag=false;
}

for(i=1;i<13;i++)
{
scanf("%d",&a);
if(total-a>=0)
flag=true;
}
printf("Case %d:\n",k++);
for(i=1;i<13;i++)
if(flag)
printf("No problem! :D\n");
else
printf("No problem. :(\n");
}

return 0;
}

Re: 11608 - No Problem

Posted: Wed May 20, 2009 4:56 pm
by MRH
Hi " bm_anas " your algorithm is wrong
read the problem again and then try to slove.
check for this input:
1
1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 2 2 2 2 2

my acc code output :

Case 1:
No problem. :(
No problem! :D
No problem. :(
No problem! :D
No problem. :(
No problem! :D
No problem. :(
No problem! :D
No problem. :(
No problem! :D
No problem. :(
No problem! :D

Re: 11608 - No Problem

Posted: Wed May 20, 2009 9:29 pm
by bm_anas
hi MRH thanks for ur help. :D

Re: 11608 - No Problem

Posted: Wed Jun 24, 2009 4:34 pm
by lnr
Accepted.

Re: 11608 - No Problem

Posted: Sat Jul 11, 2009 10:40 am
by Observer
I didn't run your code, but I see a very suspicious line:

Code: Select all

                cout << "No Problem. :(" << endl;
Any mistake here? :-D

Re: 11608 - No Problem

Posted: Fri Jul 17, 2009 11:55 pm
by New_AshkankhaN
Anybody can say what's my mistake?
i got WA

Code: Select all

// 11608.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdio.h"

int _tmain(int argc, _TCHAR* argv[])
{
	int s,count;
	int crtd[12];
	int rqrd[12];
	scanf("%d",&s);
	int c=1;
	while(s>0)
	{
		printf("Case %d:\n",c);
		c++;
		count=s;
		for(int i=0;i<12;i++)
			scanf("%d",&crtd[i]);
		for(int i=0;i<12;i++)
			scanf("%d",&rqrd[i]);
		for(int i=0;i<12;i++)
		{
			if(count>=rqrd[i])
			{
				printf("No problem! :D\n");
				count=count+crtd[i]-rqrd[i];
			}
			else
			{
				printf("No problem! :(\n");
				count=count+crtd[i];
			}
		}
		scanf("%d",&s);
	}
	return 0;
}



Re: 11608 - No Problem

Posted: Sat Jul 18, 2009 3:30 am
by helloneo
See Observer's post..

Re: 11608 - No Problem

Posted: Mon Sep 07, 2009 9:12 am
by LucasSchm
New_AshkankhaN, the problem says, "The first line of every test case has an integer S (0<=S<=100)", and on your code:

Code: Select all

 while(s>0) 
And check what Observer said...

Re: 11608 - No Problem

Posted: Sun Oct 04, 2009 12:35 pm
by mostafa_angel
Hi...
I got WA...
why !? I think my algorithm is correct ...

Code: Select all

#include <iostream>
#include <algorithm>
#include <string>


using namespace std;

int main()
{
	int sum , y[12] , p[12] , tmp;
	int cnt = 1;
	memset(y , 0 , sizeof(y));
	memset(p , 0 , sizeof(p));
	while(cin >> tmp , tmp > -1)
	{
		sum = tmp;
		for(int i = 0 ; i < 12 ; i++)
			cin >> p[i];
		for(int i = 0 ; i < 12 ; i++)
			cin >> y[i];
		cout << "Case " << cnt << ":" <<endl;
		for(int i = 0 ;i < 12 ; i++)
		{
			if (i == 0)
				if(sum >= y[0])
					sum -= (tmp - y[0]);
			else
				if(sum >= y[i-1])
					sum-= (p[i-2] - y[i-1]);
			sum+= p[i];
			
			
			if(sum >= y[i])
			{
				sum-= y[i];
				cout << "No problem! :D";
			}
			else				
				cout << "No problem. :(";
			cout << endl;	
		}
		cnt++;
	}
	return 0;
}


Re: 11608 - No Problem

Posted: Sun Oct 04, 2009 4:02 pm
by coze
Hi.

Code: Select all

if (i == 0)
   if(sum >= y[0])
      sum -= (tmp - y[0]);
else
   if(sum >= y[i-1])
      sum-= (p[i-2] - y[i-1]);
The following code is the same as above:

Code: Select all

if (i == 0) {
  if(sum >= y[0]) {
    sum -= (tmp - y[0]);
  }
  else if(sum >= y[i-1]) {
    sum-= (p[i-2] - y[i-1]);
  }
}
Hope it helps.

Re: 11608 - No Problem

Posted: Sat Oct 10, 2009 4:23 pm
by mostafa_angel
No is not work...
I use that IF statement because the index is become -1 and it is out of range...
I change my code but again I got a WA...

Code: Select all

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int n , p[13] , m[13] , sum;
	bool res;
	while(cin >> n  , n)
	{
		sum = n;
		res = false;
		for(int i = 1 ; i <= 12 ; i++)
			cin >> p[i];
		
		for(int i = 1 ; i <= 12 ; i++)
			cin >> m[i];
		
		for(int i = 1 ; i <= 12 ; i++)
		{
			if(sum >= m[i])
			{
				sum-= m[i];
				res = true;
			}
			else
				res = false;
			
			if(res)
				cout << "No problem! :D" << endl;
			else
				cout << "No problem. :(" << endl;
			
			if(i == 2)
			{
				if(m[1] < n)
					sum-= n - m[1];
			}
			if(i > 2)
			{
				if(m[i-1] < p[i-2])
					sum-= p[i-2] - m[i-1];
			}
			sum+=p[i];
		}
	}
	return 0;
}


Re: 11608 - No Problem

Posted: Sat Oct 10, 2009 5:22 pm
by LucasSchm
mostafa_angel wrote:No is not work...
I use that IF statement because the index is become -1 and it is out of range...
I change my code but again I got a WA...

Code: Select all

#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	int n , p[13] , m[13] , sum;
	bool res;
	while(cin >> n  , n)
	{
		sum = n;
		res = false;
		for(int i = 1 ; i <= 12 ; i++)
			cin >> p[i];
		
		for(int i = 1 ; i <= 12 ; i++)
			cin >> m[i];
		
		for(int i = 1 ; i <= 12 ; i++)
		{
			if(sum >= m[i])
			{
				sum-= m[i];
				res = true;
			}
			else
				res = false;
			
			if(res)
				cout << "No problem! :D" << endl;
			else
				cout << "No problem. :(" << endl;
			
			if(i == 2)
			{
				if(m[1] < n)
					sum-= n - m[1];
			}
			if(i > 2)
			{
				if(m[i-1] < p[i-2])
					sum-= p[i-2] - m[i-1];
			}
			sum+=p[i];
		}
	}
	return 0;
}

Your stop condition is wrong. And you are turning this problem harder than it is supposed to be, you dont need that if (i == 2).