11608 - No Problem

All about problems in Volume 116. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

kcode
New poster
Posts: 8
Joined: Sun Mar 22, 2009 6:24 am
Location: Aryadesa

11608 - No Problem

Post 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;
    }
}
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: 11608 - No Problem

Post 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
kcode
New poster
Posts: 8
Joined: Sun Mar 22, 2009 6:24 am
Location: Aryadesa

Re: 11608 - No Problem

Post by kcode »

Got it, thanks.
bm_anas
New poster
Posts: 10
Joined: Fri May 15, 2009 9:13 pm

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

Post 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;
}
MRH
Learning poster
Posts: 51
Joined: Mon Aug 11, 2008 9:09 pm

Re: 11608 - No Problem

Post 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
bm_anas
New poster
Posts: 10
Joined: Fri May 15, 2009 9:13 pm

Re: 11608 - No Problem

Post by bm_anas »

hi MRH thanks for ur help. :D
lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 11608 - No Problem

Post by lnr »

Accepted.
Last edited by lnr on Fri Jul 17, 2009 2:54 am, edited 2 times in total.
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

Re: 11608 - No Problem

Post 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
New_AshkankhaN
New poster
Posts: 1
Joined: Fri Jul 17, 2009 10:44 pm

Re: 11608 - No Problem

Post 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;
}


helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 11608 - No Problem

Post by helloneo »

See Observer's post..
LucasSchm
New poster
Posts: 17
Joined: Mon May 18, 2009 10:00 pm

Re: 11608 - No Problem

Post 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...
mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

Re: 11608 - No Problem

Post 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;
}

coze
New poster
Posts: 26
Joined: Tue Nov 27, 2007 7:56 am
Location: Japan

Re: 11608 - No Problem

Post 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.
mostafa_angel
New poster
Posts: 23
Joined: Sun Oct 04, 2009 12:03 pm

Re: 11608 - No Problem

Post 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;
}

LucasSchm
New poster
Posts: 17
Joined: Mon May 18, 2009 10:00 pm

Re: 11608 - No Problem

Post 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).
Post Reply

Return to “Volume 116 (11600-11699)”