11063 - B2-Sequence

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

Moderator: Board moderators

asif_iut
New poster
Posts: 16
Joined: Mon Nov 01, 2010 8:08 am

Re: 11063 - B2-Sequence

Post by asif_iut » Wed Dec 22, 2010 9:22 am

I found a couple of mistakes...

First, the sequence must start with the number greater than 0.

Second,
if(i>=2)if(Arr==(Arr[i-1]+Arr[i-2]))flg=1;

this line is wrong.
Consider the test case:

3
1 3 4

The sequence is a B2 sequence but your output shows it is not a B2 sequence.

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 11063 - B2-Sequence

Post by plamplam » Mon Jun 27, 2011 4:35 pm

After taking all the numbers as input, store them in an array. Now if ar[0] < 1 it is not obviously a B2 Sequence(see the description again). Also ar[k] must be less than ar[k + 1] for it to be a B2 sequence. Also note that i <= j. So for the first sample input:
4
1 2 4 8
The sums should be calculated as: 1 + 1, 1 + 2, 1 + 4, 1 + 8, 2 + 2, 2 + 4.........8 + 8
Brute force is enough to solve this problem, so you don't need any optimization(unless you want a higher rank), there is a blank line after every test case(including the last one), and make sure to print a . at the end of each output. There ya go, you should get AC now :) :lol:
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

BUET
New poster
Posts: 22
Joined: Sun Jun 13, 2010 8:38 am

11063 - B2-Sequence

Post by BUET » Sat Jun 02, 2012 6:24 pm

for each (i,j) with i<=j ,I have saved value+value[j] in a set, not multiset. In multiset,same data can be presented more than one.

If there is no duplicate of value+value[j] for different pairs(i,j) with (i<=j).

then no. of elements in the set would be (n*(n-1))/2 + n = (n*n-n)/2

Otherwise it is not B2 sequence.

Although we have to check some other conditions such as value[0] >= 1 && value[j] > value ( for j > i)

Md. Shadekur Rahman
BUET
07 Batch

shondhi
New poster
Posts: 25
Joined: Tue Oct 02, 2012 5:24 pm
Location: Chittagong
Contact:

Why WA in UVa: 11063 - B2-Sequence?

Post by shondhi » Thu Feb 14, 2013 9:22 am

I can't understand what's wrong in my code. Can anyone help me to fix my code? My Code is:

Code: Select all

#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int cases, i, number[102], caseno = 0;
	while(scanf("%d", &cases) == 1)
	{
	    int count = 0;
		for(i = 1; i <= cases; i++)
		{
			scanf("%d", &number[i]);
		}
		for(i = 1; i <= cases; i++)
		{
			if(number[i+1] - number[i] == number[i])
			{
				count = 1;
			}
		}
		if(count == 1)
		{
			printf("Case #%d: It is a B2-Sequence.\n", ++caseno);
		}
		else
		{
			printf("Case #%d: It is not a B2-Sequence.\n", ++caseno);
		}
		if(caseno > 0)
		{
			printf("\n");
		}
	}
	return 0;
}

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

Re: Why WA in UVa: 11063 - B2-Sequence?

Post by brianfry713 » Thu Feb 14, 2013 9:18 pm

Input:

Code: Select all

4
1 2 3 3
4
15 16 17 18
4
-5 0 5 9
6
1 9 19 0 45 70
6
1 9 19 45 70 150
5
15 16 -1 17 18
4
2 2 2 3
4
2 2 2 2
4
1 9 18 36
5
1 9 10 18 36
Correct output:

Code: Select all

Case #1: It is not a B2-Sequence.

Case #2: It is not a B2-Sequence.

Case #3: It is not a B2-Sequence.

Case #4: It is not a B2-Sequence.

Case #5: It is a B2-Sequence.

Case #6: It is not a B2-Sequence.

Case #7: It is not a B2-Sequence.

Case #8: It is not a B2-Sequence.

Case #9: It is a B2-Sequence.

Case #10: It is not a B2-Sequence.

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

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

Re: Why WA in UVa: 11063 - B2-Sequence?

Post by omarking06 » Mon Mar 18, 2013 6:54 pm

WHY WA !!?

Code: Select all

#include <iostream>
using namespace std;

int main ()
{
	int t=1,num[99],sum[10000],s,c;
	bool res;
	while (cin>>s)
	{
		res=true;
		for (int j=0;j<s;j++)
			cin>>num[j];

		for (int k=0;k<s-1;k++)
			if (num[k]<1 || num[k]>=num[k+1] ) 
			{
					res=false;
					break;
			}
		
		c=0;

		for (int i=0;i<s;i++)
			for (int l=i;l<s;l++)
			{
				sum[c]= num[i]+num[l];
				c++;
			}

		for (int x=0;x<s;x++)
			for (int y=0;y<s;y++)
				if (sum[x]==sum[y] && y!=x) res=false;
				else continue;

		if (res==true)
			cout<<"Case #"<<t<<": It is a B2-Sequence."<<endl;
		else if (res==false)
			cout<<"Case #"<<t<<": It is not a B2-Sequence."<<endl;
		cout<<endl;
		t++;
		
	}
	return 0;
}

