416 - LED Test

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

Landertxu
New poster
Posts: 4
Joined: Tue Feb 14, 2006 9:39 pm

Post by Landertxu »

I have tried EVERY tests, having always the true answer, but if I submit it, the UVA-OJ returns me Wrong Answer. This is my code:


Ok, accepted. Thanks a lot.
Last edited by Landertxu on Wed Feb 15, 2006 4:18 pm, edited 1 time in total.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Your code is alright. But your input-taking process is not right. I have changed the following part and got it Accepted.

This is your code...

Code: Select all

         for (i=0;i<c;i++) 
         { 
                scanf("%c",&d);  // I think this line is for initializing a newline
            for (j=0;j<7;j++) 
            {    
                    scanf("%c",&d); 
                    t[n][i][j]=(d=='Y'); 
            } 
         } 
This is the midified one...

Code: Select all

         for (i=0;i<c;i++) 
         { 
              
            for (j=0;j<7;j++) 
            {    
                    scanf(" %c",&d);  // Just a simple space :) 
                    t[n][i][j]=(d=='Y'); 
            } 
         } 
Hope it helps. Dont forget to remove the code after getting Accepted. :D
Ami ekhono shopno dekhi...
HomePage
flavio
New poster
Posts: 11
Joined: Sun Mar 06, 2005 4:07 pm
Location: Porto Alegre - RS (Brazil)
Contact:

Post by flavio »

What's the output for this input:

Code: Select all

2
NNNNNNN
YYYYYYY
???

Thanks in advance!
Barata
Fl
flavio
New poster
Posts: 11
Joined: Sun Mar 06, 2005 4:07 pm
Location: Porto Alegre - RS (Brazil)
Contact:

Post by flavio »

I've got AC!
The correct output is:

Code: Select all

MISMATCH
Thanks!
Fl
ebrahim
New poster
Posts: 6
Joined: Fri Jan 05, 2007 2:08 am
Contact:

Post by ebrahim »

Jan wrote: ...

Input:

Code: Select all

4
YYYYYYN
NYYNNNN
YYNYYNN
YNYYNNN
0
Output:

Code: Select all

MATCH
My AC code gives MISMATCH to this input!
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You are absolutely right. And I m extremely sorry. But still cant remember why I had posted such things. Sorry again. And thank you for showing that error. Perhaps my code produces same output. May be I got it from my WA code. I should be more careful.
Ami ekhono shopno dekhi...
HomePage
hasib_bd
New poster
Posts: 14
Joined: Wed Apr 30, 2008 12:39 pm

416 - LED Test

Post by hasib_bd »

Thanks for the discussion.

My mindset took this problem like a count down timer and i was thinking that it will count from say, 4 3 2 1 0 9 8 7 ... But i got ac now after considering there is not wrapping around. I wasn't careful at the statement "N, with value greater than zero (0) and less than eleven (11)."
shakil
Learning poster
Posts: 74
Joined: Sat Jul 15, 2006 6:28 am
Location: CUET , bangladesh
Contact:

Re: Please Help T.T 416 - LED TEST

Post by shakil »

Why i WA? I test all the inputs in the board. But WA. Please, someone give me some test case that fail my code. Thanks.

Code: Select all

#include<stdio.h>
#include<string.h>

char s[13][13],sam[13][13];
long n,yes,sa[19];

void make(long x,long y,long z)
{
if(x==n)
yes = 1;     
else
{
    long flag,i,j,i1;
    flag=1;
   for(i=0;i<7;i++)
   if(s[y][i]!=sam[x][i]&&sa[i]!=0)
   flag = 0;
   if(flag==1)
   {
     i1 = y+z;
     if(i1<0)
     i1 += 10;
     i1%=10;
     
     for(i=0;i<7;i++)
     {
     sa[i]=0;
     for(j=x+1;j<n;j++)
     if(sam[j][i]=='Y')
     sa[i]=1;                                 
     }
 
     make(x+1,i1,z);
   }     
}     
}


int main()
{
    
long i,j,i1;    
    
strcpy(s[0],"YYYYYYN");
strcpy(s[1],"NYYNNNN");
strcpy(s[2],"YYNYYNY");
strcpy(s[3],"YYYYNNY");
strcpy(s[4],"NYYNNYY");
strcpy(s[5],"YNYYNYY");
strcpy(s[6],"YNYYYYY");
strcpy(s[7],"YYYNNNN");
strcpy(s[8],"YYYYYYY");
strcpy(s[9],"YYYYNYY");


while(1)
{
 scanf("%ld",&n);        
 if(n==0)
 break;
 yes=0;
 
 for(i=0;i<n;i++)
 {
  scanf("%s",sam[i]);
 }      
 
 for(i1=9;i1>=0;i1--)
 {
 /*
 for(i=0;i<7;i++)
 {
 sa[i]=0;
 for(j=0;j<n;j++)
 if(sam[j][i]=='Y')
 sa[i]=1;                                 
 }
 
 make(0,i1,1);
 if(yes==1)
 break;
 */
 for(i=0;i<7;i++)
 {
 sa[i]=0;
 for(j=0;j<n;j++)
 if(sam[j][i]=='Y')
 sa[i]=1;                                 
 }
 
 make(0,i1,-1);
 if(yes==1)
 break;
 }
  
 if(yes==1)
 printf("MATCH\n");
 else
 printf("MISMATCH\n");
        
}
return 0;    
}

