Общий форумI think many people can not solve this problem because they do not have enough knowledge. You should know "Problem LCA" and "Segment Tree" that to solve the problem. My algo is O(n*sqrt(n)+m*log(n)), but i can solve for O(n+m*log(n)) (LCA can be solved for O(1) with preprocess or sqrt(n) without preprocess). P.S. What is the optimal asymptotic behavior? Edited by author 20.11.2016 23:27 Edited by author 20.11.2016 23:27 Edited by author 20.11.2016 23:28 Well, there were quite a lot of LCA + segment tree problems by now, so by now people mostly should know what that is :) As for me, i just took my solution to http://acm.timus.ru/problem.aspx?space=1&num=1471 and only had to modify it very slightly. Just, in there you had to operate with only minimums, and here you need to find a minimum in a certain range of your array of minimums, so there's that additional layer of minimums. import java.util.Scanner; public class Sold_Out { public static void main(String[] args){ Scanner scan = new Scanner(System.in);
int n = scan.nextInt(); int k = scan.nextInt();
if(n<3){ System.out.println(0); return; }
System.out.println(Math.max(k - 1, n - k) - 2); } } your programm works only because of weak tests. for example: 3 1 your answer is 0, but the correct one is 1. 1 _ _ 1 _ 3 1 2 3 -> there is 1 person from both sides and the distance to number 2 is equal, so in the worst case the person will hit vasya. Edited by author 13.01.2016 01:14 Edited by author 13.01.2016 01:14 Could anyone give me some sample input and output? Thanks a lot. Nope. The only inscribed rectangle with area=50 doesn't contain hole. Note, that there are only 4 possible rectangles in the solution. Calculates sum of divisors. O(lim * log(lim)). for(int i = 2; i <= lim; ++i){ ++s[i]; for(int j = i + i; j <= lim; j += i) s[j] += i; } Maybe I don't understand it clear, but I think it will get TL. Difficult of this algorithm = O(n^2) No, it's O(n log n). Learn some math. In C++, you'd better use "long long" instead of "long". 4 BBAA BABB = Bob Почему в исходном примере выигрывает Боб? Если при первом сгибе получаем полоску АА, значит должна выиграть Алиса... Почему нет? There is information:"Если после очередного сгиба полоска стала полностью одноцветной".It's mean, both of sides needs to have one color Can members of the director board be subordinates? For example, is 6 a subordinate of 3? Yes, 6 is a subordinate of 1, 2, and 3. Edited by author 19.11.2016 15:45 Для теста 5 5 что нужно вывести 0 2 5 5 или 0 1 5 "An employee can send a memo only to another employee. The route of memo can consist of one employee." So the answer should be 0 1 5. A can't understand what's the problem and why I don't pass it. Help me, please. What's the meaning of the question ? I tried to get it but in vain, even the test unclear for me I'll explain the test. 6 2 5 3 4 1 9 The first one is chosen as current candidate, and has 2 disadvantages. Then, he is compared with 2nd pirate (5 disadvantages), 3rd (3), 4th (4), 5th (1). When comparing with 5th pirate, we see that he has less disadvantages (1) than current candidate (2). So he becomes the current candidate. And then we finally compare him with last pirate (9 disadvantages). In the end, 1st pirate with 2 disadvantages was compared to 2nd, 3rd, 4th, 5th — compared 4 times; 2nd pirate with 5 disadvantages was compared to 1st — compared 1 times; 3rd pirate with 3 disadvantages was compared to 1st — compared 1 times; 4th pirate with 4 disadvantages was compared to 1st — compared 1 times; 5th pirate with 1 disadvantages was compared to 1st, 6th — compared 2 times; 6th pirate with 9 disadvantages was compared to 5th — compared 1 times; Out of all the pirates, the 1st one has the most compare times — 4. Thus, we output 1 — the index of a pirate who was compared most times. But, if several pirates were compared the same amount of times — say, if 5th one was also compared 4 times (if there were 2 more pirates in input) — then both answers "1" or "4" would be correct in this case. Is this any clearer? thanks I want to know what's the task of this problem. There is an interesting way to code it. For each piece we can have a function like this: pair<string, int> get_king(int n, int x0, int y0) { int cnt = 0; for (int dx = -1; dx <= 1; dx++) for (int dy = -1; dy <= 1; dy++) if (dx != 0 || dy != 0) { int x = x0 + dx; int y = y0 + dy; cnt += (x >= 1 && x <= n && y >= 1 && y <= n); } return { "King", cnt }; } In the main code we just do the following loop: for (auto get : { get_king, get_knight, get_bishop, get_rook, get_queen }) { auto res = get(n, x, y); cout << res.first << ": " << res.second << endl; } After that the function for queen look very easy: pair<string, int> get_queen(int n, int x0, int y0) { int cnt = get_rook(n, x0, y0).second + get_bishop(n, x0, y0).second; return { "Queen", cnt }; } If you have any ideas on how to code it better, please write them here :) My tests (N, Array, Answer): [8, '6 7 9 13 18 24 31 50', 0], [5, '5 5 4 3 3', 0], [5, '3 3 4 5 5', 0], [1, '1', 1], [1, '2', 2], [6, '1 4 5 6 7 9', 0], [5, '5 8 13 27 14', 3], [5, '5 4 3 3 3', 0], [5, '11 10 8 7 6', 0], [6, '1 4 5 6 7 9', 0], [6, '9 7 6 5 4 1', 0], [7, '1 2 3 4 5 6 6', 1], [3, '1 1 5', 3], [6, '1 2 3 4 100 100', 0], [5, '5 8 13 14 15', 1], [5, '4 6 6 7 9', 0], [7, '36 25 12 10 8 7 1', 1], [6, '101 51 51 3 2 2', 0], [6, '1 4 5 6 7 9', 0], [4, '1 3 9 27', 14], [6, '6 6 5 4 3 2', 0], [20, '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20', 0] All tests = True. What I do wrong? Edited by author 17.11.2016 19:27 Edited by author 17.11.2016 20:03 What does it mean? For example if K = 10, N = 3, M = 112 correct numbers are 101 102 103 104 105 106 107 108 109 110 111 Is it right? Thanks. Edited by author 17.11.2016 18:22 WA8 - all options are off and <10fps WA12 - "Perfect" when >=60fps, NOT >60fps Tags: geometry *hint hint* using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication8 { class Program { static void Main(string[] args) { int N = Convert.ToInt32(Console.ReadLine()); int A = Convert.ToInt32(Console.ReadLine()); int B = Convert.ToInt32(Console.ReadLine()); if (N >= 1 && 100 >= N) if (A >= 1 && 100 >= A) if (B >= 1 && 100 >= B) { Console.WriteLine(N * A * B * 2); } } } } 1) Here is task fragment: "The only line contains integers...." You are reading 3 lines. 2) if (N) if (A) if (B) {...} - else what? Any difference how exactly your program fail in "else" case? I think you should skip parameters check or fail in some specific way - visible and different from regular mistake. Edited by author 16.11.2016 16:53 |
|