omarking06
New poster
Posts: 6
Joined: Fri Mar 15, 2013 1:07 am

Re: 11063 - B2-Sequence

Post by omarking06 » Mon Mar 18, 2013 6:55 pm

WHY WA !!?

Code: Select all

#include <iostream>
using namespace std;

int main ()
{
	int t=1,num[99],sum[10000],s,c;
	bool res;
	while (cin>>s)
	{
		res=true;
		for (int j=0;j<s;j++)
			cin>>num[j];

		for (int k=0;k<s-1;k++)
			if (num[k]<1 || num[k]>=num[k+1] ) 
			{
					res=false;
					break;
			}
		
		c=0;

		for (int i=0;i<s;i++)
			for (int l=i;l<s;l++)
			{
				sum[c]= num[i]+num[l];
				c++;
			}

		for (int x=0;x<s;x++)
			for (int y=0;y<s;y++)
				if (sum[x]==sum[y] && y!=x) res=false;
				else continue;

		if (res==true)
			cout<<"Case #"<<t<<": It is a B2-Sequence."<<endl;
		else if (res==false)
			cout<<"Case #"<<t<<": It is not a B2-Sequence."<<endl;
		cout<<endl;
		t++;
		
	}
	return 0;
}

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

Re: 11063 - B2-Sequence

Post by brianfry713 » Mon Mar 18, 2013 10:22 pm

Don't double post.
Check input and AC output for thousands of problems on uDebug!

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

Re: Why WA in UVa: 11063 - B2-Sequence?

Post by brianfry713 » Tue Mar 19, 2013 8:31 pm

Doesn't match the sample I/O.
Check input and AC output for thousands of problems on uDebug!

Examiner
New poster
Posts: 27
Joined: Thu Feb 19, 2004 1:19 pm

Re: 11063 - B2-Sequence

Post by Examiner » Wed Apr 24, 2013 1:29 pm

Try this:

Code: Select all

3
1 3 5

terry646623
New poster
Posts: 8
Joined: Fri Jan 17, 2014 3:35 pm

Re: 11063 - B2-Sequence

Post by terry646623 » Tue Mar 25, 2014 3:43 pm

why do I get wrong answer :(

Code: Select all

Yeah...This is a AC code. I just don't know why the system told that this is wrong answer before...
Last edited by terry646623 on Sat Mar 29, 2014 6:12 pm, edited 1 time in total.

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

Re: 11063 - B2-Sequence

Post by brianfry713 » Wed Mar 26, 2014 12:51 am

That is AC code
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 11063 - B2-Sequence

Post by uDebug » Fri May 30, 2014 2:05 pm

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

SR7
New poster
Posts: 4
Joined: Fri Aug 14, 2015 6:36 pm

Re: WA!!!

Post by SR7 » Sun Aug 16, 2015 10:27 am

plz help...

I've tried with a lot of i/o....but couldn't fix what's wrong with this==>

Code: Select all


#include<stdio.h>
int main()
{
    int i,j,k,x,y,z,n,tc=0,ara[101],f;
    long sum[100000];
    while(scanf("%d",&n)==1){
        tc++;
        for(i=0; i<n; i++){
            scanf("%d", &ara[i]);
        }
        f=0;
        for(i=1; i<n; i++){
            if(ara[i]<=ara[i-1] || ara[i-1]<1){
                f=1;
                break;
            }
        }
        if(f==1){
            printf("Case #%d: It is not a B2-Sequence.\n",tc);
            continue;
        }
        k=0;
        for(i=0; i<n; i++){
            for(j=n-1;j>=i;j--){
              sum[k] = ara[i]+ara[j];
              k++;
            }
        }
        z=0;
        for(x=0; x<k; x++){
            for(y=k-1; y>x; y--){
                if(sum[x]==sum[y]){
                    z=1;
                    break;
                }
            }
            if(z==1) break;
        }
        if(z==0) printf("Case #%d: It is a B2-Sequence.\n",tc);
        else printf("Case #%d: It is not a B2-Sequence.\n",tc);
        printf("\n");
    }
    return 0;
}
Last edited by brianfry713 on Wed Aug 19, 2015 8:52 pm, edited 1 time in total.
Reason: Added code block

Post Reply

Return to “Volume 110 (11000-11099)”