|
|
Отсутствует язык отправки C# I devised that maybe I need to solve many systems of equations. I know the solution if the system has odd equations, but how do I solve the one with even equations? For example: solve for ai, with ki = initial cups at knight i, and F as the final cups to be achieved. a1 + a2 + k2 = F a2 + a3 + k3 = F a3 + a4 + k4 = F a4 + a1 + k1 = F I cannot solve this, even if I could I couldn't image myself programmatically solve it. If the solution is different, please give me some advise. Thanks! For future solver - Basically that's the correct solution despite being optimized or not. For even number of equations, you can solve it directly to save some mem, or you can just bruteforce like me (-1000 -> 1000) for the first value and solve the rest. That will tank the memory alot but it should be fine if you prayed for mercy first before you submit. can you help me with some tests? I tried every tests in the discussions and they're fine, I also try my own tests with big number too. to clarify, my understanding is that, 0 <= F <= 1000 right? For future solver - This is because while trying to solve system of equations that involves a subset of Knights, I put the "last index + 1" Knight to be 0, which is not true, the system does not always start with Knight 0 Try this if you have WA18: 10 7 3 0 5 9 2 3 7 3 1 4 4 The answer is: 12 1 8 + 1 8 + 4 1 + 9 6 + 2 9 - 2 9 - 3 10 - 6 3 - 6 3 - 6 3 - 6 3 - 6 3 - My solution falls on test 29. I have AC. My calculation of some values was wrong.:( TLE27???????????????? как исправить I don't know, what's wrong with my code. Who knows what's the trap? My AC solution gets WA test 29 if I replace `long` with `short int` (short int is 2 bytes, long is 4) P.S. You've got AC, so maybe you'd write what your problem was, to help anyone? Edited by author 04.02.2006 06:51 Okay, I got AC. But I still don't know, what was wrong with test 23. First I tried to solve this problem by solving Hauss equations very accurately. It works very fast, but it didn't pass the 23 test. After that I rewrote the code. Now I solved 'the rings' directly. It's much slower, but it got AC. The hints are: Start with the first knight and put the numbers 1, 1+K,1+2*K,etc. in a buffer, until you reach the first knight again. These knights form a ring, as I call it. They are served by servant in a form of a ring and don't intersect with other knights. So you can check them separately (the problem, therefore, can be separated in few parts). Now, let us denote: X[i] - the number of goblets brought to the i-th and (i+K)-th knight (don't forget, that i+K maybe more that N and use modulus). Therefore we can say that: X[i]+X[i+K]=F-A[i+k], there A[i]- the initial number of goblets near the i-th knight. Also X[i-K]+X[i]=F-A[i], and etc. Therefore you have to solve a system of linear equations, where each equation has two variables (others are zero). This can be optimised very well. If number of knights in the ring is odd, the solving is one. If it's even, you have to minimise it. The result is Sum(|X[i]|). Good luck to you all If you don't understand the solution you can mail me: vdshevch2@mail.ru I got AC! At first,My program got WA on #18, My bug is when N is even number,my answer is not minimum value 6 1 2 0 2 2 2 2 0 answer should be: 2 6 1 + 6 1 + I got WA test #21 many times before getting AC. I printed the result without noticing that the servant can take goblets from a knight only if he has at least one goblet near him. So you should print all '+' first and then '-'. 4 1 2 1 0 0 1 ans: 3 2 3 + 2 3 + 1 4 + 3 1 0 3 0 0 ans:-1 4 1 8 7 7 9 9 ans: 2 1 2 + 3 4 - 8 3 2 0 0 2 2 2 3 2 1 ans: 8 1 4 + 1 4 + 7 2 + 7 2 + 8 3 + 3 6 - 4 7 - 4 7 - 5 2 4 3 3 2 2 1 ans:-1 I remembmer clearly that when I solved it there were 74 accepts (I was 75-th). After that the number of AC grew to 90. And right now there is just 70 AC's. What happened? You are right. There were several bugs in the old validator in this problem. Because of them authors with incorrect solutions could get AC. I fixed the validator about 1 or 2 monthes ago. Tests were not changed. My prog WA test 3 please post this test or give me somr test!!! |
|
|