10415 - Eb Alto Saxophone Player

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

Moderator: Board moderators

karl
New poster
Posts: 11
Joined: Tue Jul 16, 2002 1:03 pm

10415 - Eb Alto Saxophone Player

Post by karl » Tue Dec 03, 2002 7:46 pm

Hi folks! :wink:

"10415 looks very simple", I had thought until I sent my prog...

Now, I don't know, what can be checked after trying and trying.
I mentioned:
- song may be empty -> printing only '0' 10 times
- at most 200 notes in a song -> inputstring of size 300!
- first note -> all fingers required
- further notes -> only pressed, if not used in note before
- numbers seperated by single space...

I'm asking for some test cases because I have no idea what I could try now...

Best wishes

Karl

Spike
New poster
Posts: 29
Joined: Mon Mar 18, 2002 2:00 am
Location: Washington State
Contact:

Post by Spike » Fri Dec 06, 2002 10:55 pm

Remember to check for blank lines.
Last edited by Spike on Sat Dec 14, 2002 11:05 am, edited 1 time in total.

Moinul(AUST)
New poster
Posts: 11
Joined: Tue Dec 10, 2002 11:40 am
Location: Dhaka, Bangaldesh
Contact:

Sample Inputs

Post by Moinul(AUST) » Fri Dec 13, 2002 9:42 pm

This is an easy problem...
Well, Try with these inputs
------------------------------------------------------------
12

cdefgab

BAGFEDC
CbCaDCbCbCCbCbabCCbCbabae

BAAGFFEDCbabbabbbabbbabab
ccccCCdccaccacccccaaacccc
cacacaaBBBBcCbbbbBAAGGGGG
GFGFGGaaaaFFgGgGbcdefgabbbbbbbbbbbbb
bbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccbbbbbbbbbaaaaaaaaaaa
--------------------------------------------------------------

My accepted solution returns

0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 1 1 1 1
0 0 0 0 0 0 0 0 0 0
1 1 1 1 0 0 1 1 1 0
1 8 10 2 0 0 2 2 1 0
0 0 0 0 0 0 0 0 0 0
1 2 6 1 0 0 1 1 1 0
0 2 1 5 0 0 5 5 5 5
2 2 3 5 0 0 4 4 4 4
4 1 2 3 0 0 4 1 1 1
0 1 0 0 0 0 0 0 0 0
0 1 2 1 0 0 1 1 1 1

Hope, this Helps :P

-Moinul (AUST)

User avatar
yahoo
Learning poster
Posts: 93
Joined: Tue Apr 23, 2002 9:55 am

10415

Post by yahoo » Sat Jan 11, 2003 10:46 pm

