Общий форумThanks!!! Had the same problem at the beginning, but finally solved it. Good test that helped me to find a bug in my algorithm was: 3 6 2 1 5 When the solution is: 2 (not 3) 2 5 1 Edited by author 24.03.2014 16:32 Edited by author 24.03.2014 16:33 Why two? need to output the maximum amount of trips of the elevator. I dont understand it. var a:array [1..200000] of int64; n,i: integer; begin {$IFNDEF ONLINE_JUDGE} {$ENDIF} while not seekeof do begin inc(i); read(a[i]); end; for n:=i downto 1 do begin writeln(sqrt(a[n]):4:4); end; {$IFNDEF ONLINE_JUDGE} {$ENDIF} end. See on hint in author of the problem. One more hint: Use wiki if you know nothing about Mr. Pierre Edited by author 22.03.2016 02:06 #include<stdio.h> int main() {float n,k,count=0; float m; int i=1; scanf("%f %f\n",&n,&k); n=n-1; while(n>0) {n=n-i; count++; i=i*2; if(i>=k) {m=n/k; i=m; if((m-i)>0) count=count+i+1; else count=count+i; n=0; } } i=count; printf("%d",i); return 0; } Is there any better solution? No. This is the lower bound, since you have to read the edges anyways. I know that this problem could be solved using sorting and something like that - my friends do so but don't share code, I don't know how. I used brute force (= the easiest way) and i got AC 0.281 330 KB at C++ You can use structure Heap or Interval Tree ( because the value of the elements is rather small ). Heap : O(NlogM) Interval tree : O(N log(Max_Value) ). Interval tree also can give you the k-th smallest value in log (Max_value). I know that this problem could be solved using sorting and something like that - my friends do so but don't share code, I don't know how. I used brute force (= the easiest way) and i got AC 0.281 330 KB at C++ Yes... and with little bit of optimization, one can get AC in half of that time... :) Edited by author 20.03.2016 19:06I implemented that but I have WA 5. What's in this test? I don't know, maybe double check if your numbers are exactly in range of [a, b]? And if they're long, not int? I implemented it too, but still have WA 27... Please, help me found a bug... What's wrong here: -- Thanks in advance. Edited by author 19.03.2016 19:43 Edited by author 20.03.2016 15:53 For max test, your answer ends in 3. But it's actually 8. Can you give the right answer on that test? Uh, i just did? I guess i didn't make it clear enough. Anyways, there you go. 2 1000000000000 999999921288 UPD: it's fine, and congrats~ Edited by author 20.03.2016 16:06 Sorry for bother, I just wanted to clarify. :) Now I corrected a mistake and got AC. input 1: 1 2 0 1 10 10 output 1: 10 5 input 2: 1 2 1 0 10 10 output 2: 5 10 input 3: 1 2 0 0 10 10 output 3: 10 10 Edited by author 17.12.2015 10:39 Thank you And it's really strange that in these three cases if I output 0 5 5 0 0 0 I will get a WA...., if I output the another answers I will get AC... why? What is number N = ? and what to output? My program uses only 850K of memory!!! Two days of troubles and the best solution was written! If you are intrested in it leave your mail here. I've solved this problem via interval tree, but it uses 4 Mbytes. I don't need your code, but could you explain your algorithm? My e-mail is dimanyes@yahoo.com I think, that he have used Fenwick tree No :) This solution uses Cartesian tree. My best solution which uses Fenwick's tree uses about 1400K of memory PS: Good luck on the ROI, Ilya :) Can you say book's names where these tree are described? I've modified this solution... Now it uses only 630K of memory!!! (Random Trees are very useful :) can i do it without trees ? like this #include<iostream> #include<string> using namespace std; void limit_to_two_num(float &price) { price=price*100; price=static_cast<int>(price); price=(price)/100; } void main() { int check=0,quantity,length=0; string str="\0"; float price; float profit=0; float arr[100000]; while(str!="QUIT" && check!=100000) { cin>>str; if(str=="BID") { cin>>price; limit_to_two_num(price); arr[length++]=price; check++; } else if(str=="DEL") { cin>>price; limit_to_two_num(price); for(int i=0;i<length;i++) { if(arr[i]==price) { for(int j=i;j<length-1;j++) { arr[j]=arr[j+1]; } length--; break; } } check++; } else if(str=="SALE") { cin>>price; limit_to_two_num(price); cin>>quantity; for(int i=0;i<length;i++) { if(arr[i]>=price) { profit=profit+0.01; } } } } cout<<"Total profit: "<<profit<<endl; } i can't solve this problem.Please help... yu1178209138@hotmail.com window | ******| window window?|****|window? The distance between window and last chairs is 1 chair but it's there! Windows can be only in Business and Econom cause these parts are in different decks. Edited by author 22.03.2016 20:56 Edited by author 22.03.2016 20:56 Можете обьяснить пожалуйста что я делаю не так? Я ходил по обсуждению задачи пробывал тесты которые предлагают, результаты вроде бы как правильные. Может я неправильно организовал ввод/вывод данных? Работает как-то так. Считываю в 1 строку: 6 1 4 5 6 7 9 Очищаю консоль и вывожу Console.WriteLine ответ: 0 There are 2 (TWO) lines in the sample. First contains count of stones, second contains stones weights. Your test should look like: --- 6 1 4 5 6 7 9 --- By the way some languages (C scanf/C++ iostream/Java scanners) allow reading from input without checking how data items are placed on input lines. Here - http://acm.timus.ru/help.aspx?topic=csharp - input read in similar way via string[] input = Console.In.ReadToEnd().Split( new char[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries); spot check shows me that it should be 7 am i right? then the answer is 8 moves?? EGGS=2, FLOORS=20 (20 eggs, initial step = 7) e=20(20) 7 14 17 18 19 e=19(20) 7 14 17 18 19 (+7, +3) ...(e=18..14 ) e=13(20) 7 14 8 9 10 11 12 13 [7 moves] (20 eggs, initial step = 7) (20 eggs, initial step = 6) e=5(20) 6 1 2 3 4 5 e=17(20) 6 12 18 13 14 15 16 17 [8 moves] (20 eggs, initial step = 5) e=20(20) 5 10 15 18 19 20 e=17(20) 5 10 15 18 16 17 e=14(20) 5 10 15 11 12 13 14
(20 eggs, initial step = 4) 4 8 12 16 20 17 18 .. thanks! also what is the algorithm for this particular test case? thanks or maybe step is not fixed at all? like step0=7, step1=6, step2=5? +6 +5 +4 +3 6 11 15 18 5 6 1 2 3 4 5 10(or 11) 6 11 7 8 9 10 14(or 15) 6 11 15 12 13 14 17(or 18) 6 11 15 18 16 17 20 6 11 15 18 19 20 hmm for 2 eggs / 20 floors the answer is 6, this is weird Edited by author 16.03.2016 05:21 2eggs 100floors (14) +14 +13 +12 +11 +10 +9 +8 +7 14 27 39 41 52 62 71 80 88 95 39 14 27 39 28 29 30 31 32 33 34 35 36 37 38 100 14 27 39 41 52 62 71 80 88 95 96 97 98 99 IIRC for this task we need to save the last egg at all costs, until the moment we figure out the exact answer. For 2 eggs / 20 floors, that would be: 1st try: 6, and if breaks — 1, 2, 3, 4, 5 in worst case for last egg (so it breaks when we figure out the answer for sure). 2nd: 11, if breaks — 7, 8, 9, 10. 3rd: 14, if breaks — 11, 12, 13. 4th: 17, if breaks — 15, 16 5th: 19, if breaks — 18. 6th: 20 So in worst case, 6 tries. Then again, i didn't solve it yet, so i can't guarantee anything, but that's how i understood it from previous discussions. And yeah, you already described it above, i didn't read. Sorry. Edited by author 16.03.2016 06:26 the direction is right, step0 is the answer, for 2 eggs dunno for 3 eggs also coz i не решил еще тоже Well, intuitively, with 3 eggs we should put the first one in the middle, to minimize a floor quantity in worst case for remaining two eggs? intuitively this is DP problem with precomputing table of 1001x1001 cells row 1 contain values -1 1 2 3 4 5 .. row 2 contain values -1 1 2 2 3 3 .. row 3 ?? with 3 eggs we do move0 somewhere in the middle, doing loop from Eggs to 1, computing min(row1[step1]+row2[step22]) (or minimize step1+step2, maybe) for 3 eggs: for (step2=e; step2>1; step2--) for (step1=i2; step1>1; step1--) row 2 : -1 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7 7 8 .. Can you give me some examples, please! n=int(input()) l=[int(input()) for _ in range(n)] items=sum(l) n=float(n) x=3.0 for i in l: try: i==x print ('None') if items/n==5 and i!=x: print 'Named'
elif (4.5<=(items/n)<5)and i!=x: print 'High'
elif ((items/n)<4.5)and i!=x: print 'Common' Problem ambiguous but finally solve! I scratched head for longest time, so clarification here to help others Do not worry, no answer writed, only clarification: IMPORTANT 1: One step = one grid COLUMN. Example show 2 steps: * ** Example show 2 steps: * ** ** Example show 4 steps: * * * ** *** **** IMPORTANT 2: Step HEIGHT > before step height. Example show all VALID N = 7: VALID Staircase #1 of 4 * * * * * ** VALID Staircase #2 of 4 * * * ** ** VALID Staircase #3 of 4 * ** ** ** VALID Staircase #4 of 4 * * ** *** Example of INVALID N = 7: INVALID Staircase: * * * * * * * Invalid because only 1 step INVALID Staircase: * *** *** Invalid because 2 steps same height (height 2, height 2, height 3) INVALID Staircase: * * * * *** Invalid because step height not > before step (height 3, height 1, height 3) try this test: 10 1 10 100 9 1 1 1 1 1 1 1 1 10 right answer: 19 Edited by author 10.11.2013 14:51 Edited by author 10.11.2013 14:51 Edited by author 10.11.2013 14:51 You can try this .... 5 1 4 1 2 2 6 6 5 right ans : 7 //Timus1493 #include <iostream> using namespace std; //Creates a copy and does not change the argument int sum_of_3(int num) { int result = 0;
for (int i = 1; i <= 3; i++) { result += num % 10; num /= 10; } return result; } int main () { int num; cin >> num;
int digit = num % 10, right = sum_of_3(num), left = sum_of_3(num / 1000);
if ((left > right && digit == 9) || (left < right && digit == 0)) cout << "No \n"; else cout << "Yes \n"; cout << num; return 0; } Fix output as task required - remove spaces after Yes and No, remove "cout << num;". program z1026; var n,k,i,j,nomer:integer; count:array[1..5000]of integer; a,rez:array[1..100000]of integer; z:array[1..100]of integer; s:string; begin read(n); for i:=1 to n do read(a[i]); read(s); read(k);
for i:=1 to 5000 do count[i]:=0; for i:=1 to n do inc(count[a[i]]); nomer:=1; for i:=1 to 5000 do for j:=1 to count[i] do begin rez[nomer]:=i; inc(nomer); end; for i:=1 to k do read(z[i]); for i:=1 to k do writeln(rez[z[i]]); end. Answer for test1 is 121 121 7 123 |
|