Common Boardive googled that the answer for all n except 1 is 1 + 1/sin(PI/n), can smb explane me why? Centers of circles form a regular polygon with side length 2. Now, consider the formula to find circumradius of a regular polygon and add 1 because you were connecting circle centres, but not their tangent points to the circle. i also have wa#6 Give some tests or hints to understand logic of calculating Edited by author 01.11.2009 14:30 Try test 31 10 2 This test helped me to receive AC... thx Is the answer "6.00000 8.00000"? What is Test #16? Please someone help! What is Test #16? Please someone help! Same here... got stuck in Test-16 . so why did you get the WA16? Well maybe someone gonna read this but i got WA #16 cause my logic was wrong. i thought that i need to check if i studied any of prerequisite BUT i must check if i studied ALL OF them. maybe my code would help idk #include <iostream> #include <vector> using namespace std; int N, M, a[(int)1e3 + 5], b, c; bool visited[(int)1e3 + 5], flag, ans = true; vector <vector <int> > adj((int)1e3 + 5); int main() { cin >> N >> M; while(M--) cin >> b >> c, adj[c].push_back(b); for(int i = 0; i < N;++i) { cin >> a[i]; flag = true; visited[a[i]] = true; if(adj[a[i]].empty()) continue; for(int j = 0; j < adj[a[i]].size();++j) if(!visited[adj[a[i]][j]]) flag = false; if(!flag) ans = false; } if(!ans) cout <<"NO"; else cout << "YES"; } I have the feeling that this problem can not be solved with less then 9*k+7 rows in the control table(my solution has exactly 9*k+7 rows) but I have not proven it. Has anybody a shorter solution? Edited by author 06.04.2008 23:24 It can be solved using O(log(n) + log(k)) rows. Do it like that: 1) put AA right before # to the left. This is 00 written base 26. 2) go right until you encounter -. Put + there and then go left until you hit #. Increase that number (it will become AB). Then go right again. 3) if you encounter # while walking right, go left and compute coordinate of last - mathematically using cells to the left as memory with base-26 2-digit arithmetics. For arbitrary k and n it will be more than 2 of course, that's why it's O(log(k)+log(n)), but not a constant. 4) like in case of 2 run right/left by putting - instead of + until result becomes zero (decrease it with every - set). 5) Find rightmost - and paint everything to the left with + 6) Find - and stop there Though, I heard in this forum that the checker is wrong as it stops when there are n-1 pluses, but not when invalid state/character pair is met. So, actually you will have to use O(n) states to calculate 'n' and then bring back this value to calculation area inside read/write head :) My solution for each k output 604 lines. How did you do this? My solution uses 1003 lines for each k, and I don't know how to optimize it :( I also came up with 604 lines solution. Just go to the right incrementing the state (200 instructions), then output "X # something_related_to_josephus # <" for X in range [2, 201]. You've spent 400 states. Now your state number should have the information how many steps left you should make outputting '+' -- you will need 199 instructions for this. After that you'll have to add 5 more instructions JOSEPHUS_POINT - LEFT_MODE - < LEFT_MODE - LEFT_MODE + < LEFT_MODE # RIGHT_MODE # > RIGHT_MODE + RIGHT_MODE + > RIGHT_MODE - FINISH - = How is it possible?? Establish 2 4 = 2.6667? 1 2 3 4 1 2 2 (2+2)/2 = 2 I don't understand what you mean there. In fact, the problem asks for an interval [l, r] to find the average cost of a sub-interval. That is, as for the first test case. After two 'change' queries we have cost(1, 2) = 1; cost(2, 3) = 2, cost(3, 4) = 2. Then we are asked for the average on the interval [2, 4] which is (cost(2, 3) + cost(3, 4) + cost(2, 4)) / 3. So, given an interval [l, r] you are asked to compute: int64_t n_of_intervals = 0; int64_t total_sum = 0; for (int i = l; i < r; ++i) for (int j = i + 1; j <= r; ++j) n_of_intervals += 1 total_sum += cost(i, j) output total_sum / n_of_intervals I have got AC with bruteforce. You need only to state larger memory for stack (if you use stack), and perform some little optimization when enumerating. PS: Solution always exists. For n <= 300000, the task could be finished with only 14 (or 15?) colors. BTW: If anyone could provide me a method of construction, I would be very glad to see it. Please paste it here, and let others see. What do you mean under "the method of construction"? For example I solved it using greedy algo. And, as I know, it's very hard to prove that for some fixed n solution doesn't exist. Therefore jury checked a possibility of coloring artists for all n <= MAXN with a help of their own method (maybe, also greedy). According to this time limit and MAXN for this problem were selected. What I said under "the method of construction" means that you have such a method, that you could use some formula or equation to calculate elements at each place DIRECTLY. More precisely, you have a formula for a[n]: a[0] = ... a[1] = ... ... a[n - 1] = ... That is "the method of construction". Many problems in TIMUS could be solved with this kind of method, and I wonder whether this problem could be done too. Hmm, it's very interesting. But I don't know such method. And I guess, such solution doesn't exist for every natural N. Edited by author 08.09.2011 22:00 Edited by author 09.09.2011 11:11 Look at author rating for this problem. There are 0.031 and even 0.015 solutions. I don't think they did bruteforce too. Edited by author 24.11.2011 00:33 Эта задача имеет математическое решение. Нам задан граф на N вершинах, причём степень каждой вершины p (нужно самому понять, откуда берётся p). Требуется покрасить вершины так, чтобы смежные имели разный цвет. Утверждение: покраска возможна <=> цветов >=p+1. Необходимость очевидна. А достаточность реализуется по индукции: пусть мы покрасили k<N вершин, так что смежные имеют разный цвет. Возьмём не покрашенную вершину. Её степень <=p, а цветов >=p+1.Тогда покрасим её в любой из оставшихся цветов. There is a constructive approach that works in O(n). Hint: LCM(1, 2, ..., 13) > 3*10^5. Edited by author 10.09.2019 21:16 Hey guys, how to get run time under 0.02s? I implement O(n) solution, but my time is ~0.15s for CLang... What optimisations do you use? I used fast I/O to get 0.031. There are faster input methods that use fwrite/fread while mine is based on getChar/writeChar. Perhaps using even faster I/O can get you to 0.015 [code deleted] Edited by author 10.09.2019 14:33 Edited by moderator 24.11.2019 13:26 And yes. I got accepted in 0.015s using fread/fwrite IO and C language compiler (not C++) I've tried priority_queue and heap, but still MLE. Here's my code, can somebody help me? #include <iostream> #include <algorithm> #include <vector> int main() { int n, a; std::cin >> n; std::vector<int> v(n / 2 + 1); for (int i = 0; i < n / 2 + 1; ++i) { std::cin >> v[i]; } std::make_heap(v.begin(), v.end()); for (int i = 0; i < (n + 1) / 2 - 1; ++i) { std::cin >> a; v.push_back(a); std::push_heap(v.begin(), v.end()); std::pop_heap(v.begin(), v.end()); v.pop_back(); } std::sort_heap(v.begin(), v.end()); if (n % 2) { std::cout << v.back() << ".0"; } else { a = v.back(); v.pop_back(); std::cout << (0ll + a + v.back()) / 2 << '.'; if ((0ll + a + v.back()) % 2) { std::cout << 5; } else { std::cout << 0; } }
return 0; } It's wrong. Because the last leaf of the max heap is not necessarily minimum but you are removing it (v.pop_back();). Your code may remove the median element. And the sort_heap has no effect. Count numbers bigger than a[i] from 0..i-1 ans smaller than a[i] from i+1..n-1 ans then try to build the answer :) It is around 70 Edited by author 09.09.2019 22:01 [code deleted] Edited by author 08.09.2019 10:26 Edited by moderator 19.11.2019 23:32 Решил с грехом пополам, здесь писать не буду. Остались сомнения, что в условии(в тестах) правильно размер массива подсчитан, этот(SIZE) не катит. OMG, standart interval tree gives TLE 6. It's terrible! Why?! Use Segment Trees with lazy propagation Please, could you send your problem(AC code) Please, could you send your problem(AC code) Edited by author 09.09.2019 23:30 49 3 I mean, FRRR or FLLL or FLFLLF could return us to the base, it also doesn't violate any of two rules: 1. The total number of letters F must not exceed S and 2. the total number of letters L and R must not exceed T are there any more restrictions??? The problem asks: "What is the longest closed path that you can assemble?" Your examples are not closed loops. The first and last squares, although they are neighbours, they don't match their path endings. #include <iostream> using namespace std; int main() {
int n, k; cin >> n >> k; int c = n * k; int *arr = new int[k];
for (int i = 0; i < k; i++) { cin >> arr[i]; c = c - arr[i]; }
cout << abs(c);
} Could anybody help me? I have WA at 4th test! u may try this test: 2 1 2 0 1 0 0 so output should be: 2 0 1 1 2 when WA is 2 1 2 0 1 This test helped me: 4 0 4 -5 0 3 4 -4 4 0 0 Answer is: 1 -4 4 Is the answer : 1 0 4 right? i have wa 4 too,and i am confused about the output principles. This test helped me: 10 -5 1 1 14 -5 2 2 3 3 19 0 0 The answer is: 2 -5 1 1 14 Now, let's fight with WA5 :D why not this: 2 -5 2 1 14 ? Actually, what if there are several possibilites to cover? I think that it does not matter which one you choose, as long as it has a minimum number of intervals. I guess the judge just tests whether the intervals you give cover the large interval. Best regards, Erik Edited by author 25.02.2013 04:56 This test helped me too. At last got AC. My solution is similar to task 1987. Edited by author 05.09.2019 16:47 |
|