10295 - Hay Points
Moderator: Board moderators
10295 - Hay Points
It says the dollars value are real numbers, so how to output them?
10295
I'm getting WA for this problem.My algo is right and I can pass simple input.I'm sorting words than use binary search to find word in dictionary.
I whant to know, are there many inputs ending with eof or just one test?
Thanks.
I whant to know, are there many inputs ending with eof or just one test?
Thanks.
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
10295 Hay Points
hi, i am stuck with this problem(10295)... i have some inquiries ...
[/quote]
a dollar value (a real number between 0 and 1,000,000)
Code: Select all
Does that mean that point is a floating point number ?
Then how come the sample output is without decimal point...
(Is it because the sample input produces result without fractions !!!)
SECONDLY,
what is the size of the array to take per input line ?
[I use some 10000000 bytes char array and gets RE :(]
Please clarify ... thanks.
SOLARIS ... thanks.
scanf("%s", str) is well enough to get ACC. THANKS SOLARIS
, i am honored to be your friend. Thanks again.
![:D](./images/smilies/icon_biggrin.gif)
-
- New poster
- Posts: 20
- Joined: Thu Jan 19, 2006 2:32 pm
10295 WA (need some Sample Input!!!)
10295 WA ( I need some Sample Input!!!)
Man... I guess I learned a few tricks in the meantime, but this is plain silly:
AC
WA
AC
Code: Select all
st = new StringTokenizer(readLine());
String s = st.nextToken();
int val = parseInt(st.nextToken());
list.put(s, new Integer(val));
Code: Select all
st = new StringTokenizer(readLine());
list.put(st.nextToken(), new Integer(parseInt(st.nextToken())));
^^...
sorry, i'm not good at english.
I Got Compile Error Many Times
ACed
ACed
Last edited by hamedv on Thu Aug 16, 2007 6:29 pm, edited 1 time in total.
Runtime Error - Hay Points problem
Hi, I'm getting runtime error with my Hay Points problem (10295)
I really appreciate any help.
Here is the code:
I really appreciate any help.
Here is the code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct no
{
char pala[16];
long value;
}dictionary;
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo );
void Quick(dictionary tabela[], unsigned inf, unsigned sup);
void QuickSort(dictionary tabela[], unsigned nElem);
int EncontraIndice(char palavra[], dictionary tabela[], int tam);
int main()
{
dictionary words[1000];
char aux[16];
char palavra[16];
long aux2;
long score;
int help;
int numberWords;
int numberJobs;
int i = 0;
scanf("%d %d", &numberWords, &numberJobs);
while(i < numberWords)
{
scanf("%s %ld", words[i].pala, &words[i].value);
i++;
}
if(strcmp(words[0].pala, words[1].pala) < 0 )
{
strcpy(aux, words[1].pala);
aux2 = words[1].value;
strcpy(words[1].pala, words[0].pala);
words[1].value = words[0].value;
strcpy(words[0].pala, aux);
words[0].value = aux2;
}
QuickSort(words, numberWords);
i = 0;
while(i < numberJobs)
{
score = 0;
while(1)
{
scanf("%s", palavra);
if(!strcmp(palavra,"."))
{
break;
}
help = EncontraIndice(palavra, words, numberWords);
if(help == -1)
{
continue;
}
else{
score = score + words[help].value;
}
}
printf("%ld\n", score);
i++;
}
return(0);
}
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo )
{
char pivo[16];
long vpivo;
unsigned sobe, desce;
char aux[16];
int vaux;
strcpy(pivo,tabela[inf].pala);
vpivo = tabela[inf].value;
sobe = inf;
desce = sup;
while (sobe < desce) {
while (strcmp(tabela[sobe].pala, pivo) <= 0 && sobe < sup)
sobe++;
while (strcmp(tabela[desce].pala, pivo) > 0)
desce--;
if (sobe < desce) {
strcpy(aux, tabela[desce].pala);
vaux = tabela[desce].value;
strcpy(tabela[desce].pala, tabela[sobe].pala);
tabela[desce].value = tabela[sobe].value;
strcpy(tabela[sobe].pala, aux);
tabela[sobe].value = vaux;
}
}
strcpy(tabela[inf].pala, tabela[desce].pala);
tabela[inf].value = tabela[desce].value;
strcpy(tabela[desce].pala, pivo);
tabela[desce].value = vpivo;
*posPivo = desce;
}
void Quick(dictionary tabela[], unsigned inf, unsigned sup)
{
unsigned posPivo;
if (inf >= sup)
return;
Particiona(tabela, inf, sup, &posPivo);
Quick(tabela, inf, posPivo-1);
Quick(tabela, posPivo+1, sup);
}
void QuickSort(dictionary tabela[], unsigned nElem)
{
Quick(tabela, 0, nElem-1);
}
int EncontraIndice(char palavra[], dictionary chaves[], int tam)
{
int limiteInf, limiteSup, metade;
limiteInf = 0;
limiteSup = tam - 1;
while(limiteInf <= limiteSup) {
metade = (limiteInf + limiteSup)/2;
if (!strcmp(chaves[metade].pala, palavra))
{
return metade;
}
if (strcmp(palavra, chaves[metade].pala) < 0)
limiteSup = metade - 1;
else
limiteInf = metade + 1;
}
return -1;
}
Re: 10295 - Hay Points
I'm getting Runtime Error
Any help is appreciated.
I'm just wondering where is the error, on my computer it runs fine.
Here is the code:
Any help is appreciated.
I'm just wondering where is the error, on my computer it runs fine.
Here is the code:
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct no
{
char pala[16];
long value;
}dictionary;
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo );
void Quick(dictionary tabela[], unsigned inf, unsigned sup);
void QuickSort(dictionary tabela[], unsigned nElem);
int EncontraIndice(char palavra[], dictionary tabela[], int tam);
int main()
{
dictionary words[1000];
char aux[16];
char palavra[16];
long aux2;
long score;
int help;
int numberWords;
int numberJobs;
int i = 0;
scanf("%d %d", &numberWords, &numberJobs);
while(i < numberWords)
{
scanf("%s %ld", words[i].pala, &words[i].value);
i++;
}
if(strcmp(words[0].pala, words[1].pala) < 0 )
{
strcpy(aux, words[1].pala);
aux2 = words[1].value;
strcpy(words[1].pala, words[0].pala);
words[1].value = words[0].value;
strcpy(words[0].pala, aux);
words[0].value = aux2;
}
QuickSort(words, numberWords);
i = 0;
while(i < numberJobs)
{
score = 0;
while(1)
{
scanf("%s", palavra);
if(!strcmp(palavra,"."))
{
break;
}
help = EncontraIndice(palavra, words, numberWords);
if(help == -1)
{
continue;
}
else{
score = score + words[help].value;
}
}
printf("%ld\n", score);
i++;
}
return(0);
}
void Particiona(dictionary tabela[], unsigned inf, unsigned sup, unsigned *posPivo )
{
char pivo[16];
long vpivo;
unsigned sobe, desce;
char aux[16];
int vaux;
strcpy(pivo,tabela[inf].pala);
vpivo = tabela[inf].value;
sobe = inf;
desce = sup;
while (sobe < desce) {
while (strcmp(tabela[sobe].pala, pivo) <= 0 && sobe < sup)
sobe++;
while (strcmp(tabela[desce].pala, pivo) > 0)
desce--;
if (sobe < desce) {
strcpy(aux, tabela[desce].pala);
vaux = tabela[desce].value;
strcpy(tabela[desce].pala, tabela[sobe].pala);
tabela[desce].value = tabela[sobe].value;
strcpy(tabela[sobe].pala, aux);
tabela[sobe].value = vaux;
}
}
strcpy(tabela[inf].pala, tabela[desce].pala);
tabela[inf].value = tabela[desce].value;
strcpy(tabela[desce].pala, pivo);
tabela[desce].value = vpivo;
*posPivo = desce;
}
void Quick(dictionary tabela[], unsigned inf, unsigned sup)
{
unsigned posPivo;
if (inf >= sup)
return;
Particiona(tabela, inf, sup, &posPivo);
Quick(tabela, inf, posPivo-1);
Quick(tabela, posPivo+1, sup);
}
void QuickSort(dictionary tabela[], unsigned nElem)
{
Quick(tabela, 0, nElem-1);
}
int EncontraIndice(char palavra[], dictionary chaves[], int tam)
{
int limiteInf, limiteSup, metade;
limiteInf = 0;
limiteSup = tam - 1;
while(limiteInf <= limiteSup) {
metade = (limiteInf + limiteSup)/2;
if (!strcmp(chaves[metade].pala, palavra))
{
return metade;
}
if (strcmp(palavra, chaves[metade].pala) < 0)
limiteSup = metade - 1;
else
limiteInf = metade + 1;
}
return -1;
}