I have tried to solve this problem several times with various algorithm but all of them give me wrong answer. Can anybody explain me the tips to solve this problem. Thanks in advance. :(

galois_godel
New poster
Posts: 17
Joined: Wed Jul 17, 2002 5:00 pm

I have pass the all test data above .but still wrong answer?

Post by galois_godel » Sun Jan 12, 2003 4:21 pm

I have pass the all test data above .but still wrong answer?
#include<iostream>
#include<cstring>
using namespace std;
const int a[14][10]={
{0,1,1,1,0,0,1,1,1,1},
{0,1,1,1,0,0,1,1,1,0},
{0,1,1,1,0,0,1,1,0,0},
{0,1,1,1,0,0,1,0,0,0},
{0,1,1,1,0,0,0,0,0,0},
{0,1,1,0,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0},
{1,1,1,1,0,0,1,1,1,0},
{1,1,1,1,0,0,1,1,0,0},
{1,1,1,1,0,0,1,0,0,0},
{1,1,1,1,0,0,0,0,0,0},
{1,1,1,0,0,0,0,0,0,0},
{1,1,0,0,0,0,0,0,0,0}};
int getindex(char c)
{
if(c>='A' && c<='G')
return (c-'C'+7)%7+7;
else
return (c-'c'+7)%7;
}
void work()
{
char note[200];
int notenum;
int i,j;
int ans[10],press[10];
cin.getline(note,200);
notenum=strlen(note);
int n;
for(i=0;i<10;i++)
{
ans=0;
press=0;
}
if(notenum==0)
{
for(i=0;i<10;i++)
if(!i)
cout<<ans;
else
cout<<" "<<ans;
cout<<endl;
return;
}

for(i=0;i<notenum;i++)
{
n=getindex(note);
for(j=0;j<10;j++)
{
if(a[n][j])
if(!press[j])
ans[j]++;
press[j]=a[n][j];
}
}
for(i=0;i<10;i++)
if(!i)
cout<<ans;
else
cout<<" "<<ans;

cout<<endl;
}



int main()
{
int t;
cin>>t;
char temp[10];
cin.getline(temp,10);
while(t--)
{
work();
}
}

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry » Fri Jan 17, 2003 9:20 am

There are at most 200 notes in a song, and the song maybe empty.
You may want to allocate a little more memory for your string.. an array of 200 is slightly not enough.. try 210 or something. (Remember \0 and \n).

dispanser
New poster
Posts: 18
Joined: Wed May 01, 2002 4:12 pm
Location: Jena/Germany
Contact:

Post by dispanser » Mon Jan 27, 2003 1:55 pm

there is no special trick or algorithm involved i think.

do the test cases from the sample input work for you?

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

need help

Post by anupam » Thu Jan 30, 2003 1:48 pm

i can't understand the problem..
that is why i can't solve this..
will anybody please tell about the problem in easy words..?
i will be greatful to him/her...
i contact yahoo but he gives me no better suggestion..
will you help?
:oops: :oops: :oops:
anupam
"Everything should be made simple, but not always simpler"

User avatar
Ghost77 dimen
Learning poster
Posts: 67
Joined: Sun Sep 22, 2002 5:40 am
Location: Taiwan

Post by Ghost77 dimen » Sun Feb 02, 2003 4:46 pm

The article tells which fingers should press of each note.

So you could achieve the goal by the steps as follows.

Of course, this is just a reference, you can do it yourself.

Step 1

Declare an array or something else you like.

It keeps the messages that which positions you should press of each

note.

Step 2

As above, declare an array.

It keeps the messages that each of your fingers is pressing or relaxing.

Step 3

Also declare an array.

It keeps the messages that the pressing times of each finger.

Start with all zero.

Step 4

Then read the list of notes.

Get a note, goto Step1.

See which positions you should pressing and relaxing.

Goto Step2.

If the finger you should press, but you don't.

Then change it off to on.

Goto Step3, add the calculater to 1.

If the finger you should relax, but you don't.

Then change it on to off.

Don't touch the calculater.

Finally, if the status of your finger is the same as the request, nothing

should be done.

Do it again and again as the request.

Report to the author the number of each calculater displaying.

8) 8) 8)
Good luck.

anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam » Wed Feb 05, 2003 11:21 am

thank you..
you have done just like a great friend..
thaks again and waiting for any help from you everytime..
--anupam :P :P
"Everything should be made simple, but not always simpler"

boatfish
New poster
Posts: 18
Joined: Thu May 08, 2003 11:46 am

10415

Post by boatfish » Fri Jul 11, 2003 11:05 am

For the sample input : cdefgab
why the output is 0 1 1 1 0 0 1 1 1 1.

Because in the first note, finger 2~4, 7~10 were used; then in 2nd note(d), no finger was used; in 3rd note e, finger 2~4, 7, 8 were used. So why finger 2 is used only once?

User avatar
UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 » Mon Aug 11, 2003 7:38 pm

Notes: cde...

First note: c .. 2 3 4 7 8 9 10
Second note: d .. 2 3 4 7 8 9 .. 10 was released, no new fingers pressed
Third not: e .. 2 3 4 7 8 .. 9 was released, no new fingers pressed

Only increment the finger count, if it requires you to use a finger to produce the new note from the previous note.

rubendv
New poster
Posts: 9
Joined: Mon Mar 15, 2004 10:23 pm

10415 - Why Wrong Answer?

Post by rubendv » Sun Feb 20, 2005 1:49 pm

Hi, I have tested my program with an infinity of inputs, and it seems correct to me. However, it still evaluates to WA in the judge. Could anyone take a look at it, or send me some inputs of your one? Thanks!

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

#define MAXLENGTH (10)
#define MAXKEYS (500)

short counters[MAXLENGTH];
short usage[MAXLENGTH];

char song[MAXKEYS + 1];

