10963 - The Swallowing Ground

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

Moderator: Board moderators

salous
New poster
Posts: 1
Joined: Tue Dec 11, 2007 6:40 am

I have problems with this one too

Post by salous » Tue Dec 11, 2007 6:46 am

Can someone please help me with this problem? This should be a very easy one but I just don't understand why can't I get it right, I have read all the threads about this problem and tried lots of attempts but still no luck. Can you please help me point out what's wrong with my code? Thanks a lot!

Code: Select all


#include <stdio.h>
#include <stdlib.h>

int main(void) {
	int dataNum = 0;
	scanf("%d", &dataNum);
	int i = 0;
	for(i = 0; i < dataNum; ++i) {
		int columnNum = 0;
		scanf("%d", &columnNum);
		int ableToFix = 1;
		if(columnNum < 0)
			ableToFix = -1;
		int diff = -1;
		int j = 0;
		for(j = 0; j < columnNum; ++j) {
			int y1, y2;
			y1 = y2 = 0;
			scanf("%d%d", &y1, &y2);
			if(ableToFix == 1) {
				int diffTemp = abs(y1 - y2);
				if(diff == -1)
					diff = diffTemp;
				else if(diff != diffTemp)
					ableToFix = -1;
			}
		}
		if(ableToFix == 1)
			printf("yes\n\n");
		else
			printf("no\n\n");
	}
}


jurajz
Learning poster
Posts: 69
Joined: Sat Sep 02, 2006 7:30 pm
Location: Slovakia

Post by jurajz » Thu Dec 20, 2007 11:57 pm

Hi salous!

I solved this problem in the same way, as you, and I have AC. I think, that I found your little mistake. In new system, if you print extra blank line, the judge will give probably WA instead PE. I wrote about this in this thread:

http://online-judge.uva.es/board/viewtopic.php?t=22134

For this problem, the problem description says:
The outputs of two consecutive cases will be separated by a blank line.
And there is probably a mistake in your code, consecutive means, that blank line is "After each test case except last" or "Before each test case except first". And you write a blank line after each test case, including the last. Make something with this and I hope, that you will get AC ;)

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10963 - The Swallowing Ground

Post by DD » Tue Mar 15, 2011 10:07 pm

In this problem, you can assume that the row of the northern block is bigger than the row of the southern block. Of course you also need to take care about the multi-case input.
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 10963 - The Swallowing Ground

Post by f.maru » Tue Sep 10, 2013 12:09 pm

can sb help me i get Wa

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=2;j<=tes;j++)
    {
    cout<<endl;
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=abs(y1-y2);
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10963 - The Swallowing Ground

Post by brianfry713 » Wed Sep 11, 2013 12:17 am

Try running your code on the sample input.
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 10963 - The Swallowing Ground

Post by f.maru » Wed Sep 11, 2013 3:18 pm

i tried sample and i got correct answer
this is my new code i still don't know what to do if someone can help me

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=1;j<=tes;j++)
    {
    cout<<endl;
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=y1-y2;
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(j>1)
    cout<<endl;
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10963 - The Swallowing Ground

Post by brianfry713 » Wed Sep 11, 2013 10:08 pm

Don't print a blank line at the start of the output.
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 10963 - The Swallowing Ground

Post by f.maru » Wed Sep 11, 2013 11:52 pm

You ean don't use cout<<endl before cin>>n in the for?
I tried this but I got WA.
And I think I have to seperate output with bank line except first output like leap year...

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10963 - The Swallowing Ground

Post by brianfry713 » Thu Sep 12, 2013 10:43 pm

The outputs of two consecutive cases will be separated by a blank line.
Input:

Code: Select all

2

5
2 1
0 -1
1 0
1 0
2 1

5
2 1
0 -1
1 0
1 0
2 1
Correct output:

Code: Select all

yes

yes
Check input and AC output for thousands of problems on uDebug!

f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

Re: 10963 - The Swallowing Ground

Post by f.maru » Thu Sep 12, 2013 11:09 pm

Sry but I had submitted my code without printing blank line befor reading n but I got WA and it the output is same as what wrote

Code: Select all

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n,y1,y2,q,tes;
    bool flag=false;
    cin>>tes;
    int ms;
    for(int j=1;j<=tes;j++)
    {
    cin>>n;
    for(int t=1;t<=n;t++)
    {
     
            cin>>y1>>y2;
            q=y1-y2;
            if (t==1)
            ms=q;
            if (q!=ms)flag=true;
    }
    if(j>1)
    cout<<endl;
    if(flag==true)cout<<"no"<<endl;
    else
    cout<<"yes"<<endl;
}
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10963 - The Swallowing Ground

Post by brianfry713 » Fri Sep 13, 2013 10:16 pm

You need to reset flag to false at the start of each test case.
Check input and AC output for thousands of problems on uDebug!

Samleo
New poster
Posts: 11
Joined: Mon Dec 03, 2012 2:39 pm

Re: 10963 - The Swallowing Ground

Post by Samleo » Tue Oct 22, 2013 12:56 pm

Why is my code getting WA? I am printing the lines properly, have passed all test inputs on the forum.. But still WA :(

Code: Select all

CODE REMOVED AFTER AC
Would appreciate some help and test inputs :)
Thanks,
Sam
Last edited by Samleo on Sun Nov 03, 2013 4:39 pm, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10963 - The Swallowing Ground

Post by brianfry713 » Tue Oct 22, 2013 10:35 pm

Either don't use abs or make your abs function return something.
Check input and AC output for thousands of problems on uDebug!

Samleo
New poster
Posts: 11
Joined: Mon Dec 03, 2012 2:39 pm

Re: 10963 - The Swallowing Ground

Post by Samleo » Sun Nov 03, 2013 4:39 pm

brianfry713 wrote:Either don't use abs or make your abs function return something.
Thanks :) Solved with that tip :D Stupid mistake

NickStern
New poster
Posts: 3
Joined: Wed Nov 20, 2013 1:29 am

Re: 10963 - The Swallowing Ground

Post by NickStern » Wed Nov 20, 2013 1:47 am

I keep getting WA for this problem but it responds fine to all the test cases I have given it. Could someone tell me the issue with my code? Unlike most of the other posts it is in java.

Code: Select all

Issue resolved
Last edited by NickStern on Thu Nov 21, 2013 6:39 am, edited 1 time in total.

Post Reply

Return to “Volume 109 (10900-10999)”