Общий форумMy solution is fast! valery@uni.lg.ua Ha! My solution: only 0.001 sec and 70 Kb! And it's normal solution (no cheating). I sent it some minutes ago. PS: It's very good that your solution works fast but Always there is better one :) Ha-Ha! My solution works sometimes too 0.001, but how many iterations of your cycle on N=500? Ha-ha-ha! My solution is O(n^2) but I know O(sqrt(n)*n) one. My solution is O(1) :) sorry to bother u on such an old post...but can u help me on a better approach to this question my solution is O(0) :) Jokes on you! My solution is O(-∞) So, your solution travels back in time or make the time in the Universe acting backwards?:) Why is here the runtime error on the 6 test? What test is 6? #include <iostream> #include <cmath> using namespace std; void ghjkl(long double p) {cout << fixed; cout.precision(4); cout << p << endl;} int main() { long double a[1000]={-1.0}; long long i=0; while(cin) {cin >> a[i]; i++;} i=i-2; long double b[1000]; for(int k=0; k<1000; k++) {b[k]=sqrt(a[k]);} for(int m=i; m>=0; m--) {ghjkl(b[m]);} return 0; } Edited by author 24.03.2021 16:53 Edited by author 24.03.2021 16:54 i don't know Edited by author 31.03.2021 19:27 Edited by author 31.03.2021 19:27 Edited by author 31.03.2021 19:27 Oh, I have understood. The array isn't the needed collection for this task. Stack is better. #include <iostream> #include <stack> #include <cmath> using namespace std; int main() { stack<double> a; double b; int c=0; while(cin) {cin >> b; a.push(b); c++;} c-=1; a.pop(); for(int i=0; i<c; i++) {cout << fixed; cout.precision(4); cout << sqrt(a.top()) << endl; a.pop();} return 0; } Edited by author 10.06.2021 03:35 Or you can use deque: #include <iostream> #include <queue> #include <cmath> using namespace std; int main() { deque<double> a; double b; int c=0; while(cin) {cin >> b; a.push_back(b); c++;} c-=1; a.pop_back(); for(int i=0; i<c; i++) {cout << fixed; cout.precision(4); cout << sqrt(a.back()) << endl; a.pop_back();} return 0; } Hi, Well it took me a while to figure out as to how to approach this problem but as it turned out it is pretty straightforward. I divided the problem into two parts. First I printed out the elements up until the middle diagonal. And then the elements after that. Here is the format of the numbers for 4 X 4 array 0,0 0,1 0,2 0,3 1,0 1,1 1,2 1,3 2,0 2,1 2,2 2,3 3,0 3,1 3,2 3,3 We can see a pattern here. First print the element 0,0. Then -> 1,0 to 0,1 (i = 1 to i = 0 and j = 0 to j = 1) Then -> 2,0 to 0,2 (i = 2 to i = 0 and j = 0 to j = 2) Then -> 3,0 to 0,3 (i = 3 to i = 0 and j = 0 to j = 3) So, basically as we are heading towards the main diagonal, we are increasing the value of i and at the same time running j from 0 to i. Implementing this will get you the first 10 out of 16. For the rest of them, we have the same pattern again but this time its reverse Then -> 3,1 to 1,3 (i = 3 to i = 1 and j = 1 to j = 3) Then -> 3,2 to 2,3 (i = 3 to i = 2 and j = 2 to j = 3) Then the last element 3,3 So, this just requires some clever manipulation of the for loops or while loops. In order to achieve absolute safety providing electricity to the camps, besides an electric supplying system, the host organization set up a path from a reserved electricity generator (which is placed in one of the camps) to every camp once, this means that, thare is only and only one path from Pi camp to Pj camp. The answer should be a path (successive line segments) NOT a tree (minimal spanning tree) NOT a Steiner tree (minimal spanning tree with additional points) Можете дать подсказку? Я понял что количество всех пар всегда три И число дней как посчитать Но не могу подобрать алгоритм чтобы вывести в каком порядке будут солдаты выходить на дежурство Edited by author 02.06.2021 13:24 Hint: Binary search!! Solution: This is a pretty easy binary search problem. All we need is to check for every number of the second list(as first list is sorted in ascending order) let's denote as x, if we can find y = 10000-x in the first list. If we find y for any x(from the 2nd list) then we will print "YES". Because we already got a pair x, y for which x + y = 10000. So, the complexity is NlogN(as we are doing binary search for every element of a list in the worst case). [Code was deleted] Edited by moderator 06.06.2021 03:06 Binary search is not needed here. It is enough to traverse the array with two pointers. WA on test 2 don't know why :( Edited by author 01.07.2016 14:09 Edited by author 01.07.2016 14:09 Edited by author 01.07.2016 14:09 Edited by author 01.07.2016 14:10 i keep having the same problem and i don't know why.Did you find out? It's 2021 now, so... have you found out the problem? :) We want to use segment tree, but we need to know how express some segment in order to preserve validity of multiplication and order calculation. I noticed any segment can be expressed by just 2 integers. I cannot proof this, my math background is not good here. Multiplication is trivial. Now we need ability to merge 2 segments (expressed by 1-2 integers) and get 2 another integers. I spent tens of hours thinking on this, but cannot come up with correct merge algorithm. Tried this: merge(x1, x2, x3, x4): if exists such i,j,k: where x[i]*x[j]%p=x[k], then we can remove x[k] if we preserve order else try to set x[i] = x[i]*x[j]%p for some random i,j repeat My merge procedure is not correct. Am I heading in the right direction?
I don't remember the problem quite well, but I think the main data structures you need in this problem are those that query for sum of segment and gcd on segment; maybe lcm. There are several approaches, some of which use discrete logarithm while others don't. In any case you would need some optimizations. I'm not sure what you are trying to do, so sorry if my comment is misleading and is stopping you from coming up with your own original solution. I already stuck with my solutions at least 5 times, it's ok, I need fresh ideas :) One of my first ideas was with segment tree and LCM. 1) We calculate order for every element. 2) It is easy to combine 2 segments. order(combined) = LCM(order(segment1), order(segment2)) 3) But it hard to do multiplication. If we multiply by m, we cannot just do order=LCM(order(m), order(segment)). Counterexample: p=17 segment=[2] order(segment)=8 m=2 after multiplication segment=[4] order(segment)=4 4 != LCM(order(2), order(segment)) = 8 I am trying to find a way how to express segment of any length in a short way (lets call it segment_data), so it has next properties: 1) I can calculate order quickly 2) I can create multiplication procedure over segment_data 3) Multiplication over segment_data leads to the same order as multiplication over raw segment 4) I can combine 2 segment_data into 1 (so I can build segment tree) If segment_data is just order of a segment, I cannot make it work (example above). Property 3 is not working. My last idea was to use segment_data = array of 2 elements (I understand I was not very clear in first post, it is confusing even for me). I found next: there are group of segments, that behaves exactly the same for our task. I mean, if: for any i in (1..p-1): order(i * segment1) = order(i * segment2) Then we can replace segment1 with segment2, and nothing changes for our task. I generated groups of such segments for different p. Example: p=17 [6,7,10,12] can be replaced with [3,6] after multiplication by 1..p-1, they lead to the same picture of orders: [16 16 8 16 8 8 8 16 16 8 8 8 16 8 16 16] [6,7,10,11] can be replaced with [6,7], picture [16 16 4 16 4 8 8 16 16 8 8 4 16 4 16 16] When I was investigating behavior of similar segments, I noticed segment of any length can be replaced with segment of length 2. And it will have the same properties. The plan was to have 2 numbers as nodes of segment tree. But I stuck with combining procedure. Edited by author 29.05.2021 18:42 My accepted program 9380769 fails on the test: 1 3 100 1.1 3 why wrong answer? #include"iostream" int main() {
int banki=10; int Garry,Larry; std::cin>>Garry>>Larry; std::cout<<banki-Garry<<" "<<banki-Larry; return 0; } because its wrong - int banki=10 Why this solution is wrong? #include <iostream> using namespace std; int main() { int herry; int larry; int all; cin >> herry; cin >> larry; all=herry+larry-1; herry=all-larry; larry=all-herry; cout << herry << " " << larry; return 0; } Edited by author 03.07.2013 01:45 =) Do you know math? Code: all=herry+larry-1; herry=all-larry; larry=all-herry; Math: all=herry+larry-1; herry=all-larry=herry+larry-1-larry=herry-1; larry=all-herry=herry+larry-1-(herry-1)=larry; Edited by author 25.09.2013 18:28 actually the twist is in the number of total canes. Edited by author 26.05.2021 02:53 Edited by author 26.05.2021 02:53 I spent 3 hours on it.But I find it is expected to use "short" at last!!! I use Segment tree.I can't find anything wrong in my code.Why? I always get a wrong answer on test 11,who can help me? This small test helped me to move from WA on test 11 to AC. 3 4 3 2 1 3 2 1 1 2 ans: 1 #include<iostream> int main() { int32_t a,c=0,c1=0,d=0; std::cin>>a; int32_t b[a]; for(int g=0;g<a;g++){ std::cin>>b[g]; } for(int g=1;g<a-1;g++){ c=b[g-1]+b[g]+b[g+1]; if(c>c1) {c1=c;d=g+1;} } std::cout<<c1<<" "<<d; } У меня код не выдает ошибок на моем Кодеблоке, тут же выдает следующее: solution(6): error C2131: expression did not evaluate to a constant solution(6): note: failure was caused by a read of a variable outside its lifetime solution(6): note: see usage of 'a' solution(8): warning C4552: '>>': result of expression not used Дело в том, что запись "int32_t b[a];" не стоит использовать, когда в квадратных скобках стоит переменная, которая вводится с клавиатуры (не является константой). Для этого нужно использовать запись "int32_t* b= new int32_t [a];", попробуйте заменить в шестой строке. #include <iostream> using namespace std; int main() { int count; cin >> count; while (count--) { char x, y; cin >> x >> y; float a = (x - 'a') - 3.5; float b = (y - '1') - 3.5; cout << trunc(1.143 * trunc(1.2 * (6 - trunc((a * a + b * b) * 0.2f)))) << endl; } } #include <iostream> using namespace std; int main() { int count; cin >> count; while (count--) { char x, y; cin >> x >> y; float a = abs(abs((x - 'a') - 3.5) - 1.0) - 0.5; float b = abs(abs((y - '1') - 3.5) - 1.0) - 0.5; cout << trunc(1.143 * trunc(1.2 * (6-a-b))) << endl; } } I set the length of my array to 15 then got WA at #14 while I set16 then I got AC But I dont know why,could anyone help me? 10 4 2 1 2 8 10 answer: 0 11 6 3 1 2 10 11 5 7 answer: 2 Edited by author 06.03.2021 15:54 Test: 6 5 1 2 4 3 2 9 2 4 4 1 Ans: IMPOSSIBLE Thank you very mutch!!! It's very helpfull if somebody get WA7. (We just cann't paint this graph on 2 colors. ) A very good test, thanks. I had WA7 and now I have AC, using this one |
|