void processFingers(short *list, int size){
for (int i = 0; i < size; i++)
if (usage[list - 1] == 0){
usage[list - 1] = 1;
counters[list - 1]++;
}
for (int i = MAXLENGTH; i > 0; i--)
for (int j = 0; j < MAXLENGTH; j++){
if (list[j] < i){
usage = 0;
break;
}
else if (list[j] == i)
break;
}
}

void processNote(char c){
short list[MAXLENGTH];
int counter = 0;
switch (c){
case 'c': list[counter++] = 10;
case 'd': list[counter++] = 9;
case 'e': list[counter++] = 8;
case 'f': list[counter++] = 7;
case 'g': list[counter++] = 4;
case 'a': list[counter++] = 3;
case 'b': list[counter++] = 2; break;
case 'C': list[counter++] = 3; break;
case 'D': list[counter++] = 9;
case 'E': list[counter++] = 8;
case 'F': list[counter++] = 7;
case 'G': list[counter++] = 4;
case 'A': list[counter++] = 3;
case 'B': list[counter++] = 2; list[counter++] = 1; break;
}
processFingers(list,counter);
}

void solve(void){
int size = (int)strlen(song);
for (int i = 0; i < size; i++){
processNote(song);
}
}

int main(void){
int n;
scanf("%d%*c",&n);
for (int i = 0; i < n; i++){
for (int i = 0; i < MAXLENGTH; i++){
counters = 0;
usage = 0;
}
song[0] = '\0';
gets(song);
solve();
for (int i = 0; i < MAXLENGTH - 1; i++)
printf("%d ",counters);
printf("%d\n",counters[MAXLENGTH - 1]);
}
return 0;
}

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

10415 WA need some samples

Post by sunnycare » Mon May 09, 2005 5:13 am

Code: Select all

//10415 Eb Alto Saxophone Player
#include <iostream>
using namespace std;
//if finger press on one button;
//then isPress[finger]=true;
bool isPress[11];
//store the number of total press of every finger
int pressNum[11];
char music[210];

void press(int finger)
{
    if(!isPress[finger])
   	{
   	    pressNum[finger]++;
   	    isPress[finger]=true;
   	}
}        
void play(char note)
{
    int i;
    //finger press part
    switch(note)
    {
    case 'c':press(10);
    case 'd':press(9);
    case 'e':press(8);
    case 'f':press(7);
    case 'g':press(4);
    case 'a':press(3);
    case 'b':press(2);break;
    case 'C':press(3);break;
    case 'D':press(9);
    case 'E':press(8);
    case 'F':press(7);
    case 'G':press(4);
    case 'A':press(3);
    case 'B':press(2);
    default:press(1);break;
    }
    //here is finger un-press part
    switch(note)
    {
    case 'b':isPress[3]=false;
    case 'a':isPress[4]=false;
    case 'g':isPress[7]=false;
    case 'f':isPress[8]=false;
    case 'e':isPress[9]=false;
    case 'd':isPress[10]=false;
    case 'c':isPress[1]=false;break;
    case 'C':
        for(i=1;i<=10;i++)
        	isPress[i]=false;
       	isPress[3]=true;
       	break;
    case 'B':isPress[3]=false;
    case 'A':isPress[4]=false;
    case 'G':isPress[7]=false;
    case 'F':isPress[8]=false;
    case 'E':isPress[9]=false;
    case 'D':isPress[10]=false;
    default:break;
    }
}            

int main(int argc,char *argv[])
{
    long n;
    long i;
    cin>>n;
    while(n-->=1)
    {
        cin>>music;
        for(i=1;i<=10;i++)
       	{
       	    isPress[i]=false;
       	    pressNum[i]=0;
       	}
        for(i=0;music[i]!='\0';i++)
        	play(music[i]);
        cout<<pressNum[1];
        for(i=2;i<=10;i++)
        	cout<<' '<<pressNum[i];
        cout<<endl;
    }
}            

User avatar
dumb dan
Learning poster
Posts: 67
Joined: Tue Aug 05, 2003 1:02 am

Post by dumb dan » Mon May 09, 2005 2:07 pm

There are at most 200 notes in a song, and the song may be empty.

input:

Code: Select all

2

CbCbCb
output:

Code: Select all

0 0 0 0 0 0 0 0 0 0
0 3 3 0 0 0 0 0 0 0

Post Reply

Return to “Volume 104 (10400-10499)”