SHAKIL
deathstriker
New poster
Posts: 1
Joined: Sat Aug 24, 2013 5:23 am

Re: Please Help T.T 416 - LED TEST

Post by deathstriker »

I tried many test cases and they all seem to work, but when I submit it gets rte .. would someone help please ..

Code: Select all

import java.io.BufferedReader;
import java.io.InputStreamReader;


class UVa_413 {
	static boolean[][] ledtable = new boolean[10][7];
	static boolean[][] seq;
	static int n;
	
	public static void main(String[] args) throws Exception {
		ledtable[0] = new boolean [] {true, true, true, true, true, true, false};
		ledtable[1] = new boolean [] {false, true, true, false, false, false, false};
		ledtable[2] = new boolean [] {true, true, false, true, true, false, true};
		ledtable[3] = new boolean [] {true, true, true, true, false, false, true};
		ledtable[4] = new boolean [] {false, true, true, false, false, true, true};
		ledtable[5] = new boolean [] {true, false, true, true, false, true, true};
		ledtable[6] = new boolean [] {true, false, true, true, true, true, true};
		ledtable[7] = new boolean [] {true, true, true, false, false, false, false};
		ledtable[8] = new boolean [] {true, true, true, true, true, true, true};
		ledtable[9] = new boolean [] {true, true, true, true, false, true, true};
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while ((n = Integer.parseInt(br.readLine())) != 0) {
			seq = new boolean[n][7];
			
			for (int i = 0; i < n; i++) {
				line = br.readLine();
				for (int j = 0; j < 7; j++)
					seq[i][j] = line.charAt(j) == 'Y' ? true : false;
			}
			
			boolean ans = false;
			
			boolean[] failed = checkFailed(0);
			boolean possible;
			for (int i = 9; i >= 0; i--) {
				possible = true;
				for (int j = 0; j < 7; j++) {
					if ((seq[0][j] && !ledtable[i][j]) || (!seq[0][j] && !failed[j] && ledtable[i][j])) {
						possible = false;
						break;
					}
				}
				
				if (possible)
					ans = checkMatched(1, i - 1);
				
				if (ans)
					break;
			}
			
			System.out.println(ans ? "MATCH" : "MISMATCH");
		}
	}
	
	static boolean checkMatched(int p, int cur) {
		if (cur < 0)
			return false;
		
		if (p == n)
			return true;
		
		boolean[] failed = checkFailed(p);
		
		boolean possible = true;
		for (int j = 0; j < 7; j++) {
			if ((seq[p][j] && !ledtable[cur][j]) || (!seq[p][j] && !failed[j] && ledtable[cur][j])) {
				possible = false;
				break;
			}
		}
		
		if (possible)
			return checkMatched(p + 1, cur - 1);
		return false;
	}
	
	static boolean[] checkFailed(int p) {
		boolean found;
		boolean[] failed = new boolean[7];
		
		for (int i = 0; i < 7; i++) {
			found = false;
			if (!seq[p][i]) {
				for (int j = p + 1; j < n; j++) {
					if (seq[j][i]) {
						found = true;
						break;
					}
				}
				if (!found)
					failed[i] = true;
			}
		}
		return failed;
	}
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Please Help T.T 416 - LED TEST

Post by brianfry713 »

Use class Main
Check input and AC output for thousands of problems on uDebug!
Paulino_sanchez
New poster
Posts: 1
Joined: Sat Nov 16, 2013 10:11 pm

Re: Please Help T.T 416 - LED TEST

Post by Paulino_sanchez »

Hi guys,
Could you anyone please send me critical cases for that problem, my code seems to be working well, but I am getting WA.

Code: Select all


#include <cstdlib>
#include <stdio.h>
#include<cstdio> 
#include<cstdlib> 
#include<cctype> 
#include<iostream> 
#include<sstream>
#include<vector>
#include<algorithm>
#include <queue>
#include <map>
#include <string>
#include <math.h>
#include <numeric>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <set>

using namespace std;

typedef long long int64;
typedef vector<int64> VL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<VVB> VVVB;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef vector<VVC> VVVC;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<VPII> VVPII;
typedef pair<double,double> PDD;
typedef vector<PDD> VPDD;

const int INF = 0x3f3f3f3f; 

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i,a,b) for(int i=(b) - 1;i>=(a);--i)
#define RANGE(c) (c),(c) + sizeof((c)) / sizeof((c)[0]) 

int n;
int data[10];
string line;
int led[10];
bool match;

