Common BoardWith help of my friend that was just looking at maximums index sequense and found an idea, finally, I got AC. Some hints: 1) Find an idea to calculate next maximum indices from previous ones: all the maximum's indices can be obtained from previous ones in such ways: i = s*2 + 1; or i = s*2 - 1; or i = s*4 + 1; or i = s*4 - 1; for example f(21)=8 is maximum for 21<=n<=34 so 21 = 2*11-1, where 11 is one of previous maximums indices. And so on using all the formulas above. but 2*11+1 = 23 is not a maximum index. so we have to cancel this number (23). 2) Learn to calculate f(n) in O(logn) 3) Generate all maximums indices (about 1500). You can store them in heap to get an access to the smallest maximum index. 4) than read n and just search for it in maximums index array. P.S. who can prove the first and the main idea? If you can, please post here you proof. How did you invent it? Edited by author 05.07.2009 22:51 It seems that only test s*2 - 1 and s*4 - 1 is OK. I've tested by bruteforce program in range [0, 20000000]. I will try it. Edited by author 15.10.2016 08:24 This is exactly how my accepted program runs. Suppose i is a maximum index, i = 2*i1+1, i2 = i1+1, then either 1) i1 is even, at least one of i1/2, i2 is a maximum index; or 2) i2 is even, at least one of i2/2, i1 is a maximum index. But I don't know how to prove it. Thus candidate indices from 2^n to 2^{n+1} can be generated from calculated maximum indices from 2^{n-2} to 2^n. You only have four things to pick from, so you can calculate each step explicitly. This equation follows the notation in the article: T is the time to collect all of the items, and ti be the time to collect the i-th item after i−1 items have been collected. E(T)=E(t1)+E(t2)+E(t3)+E(t4)=p1−1+p2−1+p3−1+p4−1. The probability p1 of picking a new one if you have picked none yet is 1. The probability p2 of picking a new one if you have picked one depends on which one you picked first. Let's call the items A through D and the probabilities of picking each item if they're all in the box pa through pd. Then p2 would be pa(pb+pc+pd)+pb(pc+pd+pa)+pc(pd+pa+pb)+pd(pa+pb+pc). The above expression is the probability of picking a new one given that A had been picked already, plus the probability of picking a new one given that B had been picked already, and so on. The expression for p3 will have six terms in the sum; one of these will be papb(pc+pd). The expression for p4 will have four terms in the sum (actually, it's the same term four times!) What can I do?.. My program passes all testes here, but still WA12... Any test cases? it takes a lot of my times. #include<iostream> using namespace std; int main() { int a, b; cin >> a >> b; cout << b-1 << ' ' << a - 1; } 4 2 2 3 2 1 3 3 1 2 4 1 3 6 5 2 3 4 5 6 5 1 3 4 5 6 5 1 2 4 5 6 5 1 2 3 5 6 5 1 2 3 4 6 5 1 2 3 4 5 8 7 2 3 4 5 6 7 8 7 1 3 4 5 6 7 8 7 1 2 4 5 6 7 8 7 1 2 3 5 6 7 8 7 1 2 3 4 6 7 8 7 1 2 3 4 5 7 8 7 1 2 3 4 5 6 8 7 1 2 3 4 5 6 7 6 2 2 3 2 1 3 2 1 2 2 5 6 2 4 6 2 4 5 a = input() minussum=0 plussum=0 b =[0:3] c =[3:6] c=int(c) minus = c-1 plus = c+1 minus=str(minus) plus=str(plus) for i in minus: i=int(i) minussum+=i for i in plus: i=int(i) plussum+=i n=0 for i in b: i=int(i) n+=i if n == minussum or n == plussum: print("Yes") else: print("No")
Help please) Why re? Edited by author 13.09.2022 23:21 Python files encoded in UTF-8 with BOM always get "Runtime Error 1". It would be nice if it was fixed. I just do maxsimum 30 iteration on my super all doing bruteforce and this give me right ans and i got ac I could solve it using trivial bruteforce. But I get TL, using more clever and probably expected solution. I used this: https://e-maxx.ru/algo/discrete_root (Read only first section, we don't need anything else). The slowest part here is Discrete Logarithm, which I calculate in \sqrt{n} * log_from_map. My program stuck at WA-17 for several times and I don't know the reason why. Can anyone give me some challenging test cases? Update: accepted now. Key point is to run unit test for the integral division function that I wrote. Both self-written complex division and std::complex<long double> division can be used to get approximate value of the quotient. The more - the better! 'cause I have no idea what I'm doing wrong :\ 50 49 8.4 5.5 //1 50 49 8.4 5 //25 50 49 8.4 4 //28 50 49 8.4 2.0 //37 50 49 8.4 0.2 //48 The answer of second test case is 1, not 25. My ac programm gives 1 for second and 25 for third test #include <iostream> using namespace std; int main() { int leavingCars, minutes; int carPerMinute[100]; int totalCars = 0;
cin >> leavingCars >> minutes; int carsLeavingPerMinute = leavingCars * minutes;
for(int index = 1; index <= minutes; ++index) { cin >> carPerMinute[index]; totalCars += carPerMinute[index]; }
cout << totalCars - carsLeavingPerMinute;
return 0; } Are you going to add javascript (especially nodejs) support for this online judge | Планируется ли добавить на сайт поддержку javascript или nodejs? not 21 passes test: using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main() { var f = Console.In.ReadToEnd(); f = f.ToLower(); var b = f.ToCharArray(); string c = ""; c += b[0].ToString().ToUpper(); for (var i = 1; i < b.Length - 3; i++) { if ((i + 1 != b.Length && (b[i] == '!' || b[i] == '?' || b[i] == '.'||b[i] == '-') && (b[i+3] != '-'&&b[i + 1] != '!' && b[i + 1] != '?' && b[i + 1] != '.')))
{ c += b[i]; i++; while (b[i] == ' ' || b[i] == '\t' || b[i] == '\r' || b[i] == '\n') { c += b[i]; if (i + 1 != b.Length) i++; else break; } c += b[i].ToString().ToUpper(); } else c += b[i]; } Console.WriteLine(c); } } } not 4 passes test: using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication3 { class Program { static void Main() { var f = Console.In.ReadToEnd(); f = f.ToLower(); var b = f.ToCharArray(); string c = ""; for (var i = 1; i < b.Length - 1; i++) { if (b[i - 1] == '-') i--; if ((i + 1 != b.Length && i + 2 != b.Length && i + 3 != b.Length && (b[i] == '!' || b[i] == '?' || b[i] == '.' || b[i] == '-') && (b[i + 3] != '-' && b[i + 1] != '!' && b[i + 1] != '?' && b[i + 1] != '.'))) {
c += b[i]; i++; while (b[i] == ' ' || b[i] == '\t' || b[i] == '\r' || b[i] == '\n') { c += b[i]; if (i + 1 != b.Length) i++; else break; } c += b[i].ToString().ToUpper(); } else { if (i == 1) c += b[i - 1].ToString().ToUpper(); c += b[i]; } } Console.WriteLine(c); } } } Edited by author 03.01.2015 21:08 - IS IT CORRECT? - YES, IT IS. - Is it correct? - Yes, it is. Мне этот пример помог 21 тест пройти If you have this problem - remember that a sentence is ended only with "!?." Endline is not an end of a sentence Here are jokes with statuses, such as we go in order along the vertices and if we get to a vertex that we haven't been to, then we start going in a cycle from this vertex, setting the status of this cycle, if we get to the same status, then this is a cycle, if we get to a vertex with a lower status, then everything is fine and we stop the cycle, and if the vertex has no status, then we just opened a new vertex and it turns out that the algorithm is linear I've been trying to solve this problem for so long, I've had a lot of errors, more than 150 lines of clean code, I've tried to do a little dirty debug, but I think it's not fair. I got wa11, I didn't know what it was, it just turns out I forgot to sort the array correctly, it was in the second part when I'm looking for vertical stripes that I forgot to sort and got wa 11, while I was looking for it, I did a lot of tests and can show them to you. I can give advice on what to count, count all vertical rectangles 1*l where l>=2 and horizontal rectangles l*1 where l>=2, add them up and add all single cells. tests: 4 4 10 1 2 1 3 2 1 2 4 3 2 3 3 4 1 4 2 4 3 4 4 5
4 4 5 1 2 2 1 2 4 3 3 4 2 9 4 4 8 2 1 2 2 2 3 2 4 3 1 3 4 4 2 4 3 4 4 4 8 1 2 1 3 2 1 2 3 3 1 3 3 3 4 4 2 5 4 4 4 2 2 2 3 3 2 3 3 4 4 4 3 2 3 3 2 3 3 6 5 5 2 4 3 3 4 12 5 5 5 1 3 3 1 4 1 3 4 4 3 12 5 5 6 1 3 3 1 4 1 4 2 4 3 3 4 12 5 5 12 1 2 1 4 2 1 2 3 2 5 3 2 3 4 4 1 4 3 4 5 5 2 5 4 13 5 5 11 1 2 1 4 2 1 2 3 2 5 3 2 3 4 4 1 4 5 5 2 5 4 11 5 5 9 1 2 2 4 3 1 3 3 3 4 4 2 4 5 5 2 5 5 11 5 5 9 1 5 2 5 2 4 3 3 3 4 4 2 4 3 5 1 5 2 10 5 5 12 1 2 1 3 1 4 2 1 3 1 4 1 2 5 3 5 4 5 5 2 5 3 5 4 10 6 6 12 2 1 2 2 2 3 2 4 2 5 3 5 4 5 5 5 5 4 5 3 5 2 4 2 8 7 4 14 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 4 2 4 3 4 4 4 5 4 6 4 7 4 9 7 4 18 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 4 2 4 3 4 4 4 5 4 6 4 7 4 1 2 1 3 7 2 7 3 7 7 4 20 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 4 2 4 3 4 4 4 5 4 6 4 7 4 1 2 1 3 7 2 7 3 4 2 4 3 8 7 4 28 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 4 2 4 3 4 4 4 5 4 6 4 7 4 1 2 1 3 7 2 7 3 4 2 4 3 3 2 3 3 2 2 2 3 5 2 5 3 6 2 6 3 0 7 4 27 1 1 2 1 3 1 4 1 5 1 6 1 7 1 1 4 2 4 3 4 4 4 5 4 6 4 7 4 1 2 1 3 7 2 4 2 4 3 3 2 3 3 2 2 2 3 5 2 5 3 6 2 6 3 1 7 4 7 1 2 2 3 3 2 4 3 5 2 6 3 7 2 9 7 4 1 3 2 12 7 5 1 2 3 13 7 5 2 3 3 4 3 15 7 5 10 1 2 2 2 5 2 6 2 7 2 1 4 2 4 5 4 6 4 7 4 7 7 4 14 1 1 3 1 5 1 7 1 2 2 4 2 6 2 1 3 3 3 5 3 7 3 2 4 4 4 6 4 14 5 1 4 1 1 3 1 4 1 5 1 2 WRONG!!! on this test i have eror, right ans is 1 good luck, don't give up it's not such a difficult problem! Каким образом во втором тесте(примере) получаем 2 полосы??? если даже когда вручную нарисовав таблицу 1х5, получаем максимум 1 полоску????каким образом вторая получается??? п.с.или белая полоса может состоять из одного дня???? How in the second test(example) does get 2 bars??? if even when by hand drawing a table 1x5, get a 1 strip maksimum???? how does the second turn out??? p.s. or can a white bar consist of one day???? Kakim obrazom vo vtorom teste(primere) poluchaem 2 polosy??? esli dazhe kogda vruchnuju narisovav tablicu 1h5, poluchaem maksimum 1 polosku????kakim obrazom vtoraja poluchaetsja??? p.s.ili belaja polosa mozhet sostojat' iz odnogo dnja???? Без комментариев No comments Bez kommentariev Исправьте тесты! Неправильные примеры. It is all right. Even 1 square is the bar (if it not contains in other bars). So it must be added. ti cho otvet 0, poloska dlinoi odin ne mojet bit, a test is inkarekt |
|