Page 1 of 2

11201 - The problem of the crazy linguist

Posted: Sat May 19, 2007 2:57 pm
Why WA?

my coefficients of average of the SBC are:

AV[0] = 0;
AV[1] = 5506 / 2100;
AV[2] = 216824 / 10500;
AV[3] = 299414 / 10500;
AV[4] = 678002 / 10500;
AV[5] = 271884 / 3500;
AV[6] = 461178 / 3500;
AV[7] = 1576244 / 10500;

But i have WA why?

Posted: Sat May 19, 2007 3:45 pm
Did you take in account the first letter of each word?

Posted: Sat May 19, 2007 5:38 pm
Yes

Posted: Sat May 19, 2007 7:13 pm
i didnt understand how u are handling the first letter.
for any length, starting a word with different consonants the SBC average would be different. u can precalculate the 21*7 averages.

Posted: Sun May 20, 2007 8:04 am
well... my code got ac in .027s.. i did not do any pre computation. just a bit tricky bruteforce!

Posted: Sun May 20, 2007 11:55 am
Oh!

((( now I understand my mistake.

AC now in my solution no brute force. Complexity is O(len(s))

WA.....

Posted: Mon May 21, 2007 9:26 am
Someone please provide some test cases..
i got wa.. used brute force to find answer....

regards...

Posted: Tue May 22, 2007 2:47 pm
before i sent this code to online judge i had test it with dev4.9.9.2 and visual studio C++ 6.0 and worked well
but i dont know why it says it has "runtime error!" :

------------------------------
Your program has died with signal 11 (SIGSEGV). Meaning:

Invalid memory reference

Before crash, it ran during 0.002 seconds.
-----------------------------

can anyone help me?

Code: Select all

``````#include <iostream>
#include <string>
using namespace std;

double p[]={12.53,1.42,4.68,5.86,13.68,0.69,1.01,0.70,6.25,0.44,0.00,4.97,3.15,6.71,8.68,2.51,0.88,6.87,7.98,4.63,3.93,0.90,0.02,0.22,0.90,0.52};

double sbc(string w)
{
int k;
double su=0;

for (k=0;k<w.length();k++)
{
su += k*p[(int(w[k])-97)];

}
return su;
}

int main()
{
int i,l,k,m,n;
double j[100];
string str[100];
cin >> i ;
for (l=0;l<i;l++)
{
cin >> str[l];
j[l]=sbc(str[l]);

}
for (l=0;l<i;l++)
{
m = str[l].length();
n=0;
double sum=0,av = 0;
for (k=0;k<i;k++)
{
if (str[k].length() == m)
{
n +=1;
sum += sbc(str[k]);
}
}
av = sum / n;
if (sbc(str[l]) < av) cout << "below"<< endl;
else cout << "above or equal" << endl;
}

return 0;

}

``````

Posted: Tue May 22, 2007 3:27 pm
Why is your array size 100? It could be the reason

Posted: Wed May 23, 2007 2:17 pm
h_davary wrote
before i sent this code to online judge i had test it with dev4.9.9.2 and visual studio C++ 6.0 and worked well
but i dont know why it says it has "runtime error!" :
Emilio wrote
Why is your array size 100? It could be the reason
Yes this is the reason of getting u run time. But I think if u increase the array size u will get wrong answer because u missunderstood the problem.

In this problem u have to calculate the SBC of all the words which start with the same latter as given word( with the same length ) then find the average and have to determine the given words SBC is "below" or "above or below" than the average.

Posted: Fri May 25, 2007 8:17 pm
Victor Barinov wrote:Oh!

I don't understand this part. Does it mean "all valid words that start with x1" ?

Posted: Sat May 26, 2007 2:55 am
Yes.
All the words that can be constructed folowing the above pattern starts with x1.

oh yes..

Posted: Sun May 27, 2007 2:38 pm
Emilio wrote
Why is your array size 100? It could be the reason
Mushfiqur Rahman wrote
But I think if u increase the array size u will get wrong answer because u missunderstood the problem...
oh, thanks ...you'r right the size of my array wasn't sufficent and
in general i missed the main point of this problem ...

I will try to solve it again but one question is there anyway to solve it other than brute forceing
maybe it takes a long time to do brute forceing

Posted: Wed May 30, 2007 7:20 am
Ya, you can use combinatorics. But for the length(s) = 7, it is bit harder.
I also use combinatorics, but get wrong answer several time but didn't know why. At last, I get accepted using backtracking (Complete brutforce).

Posted: Sun Jun 03, 2007 4:27 am
note that the summantion of all letters' possibilitiy is not exactly 100 ( over than it).