|
|
Common Boardinput 5 4 4 2 2 1 1 3 3 4 I think output should "1" but most of my colleagues' accepted programs print "0". Do I misunderstand the problem ? This is not valid input because the graph has to have an even number of edges. Edited by author 10.02.2014 00:44 Use the FFTW (such fast wow) for AC. Thanks, I already got AC with usual FFT (heavily optimized). Could you give some link to FFTW? #include<iostream> #include<conio.h> #include<Math.h> using namespace std; int main() { long long int a[ 100000 ]; int i = 0; do { cin>>a[ i ]; i ++; }while( a[ i - 1 ] != EOF ); for( int j = i - 1; j > -1; j -- ) { if( a[ j ] >= 0 ) cout<<sqrt((double)a[ j ])<<endl; } } I don't know what is the fastest way to solve this, but I think mine is more complicated than it can be. I've keeped a vector for each remainder i mod k and i*i mod k, to quickly find the numbers which give remainder r. Then you can add edge by edge in graph and use union-find algo to check for cycles. Maybe there is a faster math solution? Yep, graph is very sparse. Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k). For each number in [1..n] try to find cycle with previous ones. Use e.g. disjoint sets for simplicity. Note, that solution always exists! Almost always (without several trivial cases) you can consider only range [0..2*k]. To avoid any kinds of checking simply get n = max(10, 2*k). Is there any mathematical proof for this? if k=1 =>ans is 3 if k=2 =>ans is 5 if k>2 => you can take numbers 1, k-1, 2*k-1, and it will be a cycle 3 2 11110001 11110001 11110000 11110000 11110000 If you alter one bit, it will become 11110000 11110000 11110001 So how the answer is 1 2? Shouldn't it be 1 1? Or we have to alter only the first byte? What you suggest changes 2 bits and you want the replacement with minimal number of bits ("And if it is, find the minimum number of bits to alter."). Edited by author 26.10.2013 17:33 Edited by author 26.10.2013 17:36 I have 3 different understandings of the target value: 1. Whole number of bits in all bytes to be changed to make bit substrings equal (any bit(s) of each byte can be changed); 2. The same as p. 1, but only last consecutive bits of byte (suffix) can be changed; 3. The number from the 0..8 range which is the minimum number of bits that can be changed in all bytes. Tests do not clarify this. Which one is right? It's allowed to change only last bit in every byte. image: 00000010 00000001 secret: 00000000 00000011 can they match? Use the FFTW for AC. Edited by author 02.08.2014 17:59 RT At least, it can be written as linear programming problem. However, it is INTEGER linear programming problem, which still remains to be NP-hard. can we use simplex() to solve floating version of lp, then use it as heuristics: brute force to search in descending order of veriable x.. I will try this approach to test case 70(toooooooooooooo hard....) I have AC in O(1), I use 2 formulas for odd and even n. Good problem, thanks to author! Now I combining both formulas in one. In my programme, I use 1000 000 random locations to check if the points are in the circle. At first, I wrote something like this: "double tx = ( double )( rand() % 101 ) / 100.0 ";(because: 0 ≤ x ≤ 1, -> rand() % 101 ∈[ 0, 100 ] );and just got WA...... Finally I changed the 101 into 100 and got AC; Can anyone tell me why 101 is incorrect? or it is actually right? You're just lucky that in the second case you got AC - actually good tests will kill your second solution as well, because what you generate is random point on integer grid 100 x 100 and this is far from random real point. Good way of generating random point in unit square is doing double(rand()) / RAND_MAX for both coordinates - this will give you point close enough to truly random. Thanks for your reply, I realize I have mixed up continuity and dispersion. :-) Please, give me a more test with answer. Please help me! Got the WA#32 with the next code. #include <iostream> #include <math.h> using namespace std; int main() { int a,b,c,i,j,x=0, f=0, count=0;
cin>>a; long long int mass[a]; for(i=0;i<a;i++) cin>>mass[i]; cin>>b; long long int mass1[b]; for(i=0;i<b;i++) cin>>mass1[i]; cin>>c; long long int mass2[c]; for(i=0;i<c;i++) cin>>mass2[i];
int y = min(min(a,b), min(b,c));
long long int mass3[y]; for(int u=0; u<y; u++) mass3[u]=-1;
long long int mass4[y]; for(int u=0; u<y; u++) mass4[u]=-1;
for(i=0;i<a;i++) { for(j=0;j<b;j++) { if(mass[i]==mass1[j]) { mass3[x]=mass[i]; x++; } } } for(i=0;i<c;i++) { for(j=0;j<c;j++) { if(mass1[i]==mass2[j]) { mass4[f]=mass1[i]; f++; } } } for(i=0;i<y;i++) { for(j=0;j<y;j++) { if(mass3[i]==mass4[j]&& mass3[i]!=-1 &&mass4[j]!=-1) count++; } } cout<<count; return 0;
} 1 1 0 ==== Yes 1 1 1 ==== Yes 3 1 1 1 0 ==== Yes 3 1 0 0 0 ==== Yes 2 2 0 0 0 0 ==== Yes 2 2 1 0 0 1 ==== Yes 3 3 1 1 1 1 0 1 1 1 1 ==== No 3 3 1 1 1 1 1 1 1 1 1 ==== Yes 3 3 1 0 1 0 1 0 1 0 1 ==== Yes 4 2 1 1 0 0 0 0 1 1 ==== Yes 4 2 1 1 1 0 0 1 1 1 ==== No 4 4 1 0 0 1 0 1 1 0 1 0 0 1 0 1 1 0 ==== Yes 4 4 1 1 1 1 0 0 0 0 1 0 1 1 0 1 0 0 ==== Yes 4 4 1 0 1 0 0 1 0 1 1 0 1 0 0 1 0 1 ==== Yes 4 2 1 1 0 1 1 1 1 1 ==== No You probably get WA#2 because your "for" goes untill 15001. Like this: for (i = 7; i < 15001; i++). Actually amount of prime numbers when i == 15001 is nearly about 2500. You need to make a counter of prime numbers and generate primes while (count <= 15001). Then your programm will be AC! Please add this test (if it is not already here and if it is not too hard): 100 133 1 2 1 1 34 300 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 1 11 12 1 12 13 1 13 14 1 14 15 1 15 16 1 16 17 1 17 18 1 18 19 1 19 20 1 20 21 1 21 22 1 22 23 1 23 24 1 24 25 1 25 26 1 26 27 1 27 28 1 28 29 1 29 30 1 30 31 1 31 32 1 32 33 1 33 34 1 34 36 300 34 35 1 35 36 1 36 37 1 36 38 150 37 38 1 38 39 1 38 40 75 39 40 1 40 41 1 40 42 38 41 42 1 42 43 1 42 44 19 43 44 1 44 45 1 44 46 10 45 46 1 46 48 5 46 47 1 47 48 1 48 50 3 48 49 1 49 50 1 50 52 2 50 51 1 51 52 1 52 54 1 52 53 1 53 54 1 54 55 1 54 56 1 55 56 1 56 57 1 56 58 1 57 58 1 58 60 1 58 59 1 59 60 1 60 62 1 60 61 1 61 62 1 62 64 1 62 63 1 63 64 1 64 65 1 64 66 1 65 66 1 66 67 1 66 68 1 67 68 1 68 70 1 68 69 1 69 70 1 70 72 1 70 71 1 71 72 1 72 74 1 72 73 1 73 74 1 74 76 1 74 75 1 75 76 1 76 77 1 76 78 1 77 78 1 78 79 1 78 80 1 79 80 1 80 82 1 80 81 1 81 82 1 82 84 1 82 83 1 83 84 1 84 86 1 84 85 1 85 86 1 86 87 1 86 88 1 87 88 1 88 89 1 88 90 1 89 90 1 90 91 1 90 92 1 91 92 1 92 93 1 92 94 1 93 94 1 94 96 1 94 95 1 95 96 1 96 98 1 96 97 1 97 98 1 98 99 1 98 100 300 99 100 1 repeated 5 times. One of my AC submissions works 0.8 seconds locally on this test, but works 0.187 seconds max on judge. Even though my computer is slower than judge, it still looks like a big difference. существует ли способ записи данных в массив без использования строк?? А причем тут строка и массив в принцепи? Берем и записываем в нужный индекс считанное число. // В случае C++ #include <iostream> #include <vector> int main() { int n; int start1, start2; std::vector<int> v; std::cin >> n; v.resize(n); for (size_t i = 0; i < n; i++) std::cin >> v[i]; std::cin >> start1 >> start2; // Решение return 0; } Edited by author 29.07.2014 22:22 |
|
|