Common BoardIt's very easy to get but how to prove it? Edited by author 08.08.2012 02:32 Warning: spoilers. Don't read if you have not solved problem. ------------------------------------------------------------ Well, I can't prove that there always exists path with such length, but I can prove that every path has at least such length. Obviously, we need to prove that there is always at least (n + m + 1) diagonal moves. Let cell be black if both it coordinates are not divisible by two and white otherwise. There are (n+1)(m+1)/4 black squares. Let f be amount of white cells we have visited plus amount of diagonal moves we have made. We start our movement from some black point. When we start f is zero. Assume we are now in black point. Lemma To reach another black points we need to increase f by at least 3. Proof: 10101 00000 10X01 00000 10101 (X is our cell, 0's are while squares, 1 are black). It's obvious, that if don't do diagonal moves at all, we need to visit at least 3 white squares. If we do at least 2, then we visit at least one white square, 2 + 1 = 3. If we do exactly 1, then if it is first move, then we can't leave white squares with second non-diagonal move. If first move is non-diagonal, then second diagonal can't help. So in that case it's true too. So we have proved lemma. Now, f is amount of diagonal moves plus nm - (n+1)(m+1)/4. From the other side f >= 3(n+1)(m+1)/4 because of lemma. So (amount of diagonal moves) >= 4(n+1)(m+1)/4 - nm = n + m + 1. Sorry for my bad English and possible bad explanation. Spoilers End -------------------- x first or y first matters!!! Edited by author 06.07.2014 16:48 how can I use #include <iostream > if it doesn't work? - Edited by author 05.07.2014 22:48 if you stuck on WA#17, try enlarging your array size ^_< 5 6 4 1 1 1 V 6 1 1 H 1 5 2 H 5 5 2 H 1 ans: 10 test 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 test 5 5 0 2 2 2 2 2 0 4 8 4 2 4 0 4 8 2 8 4 0 4 2 4 8 4 0 What is in test #35????? ;) Edited by author 18.10.2011 01:30 It was enough 5 tests for me. In first algo I used double and couldn't fly over test 5. Based on my fail on 5 test I remade algo radically, excluded doubles and got Ac 0.078. So, 5 tests are enough for debugging. Did you use __int64 or long arithmetic??? 4 0 550934784 999950884 449016100 550934784 0 449016100 999950884 999950884 449016100 0 550934784 449016100 999950884 550934784 0 Edited by author 19.10.2011 01:00 If d=a^2+b^2 and d<=10^9=> a,b<=32000 that short int is enough. Also brute force(main clue for integers) for solving triangle in int coordinates. 4 0 550934784 999950884 449016100 550934784 0 449016100 999950884 999950884 449016100 0 550934784 449016100 999950884 550934784 0 0 0 0 23472 -21190 23472 -21190 0 Edited by author 21.10.2011 00:44 @Vavan: What did you do between WA8 and WA35? Thanks. Edited by author 21.10.2011 19:56 if you have WA8, it will very likely caused by an invalid enumeration on brute force of triangle in whole numbers. for x**2+y**2 x = 0, y = floor(sqrt(D)) downto floor(sqrt(D / 2)) you should firstly to increase x, rather than y. I'm not sure I understand what you mean. Currently I enumerate the pairs (i, j) with for (i = 0; i * i <= n; i++) { j = (int) sqrtl(n - i * i); if (i <= j && j * j + i * i == n) { ... valid (i, j) pair... } } it shuld be faster signed x = 0; signed M = SQRT(D / 2); for (signed y = SQRT(D); y >= M; y--) { unsigned Y = y * y; while (x * x + Y < D) { x++; } if (x * x + Y == D) { // valid (x, y) } } Edited by author 21.10.2011 23:43 Well I also do a loop from 1 to sqrt() but without the while so I don't think that's faster. Anyway not the speed is the problem. I put a while(1); if some point exceeds 10^6 and if a D[i][j] value is incorrect so that a TLE should occur in these cases. I made a generator of tests and all looks OK. But WA #8... Any suggestions, tricky tests? Thanks Edited by author 24.10.2011 19:57 I found my mistake. I was computing the first 3 points then thought the rest of them are uniquely determined. But this is false, for example if the first N-2 points are collinear, than the N-1 one could be, by symmetry, on two locations. By ignoring one of those solutions for N-1, the N-th point may not be determined and assume the current input is impossible to solve. Now I did a sort of backtracking with all solutions for each point but obviously got TLE 39. So work in progress :) PS: I've read in some other topic about writing the sqrt in assembly but I don't think that's the way of solving this problem :) Edited by author 24.10.2011 23:30 AC, woo-hoo! Indeed, if the points 0..i-1 are fixed and collinear, the solution for the rest of the points is not unique because we have an axis of symmetry. Otherwise, if at least 3 points are non-collinear, the solution is unique. Edited by author 27.10.2011 21:09 I got wa32 and fixed to the test: 5 0 4 36 5 2 4 0 16 5 2 36 16 0 29 26 5 5 29 0 9 2 2 26 9 0 0 0 0 2 0 6 2 1 -1 1 and more: 5 0 4 25 16 100 4 0 9 36 64 25 9 0 81 25 16 36 81 0 196 100 64 25 196 0 0 0 0 2 0 5 0 -4 0 10 Edited by author 01.05.2016 01:52 test 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 test 5 5 0 2 2 2 2 2 0 4 8 4 2 4 0 4 8 2 8 4 0 4 2 4 8 4 0 answers: test 4 0 0 0 0 0 0 0 0 0 0 test 5 0 0 1 1 -1 1 -1 -1 1 -1 Edited by author 21.10.2011 00:44 Please somebody help me, and give some tests, please! WA#9 is because of integer overflow Is it possible to solve this problem using SQRT-decomposition ? 0.5 second is a very tight limit and in-spite of minor optimizations and fast I/O my code having complexity of O (N * sqrt (N)) is getting TLE on test case 17. I am just curious about the possibility. It is actually a very tough problem when you're using a segments tree, so I do not think that using a SQRT-decomposition is a very good idea. For me the key was to implement the segments tree with iterative update procedure. When I run this code I get the right answer, why do I fail test #2 import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class EJ1880 { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub File Arc = new File("C:\\Documents and Settings\\Admin\\workspace\\ACM\\src\\timus\\datos.txt"); Scanner in = new Scanner(Arc); //Scanner in = new Scanner(System.in); ArrayList<Integer> L1 = new ArrayList<Integer>(); ArrayList<Integer> B1 = new ArrayList<Integer>();
//Cargar elementos int a = in.nextInt(); for (int aux = 0; aux < a; aux++) L1.add(in.nextInt()); int b = in.nextInt(); for (int aux = 0; aux < b; aux++) L1.add(in.nextInt()); int c = in.nextInt(); for (int aux = 0; aux < c; aux++) L1.add(in.nextInt());
//Ordenar elementos Collections.sort(L1); //Buscar cantidad de elementos repetidos for (int i = 0; i < L1.size(); i++) { if ((Collections.frequency(L1, L1.get(i)) > 1)) { B1.add(i); } } System.out.println(L1.size() - B1.size()); } } You are using frequency for occurrence greater than 1, why not use equal to 3 ? Also B1 will contain repeated elements, instead try to use HashSet. 1. If you read some discussion, you may have found out, that there is `simple` algo solution, which just does A^M, and sums all final states counts (here A - is transition matrix of automaton built by `bad words`) Yes, it is cool, algorithmic, etc. But personally I've completely forgotten the 1st year of university, and after reading that I felt little shame, which results in not willing to implement that. 2. DP This is one of hardest DP I've ever thought about. It took me for almost 3 weeks of `background-thinking`. Although, when you came to the function, which is `DP-able` - code looks small, etc. But still, the function is hard to come to. Personally, i felt pure happiness after got my DP ACed. Actually I'm writing this post affected by this happiness :) Like in school :) Wish u the same when u solve it! I'd rate it as `one of the hardest problem` in this volume, if there was only DP solution and no automaton analogy. If someone can invent similar problem, but without automaton solution - would be very cool! I don't know why I got wa on 17,is there any tests??Please help me, it drives me crazy for 4 hours/ My program gives correct answers for all the tests, but has WA#3. Swap(x,y) doesn't help :( Give me, please, some unusual tests lock1 = input() lock2 = input() if lock1 % 2 == 0 or lock2 % 1 == 1: print "yes" else: print "no" I got WA in testcase 3. Why could that be? Edited by author 21.06.2014 17:45 Same error for me. Don't know the problem man. :( hi, if we want to use cin in C++ how we can use it like below for scanf while( scanf( "%lf", &m ) != EOF ) can we edit while( cin >> m != EOF )??? cin >> m; while ( m != EOF ) { //something cin >> m; } Why does it state: "... White draughts, that reached the eighth horizontal, as well as black draughts, that reached the first horizontal, are considered as draughts anyway, i.e. there are no kings here. ..." but then in the sample the white piece makes both forward and backward jumps? Perhaps it should say that all draughts move like kings. A hint for WA #13... make sure that your parser can parse everything that your program can output. for WA#8 check this test 12 9 10 6 7 8 3 4 5 2 4 4 4 answer is 3 They should be pairwise different. Whatever, this test help me. 1. Problem model is not clear: whether train from station 1, after reaching station N, continues then moving in the opposite direction (station N -> station 1), or "disappears" after? 2. Another bug in statement: "You may assume that train stops at each station are instant." and "it takes one second to board a train". How these two statements relate to each other? If train stop is instant, how tourist can board it the whole 1 second??? Answers: 1. No, it "disappears" (which is very different from the real world) 2. This stupid statement is just to show that the tourist should stay on the station during 1 minute, i.e. he cannot leave on the same train he reached the station with Edited by author 01.07.2014 00:38 // 严格按照题目来 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <algorithm> using namespace std; const int p = 10000; double xs, ys; int x, y, ans; int main(void) { scanf ("%lf%lf", &xs, &ys); ans = 1, x = y = 0; // 严格按照题目来 (more than ... ; less than ... ) ys -= 1E-10, xs += 1E-10; while (x == y) ans++, x = int (ans * xs) / 100, y = int (ans * (ys)) / 100; printf ("%d", ans); return 0; }
想知道为什么ys是减1E-10,而xs是加1E-10! 想知道为什么ys是减1E-10,而xs是加1E-10! because it said "more than P%" and "less than Q%", so it can't be equal, you have to shorten interval, just add or sub 1E-10 (因为题目是说“more than P%” 和 “less than Q%”,因此不能相等,所以两边的区间都要往里面再缩小一点,只要加或减1E-10就行) |
|