441 - Lotto

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

Moderator: Board moderators

Post Reply
stcheung
Experienced poster
Posts: 114
Joined: Mon Nov 18, 2002 6:48 am
Contact:

441 - Lotto

Post by stcheung » Wed Feb 21, 2007 8:48 am

Any trick in getting AC instead of PE on this problem 441 (Lotto)? I tried couple newline variations but still no luck.

User avatar
linux
Learning poster
Posts: 56
Joined: Sat Jul 01, 2006 12:21 pm
Location: CA-95054
Contact:

441

Post by linux » Mon Jul 16, 2007 12:44 pm

Between every output set you should put a new line.
Remember
The test cases have to be separated from each other by exactly one blank line. Do not put a blank line after the last test case.
Also exactly one space between integers sholud be followed.

See the sample ouput for input

Code: Select all

7 1 2 3 4 5 6 7
7 1 2 3 4 5 6 7
0
Output

Code: Select all

1 2 3 4 5 6\n
1 2 3 4 5 7\n
1 2 3 4 6 7\n
1 2 3 5 6 7\n
1 2 4 5 6 7\n
1 3 4 5 6 7\n
2 3 4 5 6 7\n\n
1 2 3 4 5 6\n
1 2 3 4 5 7\n
1 2 3 4 6 7\n
1 2 3 5 6 7\n
1 2 4 5 6 7\n
1 3 4 5 6 7\n
2 3 4 5 6 7\n
If same you owe an AC. :D
Solving for fun..

User avatar
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton » Sun Mar 16, 2008 9:53 pm

Thanks a lot Mr Linux

this is really a fishi problem.
keep postin.

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 441 - Lotto PE

Post by Obaida » Tue Jul 29, 2008 9:32 am

I got WA again and again. :( Some one please help me.

Code: Select all

Yes!!!
I got Accepted i was taking the input in wrong way
Again thank you very much linux
:) :) :)
try_try_try_try_&&&_try@try.com
This may be the address of success.

aaa111
New poster
Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

Re: 441 - Lotto PE

Post by aaa111 » Fri Aug 27, 2010 8:19 pm

Hi,
Sorry for reviving an old thread,but I am not sure why am i getting WA:

Code: Select all

#include<stdio.h>

int main()
{
int i,j,size,a[49],b[6],l,k,m,n;


while(1)
    {
    scanf("%d",&size);
    if(size==0)
        break;
    for(i=0;i<size;i++)
     {
	 scanf("%d",&a[i]);
	 if(i<6)
	   b[i]=a[i];
	 }
    
    j=4;
    l=5;
    n=l+1;
    m=size;
    
    for(i=0;i<6;i++)
       printf("%d ",b[i]);
   
    while(j>=(-1))
	{
    if(l>j)
	{
	if(n<m)
	   {
	   b[l]=a[n];
       printf("\n");
       for(i=0;i<6;i++)
	      printf("%d ",b[i]);
       n++;
	   }
       else
	    {
        n=l+1;
	    l--;
	    m--;
    	}
	}
    else
	      {
	      k=0;
          for(i=0;i<7;i++)
		     {
		     if(i==j)
			   continue;
		     b[k]=a[i];
		     k++;
		    }
		  n=i;
	      if(j>=0)
          {
          printf("\n");
		  for(i=0;i<6;i++)
		      printf("%d ",b[i]);
	      }
          j--;
	      m=size;
	      l=5;
	   }
      }
printf("\n");
}
return 0;
}
THX.

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 441 - Lotto PE

Post by sazzadcsedu » Sat Aug 28, 2010 1:28 pm

Two things i can say:

1.you code does not follow this-
The test cases have to be separated from each other by exactly one blank line. Do not put a blank line after the last test case.
2. This print a space after the last number,which should no be.

Code: Select all

  printf("%d ",b[i]);
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

aaa111
New poster
Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

Re: 441 - Lotto PE

Post by aaa111 » Sat Aug 28, 2010 4:05 pm

I have modified the code as what u have said,still no luck:

Code: Select all

#include<stdio.h>

int main()
{
int i,j,size,a[49],b[6],l,k,m,n,c=0;

while(1)
    {
    if(c==1)
     printf("\n");
    scanf("%d",&size);
    if(size==0)
	break;
    for(i=0;i<size;i++)
	 {
	 scanf("%d",&a[i]);
	 if(i<6)
	   b[i]=a[i];
     }
    c=1;
    j=4;
    l=5;
    n=l+1;
    m=size;

    for(i=0;i<6;i++)
       {
       printf("%d",b[i]);
       if(i<5)
           printf(" ");          
       else 
           printf("\n");   
       }
    
    while(j>=(-1))
	{
	if(l>j)
	  {
	  if(n<m)
	    {
	    b[l]=a[n];
	    
	    for(i=0;i<6;i++)
	      {
          printf("%d",b[i]);
          if(i<5)
           printf(" ");          
          else
          printf("\n");  
          }

	    n++;
	    }
	  else
	    {
	    n=l+1;
	    l--;
	    m--;
	    }
	   }
       else
	   {
	   k=0;
	   for(i=0;i<7;i++)
		{
		if(i==j)
		   continue;
		b[k]=a[i];
		k++;
		}
		n=i;
		if(j>=0)
		   {
		   for(i=0;i<6;i++)
		      {
              printf("%d",b[i]);
              if(i<5)
                 printf(" ");          
              else
                 printf("\n");
              }
        }
		j--;
		m=size;
		l=5;
	    }
	 }
     
   }
return 0;
}

