Common BoardМожете дать подсказку? Я понял что количество всех пар всегда три И число дней как посчитать Но не могу подобрать алгоритм чтобы вывести в каком порядке будут солдаты выходить на дежурство 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 36 60 60238766947 689134144379425669 151303190236896619 105037406971508485 68317121395 x=6221392564 Any thoughts whats in test #8? Solution passes all the tests here on forum and a lot of my tests. Just can't figure out what is wrong... #include<iostream> using namespace std; int main() { int a; int b; int c; int d; int h; cin>>a; cin>>b; h=a-1+b; c=h-a; d=h-b; cout<<c; cout<<d; return 0; } You should test your code locally before submitting, this way you will notice that you missed a space! I've simplified your way. use the following, you'll get the result - c = b - 1; d = a - 1; cout<<c<<" "<<d; Edited by author 16.05.2021 03:02 long long mul(long long a,long long n) { long long ret; if(n==0) return 0; ret=mul(a,n/2); ret=(ret+ret)%mod; if(n%2) ret=(ret+a)%mod; return ret; } Edited by author 24.11.2016 05:02 LL product_mod(LL a, LL b, LL mod) { a %= mod; b %= mod; LL result = 0, y = a; while(b) { if(b&1) result = ((result%mod) + y) %mod; y = (y + y)%mod; b = b >> 1; } return result%mod; } This is also known as the Russian peasant method for multiplication. For example, 7x13 13 = (8 + 4 + 1) The product is re-written as 8.7 + 4.7. 1.7 In my code, y keeps track of 7, 2.7. 4.7, 8.7, etc. It gets added to result whenever a bit is set in b. long long c = (__int128_t)a*b%md; he he) Edited by author 14.05.2021 21:34 Edited by author 14.05.2021 21:34 |
|