Общий форумIf using recursive algorithm increase recursion depth limit at least 4000. For my algo 2000 was not enough import sys sys.setrecursionlimit(4000) >>> print(round(0.0)) >>> 0.0 But "The output should contain the required distance in meters rounded to two fractional digits" So don't forget to use string formatting to provide 2 digits after comma Real test case: 5 90 2.50 0.00 This is proof of why answer < 3. Suppose, we have 3 elements x, y, z, with gcd(x, y, z) != 1. Then, after first transformation array will contain elements: gcd(x, y), gcd(x, z), gcd(y, z), Let's call them a = gcd(x, y), b = gcd(x, z), c = gcd(y, z). After second tranformation array will contain elements: gcd(a, b), gcd(a, c), gcd(b, c), we can notice, that: gcd(a, b) = gcd(gcd(x, y), gcd(x, z)) = gcd(x, y, x, z) = gcd(x, y, z). Doing similar things with gcd(a, c) and gcd(b, c), it turns out, that gcd(a, b) = gcd(a, c) = gcd(b, c) = gcd(x, y, z). That means, that after 2nd transformation array will contain 3 equal numbers greater than 1. I think it's obvious, that answer will be infinity, if array contains 3 equal numbers greater than 1. Now, if gcd of any tripple of numbers equals one, that means, that we will end in less than 2 transformations (Proof this by yourself) Edited by author 22.01.2022 15:49 var a: array[1..2000] of string; i: integer; begin for i := 1 to 2000 do begin if (i >= 1) and (i < 5) then a[i] := 'few'; if (i >= 5) and (i < 10) then a[i] := 'several'; if (i >= 10) and (i < 20) then a[i] := 'pack'; if (i >= 20) and (i < 50) then a[i] := 'lots'; if (i >= 50) and (i < 100) then a[i] := 'horde'; if (i >= 100) and (i < 250) then a[i] := 'throng'; if (i >= 250) and (i < 500) then a[i] := 'swarm'; if (i >= 500) and (i < 1000) then a[i] := 'zounds'; if i >= 1000 then a[i] := 'legion'; end;
readln(i); writeln(a[i]);
end. Edited by author 05.12.2007 18:27 My best is 0.015 104 KB My best 0.001 How do you get 0.001 sec? I'm quite sure there's nothing to improve in my code. I get 0.015 sec using FreePascal. Where do I go wrong?? Как Вы достигаете 0.001 секунды? Я не вижу где можно улучшить код для FreePascal. Есть идеи? var c: array[32..122] of byte; n, i, sum: integer; s: string; begin c[32] := 1; c[33] := 3; c[44] := 2; c[46] := 1; c[121] := 1; c[122] := 2; for i := 97 to 120 do c[i] := (i - 97) mod 3 + 1; readln(s); n := length(s); sum := 0; for i := 1 to n do sum := sum + c[byte(s[i])]; writeln(sum); end. Your memory limits are too tight for 64-bit compilers and using 32-bit Visual C++ instead is not such a good idea because of its weird behavior. Rust releases new version every 6 weeks. Even if this is too frequent please update it at least every half year Test #10 contains some non utf-8 characters. That could be the reason of panic if you use Go or Rust languages. Just pay attention when Conviviality rating < 0. can you be more precise? Thank you! 11 5 4 3 2 7 1 1 1 1 1 1 6 4 7 4 8 4 9 5 10 5 11 5 4 3 5 3 3 2 2 1 0 0 Answer:15 15 Edited by author 02.08.2013 07:51 Edited by author 02.08.2013 08:04 Edited by author 02.08.2013 08:04 Edited by author 02.08.2013 08:04 спасибо тебе, это реально помогло мне I got WA#13 .But my dfs was a little wrong and I got ac after correcting it. I think all of subtrees of the current node should be calculated before the current node is calculated. Edited by author 24.10.2017 20:03 Edited by author 24.10.2017 20:03 floor(x) or round(x) - wa7 (int)x - OK Thank you. It helped me pass WA7 Edited by author 16.01.2022 03:01 Can anybody describe the solution please ? Нужно по индукции показать, что если у нас одна куча из 2*N+1 камней (N>=0),то ходов всегда будет ровно N. А далее игра идёт параллельно в каждой из куч(неважно какое разбиение в каждой из куч,т.к. кол-во ходов одно и тоже). Побеждает первый игрок, если кол-во ходов нечётно, иначе-второй Если я правильно понимаю, то тут нужно применять метод полной математической индукции. Итак, нужно доказать, что 2*N + 1 разыгрывается за N ходов. 1. Базис. При N = 0. В этом случае 1 куча из 1 камня. Чтобы её разыграть нужно 0 ходов. 2. Допустим, для всех n = 1 .. k утверждение верно. Докажем для n = k + 1. 2*(k + 1) + 1 = 2*k + 1 + 2. Эту кучу можно разложить на кучи (1, 1, 2*k+1), т.е. затратить на разбор кучи итого k + 1 ход (1 ход чтобы разложить на (1, 1, 2*k + 1) и k ходов из предоположения индукции на 3-ю кучу). кучу 2*k + 1 + 2 можно разложить и другими способами, т.е. это будет набор (2*k1 + 1, 2*k2 + 1, 2*k3+1), при этом 2*k1 + 1 + 2*k2 + 1 + 2*k3 + 1 = 2*k + 3 => k1 + k2 + k3 = k, т.е. доказали и без того очевидное, что ki < k, т.е. попадает под предположение индукции, кроме того, что после первого хода нам потребуется ещё k ходов и итого будет k+1. куеде. My intuition... First, why not try to reduce the numbers as less as possible? That would seem like playing more turns. Well, for a pile of size n, this would mean making piles 1, 1, n-2, and the first two won't be used anymore so we could say we reduced n by 2. Is this useful? How many times can we do this? Well, floor(n/2) times, or as n is odd, (n-1)/2 times. Now keep this number. Let's try to split into arbitrary sizes, n = n1+n2+n3. The last expression is (n1+n2+n3-1)/2. How many times can we reduce by 2 with the split piles? All of them are odd, so this is (n1-1)/2 + (n2-1)/2 + (n3-1)/2 = (n1+n2+n3-1)/2 - 1. So no matter what we do for splitting, this number is always reduced by 1! And this number essentially measures how many turns we can still play, so that's all, if this number starts odd, Daenerys wins. Edited by author 16.01.2022 02:52 I noticed a lot of people complain about WA2. Just wanted to share my experience, since I got WA2 several times. Don't forget that after you read the number, you haven't read the newline after it. So cin.getchar + cin.ignore and getline(cin, ...) get that exact newline. So we must try to make teams have equal size. Why? Consider two teams with x and y members respectively, and consider x > y. Sending a member from first team to second team will only affect matches between these two teams. At first we have x*y different matches between the teams. If we send a player to the second team, there are now x-1 and y+1 members in each team. The matches are now (x-1)*(y+1) = x*y + (x-y) - 1 As we said x > y, x-y > 0, so x-y-1 >= 0 and our change can't reduce the total number of matches, so it is an optimal change. This also shows that nothing changes when x = y+1, so if we can't make all teams equal size, just add each of the ones remaining into a different team, making a difference of at most 1 in the sizes of teams. Now it's your job to compute the number of matches, I won't show that, but it can be done with a one line formula. Good luck :) I have solved this problem by using an easy greedy algorithm. MAIN: you need to use an idea of 2 pointers(of course you need to sort array) and take the rightest segment. Left part of segment need to be <= x(another pointer) The solution below: void solve() { int m; cin >> m; vector< pair<int, int> > pi; int a, b; cin >> a >> b; while (a || b) { pi.pb({a, b}); cin >> a >> b; } sort(all(pi)); int cnt = 0, j = 0; vector< pair<int, int> > ans; j = 0; int x = 0; for (; j < sz(pi) && x < m; j++) { int k = j; int mx = x; pair<int, int> par = {-INF, -INF}; while (k < sz(pi) && pi[k].ff <= x) { if (mx < pi[k].ss) { mx = pi[k].ss; par = pi[k]; } k++; } if (par.ff == -INF) { cout << "No solution\n"; return; } x = mx; ans.pb(par); if (k > j) j = k - 1; } if (x < m) { cout << "No solution\n"; return; } cout << sz(ans) << '\n'; for (auto &i : ans) { cout << i.ff << ' ' << i.ss << '\n'; } } always choose segments with rightest right points I dont understand why difficulty is 121, i think it's easy problem Not everyone is as super smart as you are, Anton. Us plebeians can barely walk upright, much less understand Western Arabic numerals. Congrats on your good fortune! I had a hard time with this, so hopefully I will save your time. Read input like this: int n; cin >> n; string t; getline(cin, t); // Necessary to process end of first line (nothing after n) .... // Now keep getting each line with getline(cin, t) Hints: 1. No sorting. It's useless. Quiqsort - too much memory, Bublesort - too long time. 2. We just need a number that is more than n/2. It always exists. 3. Read values step by step, remember the 'candidate' answer and counter increase or decrease it. e.g: 3->3 cnt=0+1=1 3->3 cnt=1+1=2 2->3 cnt=2-1=1 2->3 cnt=1-1=0 3->3 cnt=0+1=1 Note 1: e.g. 5 3 3 2 2 6 My program's answer is 6, but such a case never occurs (!). "He knows exactly that more than half banknotes have the same value." Note 2: C# - "Memory limit exceeded 21" use this: if (i % 1000 == 0) GC.Collect(); Regards Edited by author 12.01.2022 20:54 using System; namespace Timus { class Program { static void Main() { string nums = Console.ReadLine(); int a = Convert.ToInt32(nums.Substring(0, 1)); int b = Convert.ToInt32(nums.Substring(2, 1)); int c = a + b; Console.WriteLine(c); } } } #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main () { long long n; while (cin>>n) { cout<<setprecision(4)<<fixed<<sqrt(n)<<endl; } return 0; } Edited by author 12.11.2017 17:07 we have to print in reverse order. ТЫ ПРОСТО ЛОХ Тяжело Edited by author 12.01.2022 09:52 here you have to print the answer in the reverse order. This is my code!!! #include<iostream> #include<string> using namespace std; int main() { char s; int count = 0; while (cin >> s) { if ((s=='a')|| (s=='d')|| (s=='g')|| (s=='j')|| (s=='m')|| (s=='p')|| (s=='s')|| (s=='v')|| (s=='y')|| (s=='.')|| (s==' ')) {count+=1;} if ((s=='b')|| (s=='e')|| (s=='h')|| (s=='k')|| (s=='n')|| (s=='q')|| (s=='t')|| (s=='w')|| (s=='z')|| (s==',')) {count+=2;} if ((s=='c')|| (s=='f')|| (s=='i')|| (s=='l')|| (s=='o')|| (s=='r')|| (s=='u')|| (s=='x')|| (s=='!')) {count+=3;} } cout << count; system("pause"); return 0; } Possibly this part (s==' ')) If anyone is confused about this, note that cin ignores spaces. You should read the line as a whole with getline. string s; getline(cin, s); |
|