void doit(int index, int burned, int count){
    if(!match){
        if(index==n){
            match = true;
            return;
        }
                        
        if((led[count] & data[index]) == data[index]){
            int auxburned = (led[count] ^ data[index]);
            if((burned & data[index]) == 0) doit(index+1,burned | auxburned, count - 1);
        }
    }
}

void work(){
    match = false;
    FOR(i,n-1,10) doit(0,0,i);    
    if(match) printf("MATCH\n");
    else printf("MISMATCH\n");
}

void preprop(){
    string base[10] = {"YYYYYYN",
                       "NYYNNNN",
                       "YYNYYNY",
                       "YYYYNNY",
                       "NYYNNYY",
                       "YNYYNYY",
                       "YNYYYYY",
                       "YYYNNNN",
                       "YYYYYYY",
                       "YYYYNYY"};
    memset(led,0,sizeof led);
    FOR(i,0,10) FOR(k,0,7) if(base[i][k]=='Y') led[i] |= (1<<k); 
}

int main(int argc, char** argv) {
   //freopen("C:\\data.txt","r",stdin);               
    
    preprop();
    while(true){
        scanf("%d",&n);
        if(n==0) break;
        getchar();
        
        memset(data,0,sizeof data);
        FOR(i,0,n){
            getline(cin, line);
            FOR(k,0,7) if(line[k]=='Y') data[i] |= (1<<k);                    
        }
        
        work();
    }
    return 0;
}
Thanks in advance,
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Please Help T.T 416 - LED TEST

Post by brianfry713 »

Change line 101 from
getchar();
to:
while(getchar() != '\n');
Check input and AC output for thousands of problems on uDebug!
rockson
New poster
Posts: 2
Joined: Sun Aug 17, 2014 10:54 am

Re: 416 - LED Test

Post by rockson »

getting mad!

Code: Select all

#include <cstdio>
#include <iostream>
#include <bitset>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <cstring>
#include <iterator>
#include <sstream>
#include <set>
#define D 10
#define S 7
using namespace std;
int digits[D];
string nums[] =
{
        "YYYYYYN",
        "NYYNNNN",
        "YYNYYNY",
        "YYYYNNY",
        "NYYNNYY",
        "YNYYNYY",
        "YNYYYYY",
        "YYYNNNN",
        "YYYYYYY",
        "YYYYNYY"
};

void preproc()
{
    for(int i = 0; i < D; ++i)
        for(int j = 0; j < nums[i].length(); ++j)
            if(nums[i][j] == 'Y')
                digits[i] |= (1 << j);
}

bool can(int digit, int disp, int burned)
{
    for(int i = 0; i < S; ++i)
    {
        if(!(digits[digit] & (1 << i)) && (disp & (1 << i)))
            return false;
        if((disp & (1 << i)) && (burned & (1 << i)))
            return false;
    }
    return true;
}

bool countdown(int digit, vector<int>& seq, int idx, int burned)
{
    if(idx >= seq.size())
        return true;
    if(can(digit, seq[idx], burned))
    {
        for(int i = 0; i < S; ++i)
        {
            if(digits[digit] & (1 << i))
            {
                if(!seq[idx] & (1 << i))
                    burned |= (1 << i);
            }
        }
        return countdown(digit - 1, seq, idx + 1, burned);
    }
    return false;
}

int main()
{
    preproc();
//    freopen("input.txt", "r", stdin);
//	freopen("out.txt", "w", stdout);
    int n;
    while(scanf("%d", &n), n != 0)
    {
        vector<int> seq(n, 0);
        for(int k = 0; k < n; ++k)
        {
            string s;
            cin >> s;
            for(int i = 0; i < s.length(); ++i)
            {
                if(s[i] == 'Y')
                    seq[k] |= (1 << i);
            }
        }
        bool solved = false;
        for(int i = D - 1; i >= 0 && !solved; --i)
        {
            solved = countdown(i, seq, 0, 0);
        }
        if(solved)
            printf("MATCH\n");
        else printf("MISMATCH\n");

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

Re: 416 - LED Test

Post by brianfry713 »

Code: Select all

2
NYYNNYY
YYYYNYN
0
Output should be MISMATCH
Check input and AC output for thousands of problems on uDebug!
blegat
New poster
Posts: 3
Joined: Fri Apr 04, 2014 12:58 pm

Re: 416 - LED Test

Post by blegat »

I had done an initialization of my variable one scope too early and my code working for 1008 test case of the 1009 official ones :D
The one that failed me was

Code: Select all

6
YYNNNNN
YNNNYYN
YNNNNNN
NNNNNNN
NNNNNNN
NNNNNNN
0
expected output is

Code: Select all

MATCH
You can find the whole data here: http://www.ntnu.edu.tw/acm/ProblemSetAr ... index.html, it's problem E :)
Use Udebug to find the expected output ;)
Post Reply

Return to “Volume 4 (400-499)”