nema sigurnijeg osjećaja nego kad mi čitaš naglas
-savršen spoj
seen from Germany

seen from Czechia

seen from United States
seen from United States

seen from United Kingdom
seen from Romania
seen from Poland

seen from United States
seen from China
seen from Spain

seen from China
seen from Spain
seen from Netherlands
seen from Kazakhstan
seen from China
seen from Singapore
seen from United Kingdom
seen from South Korea
seen from China
seen from United States
nema sigurnijeg osjećaja nego kad mi čitaš naglas
-savršen spoj
...
I have just solved the "A Bug’s Life" challenge on SPOJ - https://www.spoj.com/BUGLIFE
Spojna cesta s brzom - #Hrvatska, #Krapinsko-zagorska, #Promet
Nova objava na portalu CroGlasnik
Spojna cesta s brzom
brza cesta, cesta, priključak, promet, spoj
Hrvatska, Krapinsko-zagorska, Promet
SPOJ Problem : Hint for MUTDNA
Actually, I think post a solution’s source code of an online judge problem is like spoiling movie. If you;re actually a coder, I think you don’t need to read this. But, if you’re a novice coder and look for a hint in this problem, I think I can help you XD.
First, read the problem properly.
Biologists have discovered a strange DNA molecule, best described as a sequence of N characters from the set {A, B}. An unlikely sequence of mutations has resulted in a DNA strand consisting only of A's.
Biologists found that very odd, so they began studying the mutations in greater detail.
They discovered two types of mutations. One type results in changing a single character of the sequence (A → B or B → A). The second type changes a whole prefix of the sequence, specifically replacing all characters in positions from 1 to K (for some K between 1 and N, inclusive) with the other character (A with B, B with A).
Compute the least possible number of mutations that could convert the starting molecule to its end state (containing only A characters). Mutations can occur in any order.
Did you get the idea?
You have a sequence of A and B string (for example, I just take AABB).
You can mutation the string either A to B or B to A in the following rule :
1. Just change 1 gen in the random position
2. Change a series of gen from start position until it reach flip position. For example, I can flip AABAB to BBBAB. Start position is A and I flip the series of A to B until it reach B position.
Your goal is to make all letter in this sequence A with a minimum mutation. Can’t you think a solution?
.
.
.
.
.
.
.
.
.
.
Ok, I have two solution for this problem.
First, is a Dynamic Programming Forward solution. I think this is too difficult to explain.
Second, is just an Ad-Hoc. Yeah...! I’ll explain this solution. Let’s make an example AAABBBABA.
First thing that I think of this problem’s solution is brute force.
With rule 1, we can change all of the B to the A. It take 4 mutations.
With rule 2, we can flip all the series with this order (AAABBBABA, BBBBBBABA, AAAAAAABA, BBBBBBBBA, AAAAAAAAA). It take same mutation, 4 mutations.
But, look at the 3rd order. It’s so ienefficient to mutate just 1 B with two times, we can directly flip it right? Okay, if we directly flip it, we have 3 mutation. It’s the minimum answer.
Did you get the idea? Okay. My algorithm is so simple, here it is.
1. From the start we count from 0
2. If there are a series of letter that contain more than 1 Bs, add 2 mutation
3. But, if there is just 1 B, add 1 mutation
However, there are a case that this algorithm didn’t work, do you know which case? Yeah, for example BBBAAABA
It took 2 mutation, but if you use the algorithm above, you got 3 mutation. We can’t just test the first letter is B or not, because there is also a case that it didn’t work. Now, how we can fix this?
Okay. Now, I have an idea. How about we have a variable named X that responsible for the changing series.
We set the X variable is ‘A’ and if there is a sequence of ‘B’ we change the X to ‘B’ and increment the answer. Except if we just detect a single letter that didn’t match the series we can just flip it directly.
For example :
X = A, ans = 0
Because the ‘BBBAAABA’ is start with B series, we add 1 to ans and change X to B so
X = B, ans = 1
And the next series is A in the 4th position so
X = A, ans = 2
And flip the random B appear in 7th position so
X = A, ans = 3
Still wrong? Okay, we change the initial value of X with ‘B’. Actually I know that I’m wrong because if we start with ‘B’ we can make sure that we just flip once if the first gen is B.
Example :
X = B, ans = 0
Series change in the 4th position
X = A, ans = 1
And flip random B in 7th position
X = A, ans = 2
So the algorithm is :
1. Let X = ‘B’ and ans = 0
2. Begin at the first, if we found a series of letter that different from X increment ans and change X with the series
3. Except if there is just 1 letter, we just increment ans and go ahead without change the X
But, you still get WA with that algorithm, why?
Because, with this algorithm we just guarantee that the DNA is mutate to a sequence of same letter. So it’s possible that the DNA is mutate to BBBBBB too. So, what’s the solution?
Of course, we can guarantee that the sequence is AAAAA by backward approach. Starting with X = ‘A’ and go backward with the same algorithm.
Hope this will help.
Snowman (SNOWMAN)
(klik di sini untuk soal)
Source Code (dalam C)
#include <stdio.h> #include <math.h>
#define PI 3.14159265
int main() { int t; double v, r, h;
scanf("%d", &t);
while(t--) { scanf("%lf", &v);
r = pow( (48*v) / (129*PI), 1.0/3.0); h = 4 * r + 0.5 * r; h = floor(h);
printf("%d\n", (int)h); printf("\n"); }
return 0; }
Analisis Algoritma
Untuk mencari volume sebuah bola, kita dapat menggunakan rumus:
V = 4/3 * pi * r^3
Karena manusia salju yang akan dibuat terdiri dari tiga bola, dengan dua bola memiliki ukuran yang sama dan satu bola memiliki jari-jari 25% dari bola yang lebih besar, maka rumus volume totalnya menjadi:
Vtotal = 2 * Vbesar + Vkecil
= 2 * 4/3 * pi * r^3 + 4/3 * pi * [(1/4)r]^3
= 8/3 * pi * r^3 + 4/3 * 1/64 * pi * r^3
= 8/3 * pi * r^3 + 1/48 * pi * r^3
= 129/48 * pi * r^3
Melalui rumus tersebut, kita dapat menemukan jari-jari dari bola yang besar.
r^3 = 48/(129 * pi) * Vtotal
r = [ 48/(129 * pi) * Vtotal]^1/3
Sekarang kita sudah menemukan panjang jari-jari dari bola yang besar, sehingga kita bisa menemukan tinggi dari manusia salju. Ingat bahwa manusia salju tersebut terdiri dari dua bola yang sama besar dan satu bola yang jari-jarinya 25% dari bola yang besar, sehingga untuk menemukan tingginya, kita menggunakan rumus berikut:
Ttotal = Tbesar + Tkecil
= 4 * r + 2 * 1/4 * r
= 9/2 * r
Karena soal meminta untuk membulatkan jawaban ke integer terkecil, maka kita menggunakan fungsi floor() dan men-typecast variabel untuk tinggi menjadi integer.
Najgori Spoj za Vaš Znak.
Ovan Bik Blizanci Rak Lav Devica Vaga Skorpija Strelac Jarac Vodolija Ribe