Show all threads Hide all threads Show all messages Hide all messages | My solution | Pearl | 1792. Hamming Code | 4 Oct 2018 04:27 | 1 | First, let give the bits some names, I put them inside the parentheses: Petal 1 (p1) = II (c2) + III (c3) + IV (c4) Petal 2 (p2) = I (c1) + III (c3) + IV (c4) Petal 3 (p3) = I (c1) + II (c2) + IV (c4) As p1, p2 and p3 are created from c1, c2, c3, c4, we check each change in c1, c2, c3, c4: When c1 change: p2 and p3 won't match the value calculated using the formular above (i.e: c1 + c3 + c4 != p2 and c1 + c2 + c4 != p3) When c2 change: p1 and p3 will go wrong When c3 change: p1 and p2 will go wrong As c4 contribute to the value of all three petals, if it is changed then p1, p2 and p3 will all go wrong. In short: Calculate ep1, ep2 and ep3 from the first 4 bits (the e in ep stand for expected), then compare them with the given p1, p2 and p3: All three pairs do not match: c4 is changed p1 and p2 do not match: c3 is changed p1 and p3 do not match: c2 is changed p2 and p3 do not match: c1 is changed Only p1 not match: p1 is changed Only p2 not match: p2 is changed Only p3 not match: p3 is changed | Correction in problem statement (for english version) | sourabh23 | 1792. Hamming Code | 27 May 2018 17:07 | 1 | Instead of "if you enemy..." it should be "if your enemy...". | How I solved it. | Mahilewets | 1792. Hamming Code | 5 Dec 2017 20:25 | 2 | I have used bitmasks. There are only 16 possible Hamming codes. So, I have precalculated. Then check, whether input is a valid code. Then try to find such valid code that it differs from input in exactly one position (I have used xoring for that) and print that codr. Don't forget about zero code. That is a special case. Можно ведь и проще гораздо) Составить три булевых функции (они вполне конкретно прописаны в условии), принимать за ошибку по очереди каждую цифру и смотреть, какие из функций при этом должны вернуть истину, а какие ложь. Остаётся прописать 8 if, один из них будет на код без ошибок, остальные - на соответствующую ошибку. Остаётся её исправить и вывести ответ) | Only for uzbek | TUITUF_Bahrom | 1792. Hamming Code | 12 Nov 2013 19:55 | 4 | if((a[2]+a[3]+a[4])%2==a[5] && (a[1]+a[3]+a[4])%2==a[6] && (a[2]+a[1]+a[4])%2==a[7]) shu bajarilguncha ketma-ketlikni o'zgartirib borasiz 0 bo'lsa 1 va aksincha 1 bo'lsa 0 Masalan: 0 1 0 1 1 0 1 for petal 0 1 0 1 1 0 1 1 0 1 for petal 0 0 1 0 0 0 1 1 0 1 for petal 1 1 1 0 1 1 1 1 0 1 for petal 1 0 0 0 1 0 0 1 0 1 for petal 1 0 1 Edited by author 30.09.2013 14:39 Mana tayyor kod!!! [code deleted] Edited by Muzaffardjan Karaev M.K _77 )))xD 11.11.2013 11:11 Edited by author 12.11.2013 19:58 Edited by moderator 24.11.2019 12:42 | wa 8 | garra | 1792. Hamming Code | 9 Jun 2012 13:19 | 2 | wa 8 garra 9 Jun 2012 11:06 #include<stdio.h> #include<stdlib.h> int main() { int a[8],i,q1=0,q2=1,q3=2,q4=3,r1=4,r2=5,r3=6; for(i=0;i<7;i++) { scanf("%d",&a[i]); } if((a[q2]+a[q3]+a[q4])%2==a[r1]&&(a[q1]+a[q3]+a[q4])%2==a[r2]&&(a[q1]+a[q2]+a[q4])%2==a[r3]) { for(i=0;i<7;i++) { printf("%d",a[i]); printf(" "); } } else if ((a[q2]+a[q3]+a[q4])%2!=a[r1]&&(a[q1]+a[q3]+a[q4])%2!=a[r2]&&(a[q1]+a[q2]+a[q4])%2==a[r3]) { if(a[q3]==1) { a[q3]=0; } else { a[q3]=1; } for(i=0;i<7;i++) { printf("%d",a[i]); printf(" "); } } else if((a[q2]+a[q3]+a[q4])%2!=a[r1]&&(a[q1]+a[q3]+a[q4])%2==a[r2]&&(a[q1]+a[q2]+a[q4])%2!=a[r3]) { if(a[q2]==1) { a[q2]=0; } else { a[q2]=1; } for(i=0;i<7;i++) { printf("%d",a[i]); printf(" "); } } else if((a[q2]+a[q3]+a[q4])%2==a[r1]&&(a[q1]+a[q3]+a[q4])%2!=a[r2]&&(a[q1]+a[q2]+a[q4])%2!=a[r3]) { if(a[q1]==0) { a[q1]=1; } else { a[q1]=0; } for(i=0;i<7;i++) { printf("%d",a[i]); printf(" "); } } else { if(a[q4]==1) { a[q4]=0; } else { a[q4]=1; } for(i=0;i<7;i++) { printf("%d",a[i]); printf(" "); } } return 0; } | Tests :) WA 8 | Dawid Drozd | 1792. Hamming Code | 29 May 2012 17:50 | 5 | IN 0 1 1 0 0 0 0 OUT 1 1 1 0 0 0 0 IN 1 0 1 0 0 0 0 OUT 1 1 1 0 0 0 0 IN 1 1 0 0 0 0 0 OUT 1 1 1 0 0 0 0 IN 1 1 1 1 0 0 0 OUT 1 1 1 0 0 0 0 IN 1 1 1 0 1 0 0 OUT 1 1 1 0 0 0 0 IN 1 1 1 0 0 1 0 OUT 1 1 1 0 0 0 0 IN 1 1 1 0 0 0 1 OUT 1 1 1 0 0 0 0 My program gives correct answer for the above tests. But I am getting wrong answer for Test 35 :( More tests please! the bits are ordered like this: 1, 2, 3, 4, (2^3^4), (1^3^4), (1^2^4) and not: 1, 2, 3, 4, (1^2^4), (1^3^4), (2^3^4) good luck. Edited by author 25.09.2011 20:53 I don't think that, because if we take x^0, x=0 or x=1, so we have always 1! Edited by author 02.10.2011 19:27 Edited by author 02.10.2011 19:28 The seven numbers: a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[5]:=(a[2]+a[3]+a[4]) mod 2 a[6]:=(a[1]+a[3]+a[4]) mod 2 a[7]:=(a[1]+a[2]+a[4]) mod 2 May it help you. Good lucky |
|
|