10714 - Ants

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

Moderator: Board moderators

S M Adnan
New poster
Posts: 4
Joined: Wed Aug 10, 2005 10:43 pm
Location: Dhaka, Bangladesh
Contact:

10714 - Ants

Post by S M Adnan »

I solved this (but not got AC) problem like...
minimum time = max(mininum time to get out of the pol)
and
maximum time = max(maximum time to get out of the pol)

So, can anyone tell me what is wrong with me.
Hul Hul
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

Post by Cho »

I've seen someone who got WA because he forgot to initialize the min and max variable for each test case.
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10714 Ants

Post by Martin Macko »

If still getting WAs, try to post your code here...
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

About 10714

Post by Rocky »

It Is A Easy & Sort Problem.But If U Want I Can Sent Some I/O For You
Solmon K.
New poster
Posts: 34
Joined: Sun Jun 04, 2006 4:57 am
Location: Busan, Korea

...

Post by Solmon K. »

I think ur algo is not wrong..
Sorry for my bad English...

OTL
frustrate
marif
New poster
Posts: 11
Joined: Sat Jun 24, 2006 11:42 am
Location: BANGLADESH
Contact:

wa on this problem

Post by marif »

Pls help me. W.A. is boaring. I used simple searching algo...
minimum value
{
i=last item that is found (and matched) before the mid value.
j=first item that is found (and matched) after the mid value.
if(i>(total length-j))minimum=i;
else minimum=total length-j;
}

maximum value
{
i=the smallest item of the array.
j=the largest item of the array.
if((total length -i)>j)
maximum=total length-i;
else maximum=j;
}
what is the wrong with it. I have used few inputs on this board and it was ok. Pls help.
:cry:
rahurprem
New poster
Posts: 10
Joined: Mon Mar 28, 2005 5:59 pm
Location: Dhaka, Bangladesh
Contact:

714: Ants --- Some critical I/O please

Post by rahurprem »

I'm getting WA in this problem. I'm sending my findMin() & findMax() code blocks. I hope until now that those two blocks are producing correct results. So help me in this matter.

Code: Select all

int findMin()
{
	int i;
	int min = L;
	int mid = L/2;   /*This is the mid of pole*/

	/**mid theke shobcheye kaser ant khojo**/		
        /**Let's find which ant is closest to the mid position****/

	/*STEP 1: Search Left side upto mid**/
	for(i=0; a[i]<mid; i++)	
	{		
		if(min> abs(a[i]-mid))
			min = abs(a[i]-mid);
	}	
	/*STEP 2: Search from Right side upto mid**/
	for(i=N-1; a[i]>=mid; i--)
	{		
		if(min>abs(a[i]-mid))
			min = abs(a[i]-mid);
	}				
	return mid-min;	/*This is the minimum distance, isn't it?*/
}

Code: Select all

int findMax()
{
	int i,j;
	int max=-1;	
	
	/***
	i=the smallest item of the array. 
 	j=the largest item of the array. 
 	if((total length -i)>j) 
 	maximum=total length-i; 
	***/	
	i = a[0];
	j = a[N-1];
	if((L-i)>j)
		max= L-i;
	else
		max= j;

	return max;
}
It'll be a great help if you provide me some i/o to prove this algo wrong.
Wishes,
R.P.
Programmer? No, no, i am a speedy typist.
unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

10714 - Ants W.A

Post by unaben »

I got W.A on this problem. :( Could someone plz give me the I/O.
Here is my code:

REMOVED AFTER AC!
Last edited by unaben on Tue Jul 25, 2006 11:29 pm, edited 1 time in total.
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10714 - Ants W.A

Post by Martin Macko »

unaben wrote:I got W.A on this problem. :( Could someone plz give me the I/O.
What if hold==distance?
your code wrote:.......if(hold<distance and hold>min)
.......{
...........min = hold;
.......}....
.......else if(hold>distance and distance>min)
.......{
...........min = distance;
.......}...
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 714: Ants --- Some critical I/O please

Post by Martin Macko »

rahurprem wrote:I'm getting WA in this problem. I'm sending my findMin() & findMax() code blocks. I hope until now that those two blocks are producing correct results. So help me in this matter.
I think your findMin() doesn't work for odd Ls. Think about something like that:

Code: Select all

1
3 1
3
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Re: 10714 - Ants W.A

Post by Martin Macko »

and btw, if there is a thread on a particular problem, please, use that thread and do not create a new one.
unaben
New poster
Posts: 12
Joined: Mon Jul 10, 2006 10:47 pm

Post by unaben »

Thanx Macko :wink: What a stupid mistake. I got AC now :P
Martin Macko
A great helper
Posts: 481
Joined: Sun Jun 19, 2005 1:18 am
Location: European Union (Slovak Republic)

Post by Martin Macko »

unaben wrote:Thanx Macko :wink: What a stupid mistake. I got AC now :P
After you got AC, please, remove the code from your first post, so there won't be too many spoilers here :wink:
ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

Why WA??

Post by ranban282 »

I have absolutely no idea why I'm getting WA.
Here's the code:

Code: Select all

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<cctype>
#include<stack>
#include<map>
#include<set>
using namespace std;

int main()
{
        int cases;
        cin>>cases;
        while(cases--)
        {
                int l,n;
                scanf(" %d %d",&l,&n);
                vector<int> v(n);
                for(int i=0;i<n;i++)
                {
                        scanf(" %d",&v[i]);
                }
                sort(v.begin(),v.end());
                int ma=max(l-v[0],v.back());
                int mi=ma;
                for(int i=0;i<n-1;i++)
                {
                        mi=min(mi,max(v[i],l-v[i+1]));
                }
                if(n==1)
                        mi=min(v[0],l-v[0]);
                printf("%d %d\n",mi,ma);
                }
        return 0;
}
Could anyone provide me with I/0?
Grazyna
New poster
Posts: 16
Joined: Wed Apr 20, 2005 2:44 pm
Location: Thessaloniki,Greece

Post by Grazyna »

Can someone explain why the output for

Code: Select all

1
10 3
3 7 9
is

Code: Select all

3 9
and not

Code: Select all

3 8

Thanks in advance for any reply.
Post Reply

Return to “Volume 107 (10700-10799)”