The more - the better! 'cause I have no idea what I'm doing wrong :\ 50 49 8.4 5.5 //1 50 49 8.4 5 //25 50 49 8.4 4 //28 50 49 8.4 2.0 //37 50 49 8.4 0.2 //48 The answer of second test case is 1, not 25. My ac programm gives 1 for second and 25 for third test Current tests contain max 2 digits after decimal point. Could you specify it in the problem statement? Else there is no solution to this problem. Without this limit specified a test can have a lot of digits after decimal point so that it is even impossible to read it within time limit. in this test Petr should go to 1 floor The problem is very simple. It is clear from the first glance what is going on. The coding is trivial. The math part is trivial. And... for some reason it is almost impossible to get AC from the first try. Give some tests. UP! Can someone explain why it happened? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Lift { public static final float LIFT_DELAY = 15; public static final float PETYA_DELAY = 5; public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(reader.readLine()); float petyaFloor = Float.parseFloat(st.nextToken()); float liftFloor = Float.parseFloat(st.nextToken()); float petyaSpeed = Float.parseFloat(st.nextToken()); float liftSpeed = Float.parseFloat(st.nextToken()); float timeByFootToTheFirstFloor = ((petyaFloor - 1) * petyaSpeed); //время, если идти до 1го этажа пешком float firstLiftDescentTime = ((liftFloor - 1) * liftSpeed) + LIFT_DELAY; //время, затраченное лифтом при спуске и простое на 1м этаже Float numOfFloorToGoByFoot = firstLiftDescentTime / petyaSpeed; //количество этажей, которые может успеть пройти Петя за время спуска лифта int numOfFloors = numOfFloorToGoByFoot.intValue(); //см. предыдущее Float numOfSeekingFloor = petyaFloor - numOfFloors; //искомый этаж float timeLiftWithPetya = (((numOfSearchingFloor - 1) * liftSpeed) * 2) + firstLiftDescentTime + PETYA_DELAY; //время на спуск, подъём к Пете на новый этаж и спуск с ним до 1го этажа if (timeByFootToTheFirstFloor < timeLiftWithPetya) { System.out.println("1"); } else if (timeByFootToTheFirstFloor == timeLiftWithPetya) { String s = numOfSearchingFloor.longValue() + ""; System.out.println(s); } else { String s = numOfSearchingFloor.longValue() + ""; System.out.println(s); } } } 50 49 0.99 0.28 Answer 21, yours 22. I've rounded up this float, now I get the same answer as you, but it still gives me WA#3 :( Could you please give me one more hint? Edited by author 23.05.2016 14:07 check the test where answer is 1 I too did not know what was wrong with my solution, but got accepted when replaced: for (int i = n; i >= 1; i--) if (time[i] < time[besti]) besti = i; with: for (int i = n; i >= 1; i--) if (time[i] + epsilon < time[besti]) besti = i; With epsilon = 1e-9. Good luck! :) Thank you very much. You really helped me: I did the same thing and got AC. for wa7 too work.. thx Edited by author 11.08.2014 17:44 I think that this problem should be 200.. sry my english is so bad Please could you give me some tests for this problem? I have WA11 and don't know what's wrong with it. It's not necessary now, I've got AC long time ago. #include <stdio.h> int main() { int i,n,k,best; float timeu,timev,time,v,u,A[101],besttime; scanf("%d%d%f%f",&n,&k,&u,&v); for(i=n;i>=1;i--) { timeu=(n-i)*u; timev=(k-1)*v; if(timeu<timev+15) time=timev+15+2*(i-1)*v+5; else if(timeu-timev>15) time=timeu+2*(i-1)*v+5; else time=timev+(timev-timeu)+2*(i-1)*v+5; A[i]=time; } besttime=A[n]; best=n; for(i=n-1;i>0;i--) if(besttime-A[i]>0.00000000001) { besttime=A[i]; best=i; } printf("%d",best); return 0; } Who can give me some tests? i dont know what is incorrect I passed this test, when I understood that, if he has to go to the first floor using his legs, he mustn't enter the elevator. So, when calculating time, when he goes to the first floor, you shouldn't add 5 seconds to the time. It's interesting that a lot of people here said that we shoudn't use double so I was doing so, and was getting WA#7. I wanted to do a kinda experiment and used double without any hope. however i got AC. I agree, double is all right in case you use comparison like (a+1e-9 < b). #include <iostream> using namespace std; int main() { long double u,v,r; int n,k; cin >> n >> k >> u >> v; r=(((k-1)*v)+15)/u; if(k==1)r=(k*v)/u; if(r+5>n)cout << 1 << endl; else cout << n-(int)r << endl; return 0; } Edited by author 02.06.2008 22:16 Edited by author 02.06.2008 22:17 Oh! I think that you are not right at r. Because the elevator goes down and then waits for 15 minute, after that it goes up. So your fomular computes r is wrong! ^_^. Edited by author 07.11.2008 05:38 May be urs test not accurately. I've used DBL_EPSILON from cfloat and I've received "WA#11". When I replace DBL_EPSILON to 1e-9, I've received "accepted". Check urs test once again plz. This is my program. I have read all forum but didn't find answer. Please help {$Q-,R-,S-,I-,O+} program z1602; uses math; var a: array [1..101] of extended; u, v, k, min: extended; pos, i, n: longint; begin read(n,k,u,v); a[1]:= (n-1)*u; for i := 2 to n do a[i]:= max((n-i)*u,(k-1)*v+15)+(i-1)*v+5+(i-1)*v; min:= a[1]; pos:= 1; for i := 2 to n do if a[i] + 1e-9 < min then begin min:= a[i]; pos:= i; end; writeln(pos); end. read problem more attentively. when you find pos, you way from 2 to N, but right way from N downto 2... and you get AC :) Edited by author 06.07.2008 02:43 What's wrong with my function? long double f(int x) { if (x>1) { long double t; if (((k-1)*v+15)>((n-x)*u)) t=(k-1)*v+15; else t=(n-x)*u; return t+(x-1)*v+5+(x-1)*v; } else { return (n-1)*u; } } People give me some tests. Edited by author 10.04.2008 19:46 Your source is right. But please don't remember that "If there are several equivalent variants, output such one in which Petr will go by foot the smaller distance." I have WA#11 and read on previous topics that it must be something in "double", what shall i do? if you compare two doubles use a - b > 0.000000001 instead of a > b The same resul :( I compare two doubles just once I'm use double and got WA#11. But with float i got AC. What wrong with double? Bad tests? When comparing calculate time _t_ to the current _best_ time, where both variables are doubles, use e.g. if (t + 1e-9 < best) my algo gives 54, but I think it's wrong. Help!!!! You are right, the answer is wrong. Right answer for the input is 76. IMHO 75 is right answer too, isn`t it? Why answer 76? Not it 75? 75 will give the best time! You are wrong, guys! Straightforward checking shows that answer 76 is better than 75. Pay attention that lift and Petya reach FIRST, not zero floor! i understand what's wrong )) Edited by author 29.03.2008 14:01 Edited by author 29.03.2008 14:20 The man should be at the floor before he call for the elevator. My English is so poor.... I still do not understand. In the example case. If Petr go to floor 45: He take 4.8*5 = 24 second to go to floor 45. The elevator take 0.2*48 + 15 + 0.2*44 = 33.4 seconds to go to floor 1, stop there 15 seconds, and then go up to floor 45. So, Petr must wait for 33.4-24 = 9.4 secs, go in for 5 secs, and go down take 44*0.2 = 8.8 secs The total time is 24 + 9.4 + 5 + 8.8 = 47.2 secs Now compare with Pert go to floor 44: He take 4.8*6 = 28.8 second to go to floor 44. The elevator take 0.2*48 + 15 + 0.2*43 = 33.2 seconds to go to floor 1, stop there 15 seconds, and then go up to floor 44. So, Petr must wait for 33.2-28.8 = 4.4 secs, go in for 5 secs, and go down take 43*0.2 = 8.6 secs The total time is 28.8 + 4.4 + 5 + 8.6 = 46.8 secs! So, go to floor 44 is better, isn't it? Edited: uh oh... I misunderstand the question. The elevator will no go up till Petr press the button of elevator. Sorry. Edited by author 07.03.2008 18:57 I understand too... Edited by author 25.03.2008 23:50 |
|