mintae71
New poster
Posts: 18
Joined: Tue Jan 19, 2010 10:50 am

Re: 441 - Plz help me.....

Post by mintae71 » Wed Sep 08, 2010 12:53 pm

I tried 10 more test data and it was all right. But Bad OJ(Sorry :roll: :roll: :roll: :roll: :roll: :roll: :roll: ) says it's WA
I don't no why it is :cry: :cry: :cry: :cry: :cry: :cry: :cry: :cry:
Please help me.....
Please give some critical inputs......
Or hint from code.

Sorry, But I'm using C++.

Code: Select all

#include <iostream>
using namespace std;
int s[13];
int Base2[13];
int main()
{
	int	k;
	int i, j;
	int ktimes2;
	int cnt = 0;
	int imsi;
	int cntzero = 0;
	int first = false;
	while (cin >> k){
		if (k == 0) break;
		if (first) cout << endl;
		first = true;
		for (i = 0; i < k; i++){
			cin >> s[i];
		}
		
		ktimes2 = 1;
		for (i = 0; i < k; i++){
			ktimes2 *= 2;
		}
		for (i = 0; i < ktimes2; i++){
			imsi = i;
			for (j = 0; j < 13; j++){
				Base2[j] = 0;
			}
			cnt = 0;
			while (imsi > 0){
				Base2[cnt++] = imsi%2;
				imsi /= 2;
			}
			cntzero = 0;
			for (j = 0; j < k; j++){
				if (Base2[j] == 1) cntzero++;
			}
			if (cntzero == 6){
				for (j = 0; j < k; j++){
					if (Base2[j] == 1){
						if (j != k-1){
							cout << s[j] << " ";
						}
						else cout << s[j];
					}
				}
				cout << endl;
			}
		}
	}
	return 0;
}

mostafiz93
New poster
Posts: 31
Joined: Thu Nov 24, 2011 12:08 am

Re: 441 - Lotto PE

Post by mostafiz93 » Thu Apr 19, 2012 2:30 pm

it's a very easy problem if your approach is iterative backtracking.
since you need to take a fixed(6) numbers at a time, you can iterate 6 loops. and the limit of k is 6<k<13, so no possibility of getting tle!!

sdipu
New poster
Posts: 23
Joined: Sun May 19, 2013 1:50 am

Re: 441 - Lotto PE

Post by sdipu » Fri Aug 02, 2013 2:54 pm

I have tried this problem more times than I can count. But every time I get the damn "Submission Error". :evil: :evil: :evil: :x
I don't know why OJ showing this. Has anyone got any idea?

I am using C++ stl funtion "next_permutation" and a vector to store data.
Check out UVA Arena - a software build for UVA solvers @ http://dipu-bd.github.io/UVA-Arena/

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

Re: 441 - Lotto PE

Post by brianfry713 » Fri Aug 02, 2013 11:27 pm

See "Information on Submission Errors" at http://uva.onlinejudge.org/
Check input and AC output for thousands of problems on uDebug!

Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

Re: 441 - Lotto

Post by Zyaad Jaunnoo » Thu Sep 11, 2014 4:51 pm

Instead of using recursion, you can solve this problem using 6 nested loops :)

For me, it ran in 0.015 seconds.

warwcat
New poster
Posts: 1
Joined: Fri Aug 07, 2015 2:37 pm

441 - Lotto

Post by warwcat » Fri Aug 07, 2015 2:54 pm

Hello , I'm relatively new in that and i tried solve this problem i used linux diff comand to compare my output with required output and is the same but when I submitted was WA someone can look to my code please.

Code: Select all



#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<string,string> ss;
typedef vector<ss> vss;


#define all(a)                      a.begin(), a.end()
#define in(a,b)                     ( (b).find(a) != (b).end())
#define pb                          push_back

int main(int argc, char const *argv[]) {
  int n;
  vi v;

  cin>>n;
  while(n!=0){
    while(cin.peek()!='\n'){
      v.pb(n);

      cin>>n;
    }
    v.pb(n);
    sort(all(v));
    auto it = unique(all(v));
    v.resize(distance(v.begin(),it));


    for (int i = 0; i < v.size(); i++) {
      for (int j = i+1; j < v.size() && v[i]!=v[j]; j++) {
        for (int k = j+1; k < v.size() && v[j]!=v[k]; k++) {
          for (int l = k+1; l < v.size() && v[k]!=v[l]; l++) {
            for (int z = l+1;z < v.size() && v[l]!=v[z];z++) {
              for (int x = z+1; x < v.size() && v[z]!=v[x]; x++) {
                cout<<v[i]<<" "<<v[j]<<" "<<v[k]<<" "<<v[l]<<" "<<v[z]<<" "<<v[x]<<endl;
              }
            }
          }
        }
      }
    }






    cin>>n;
    if(n!=0)
    cout<<endl;
    v.clear();
  }

  return 0;
}

Zyaad Jaunnoo
Experienced poster
Posts: 122
Joined: Tue Apr 16, 2002 10:07 am

Re: 441 - Lotto

Post by Zyaad Jaunnoo » Mon Aug 31, 2015 1:48 pm

Try taking the input in a simpler way as below..

Code: Select all

while (cin >> n) {
   if (n == 0) break;
   
   v.clear();
   
   // Read set
   // No need to sort as the input is already sorted.
   // We also assume that there is no duplicate in the set
   
   if (testcase > 1)
      printf("\n");
      
   //  Process and output here..
}

Post Reply

Return to “Volume 4 (400-499)”