Discussion of Problem 1607. TaxiPlease give me some more tests. And what is the test number 4? My code: why WA#6 import java.io.*; import java.util.*; public class misol1607 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out);
int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); int d = in.nextInt(); int r=c; while (a<c) { if ((a+b)>=c) { r=c; break; } else { a=a+b; }
if (a>=(c-d)) { r=a; break; } else { c=c-d; } }
out.println(r);
out.flush(); } } 11 1 10 2 Edited by author 20.03.2010 17:26 if(a==11 && b==1 && c==10 && d==2) cout<<11; Получается так: Садится в машину Петька и говорит:"11 руб" Таксист говорит: "Нет, брат, это слишком много для меня. Я подвезу тебя за 10 руб." Петька: "Послушай, товарищ, я настаиваю. Поехали за 11 руб." Таксист: "OK!" ИЛИ ЖЕ Получается так: Садится в машину Петька и говорит:"11 руб." Таксис радостно: "Поехали!!!!" И думает про себя:"Во дает! А я его бы и за 10 руб. подвез бы". Edited by author 20.03.2010 18:05 Edited by author 20.03.2010 18:05 //c++ #include <iostream> void main() { int ps,pu,ts,td,dif; std::cin>>ps>>pu>>ts>>td; dif=((ts=ps>ts?ps:ts)-ps)/(pu+td); std::cout<<(((ps+=(dif+1)*pu)<(ts-=dif*td))?ps:ts); } // Ruby a,b,c,d=gets.split.map { |x| x.to_i } e=((c=[a,c].max)-a)/(b+d) puts ((a+=(e+1)*b)<(c-=e*d)) ? a : c Edited by author 11.04.2013 23:58 When I first saw this problem, I thought I would be done in 5 minutes but ended up spending 1 and 1/2 hours. Few test cases, so that you don't blow your head up ! Input: 4000 100 200 100 Output: 4000 Input: 150 400 1000 200 Output: 800 petr taxi 150 1000 550 800** 950 600 so in the example the answer is 800,not 950; but ** in test case no 1: petr taxi 150 1000 200 900 250 800 300 700 350 600 400 500 450** 400 the same set of sequence(rather similar)of event occurs with different answers... plz help with this mess..... Edited by author 10.04.2013 17:58 import java.util.*; public class Taxi { public static void main(String[] args) {
int a, b, c, d;
Scanner rc = new Scanner(System.in); System.out.println("Введите стартовую сумму клиента: "); a = rc.nextInt(); System.out.println("Введите стартовую сумму водителя: "); c = rc.nextInt(); System.out.println("Введите сумму, на которую клиент повышает: "); b = rc.nextInt(); System.out.println("Введите сумму, на которую водитель понижает: "); d = rc.nextInt(); while (a < c){
a+=b; c-=d; }
System.out.println("Сумма, на которой они сошлись: "+a);
}
} у меня всё нормально работает, а ихний компилятор бракует... что не правильно? Edited by author 18.03.2013 15:14 Edited by author 18.03.2013 15:14 actually i have read this topic yesterday, but i still don't understand, what i do wrong... System.out.println("Введите стартовую сумму клиента: "); Such lines of code are extra, Timus checker thinks that it is an answer for task, and check it - but it is wrong :) So, don't put such lines in your programs. ok.. look. I erased all "extra lines". but this code does not compiling too... sorry for my silly questions, but i'm a newbie on this site and i need to understand what i did wrong.. import java.util.*; public class car { public static void main(String[] args) {
Scanner rc = new Scanner(System.in);
int a = rc.nextInt(); int c = rc.nextInt(); int b = rc.nextInt(); int d = rc.nextInt(); while (a < c){
a+=b; c-=d; } System.out.print(a);
} } import java.util.*; public class taksi { public static void main(String args[]) { Scanner in = new Scanner(System.in); int a = in.nextInt(); int a1 = in.nextInt(); int b = in.nextInt(); int b1 = in.nextInt(); int g = 0; for(int i = b;i>a;i=i-b1) { a=a+a1; if(i>a) g = a; } System.out.println(" kelisken bagasy :"+g); } } #include <iostream> using namespace std; int taxi(int a,int b,int c,int d){ if ((a+b)>c) {return c;} a+=b; if ((c-d)<a) return a; c-=d; taxi(a,b,c,d); } int main() { int a,b,c,d; cin>>a>>b>>c>>d; cout<<taxi(a,b,c,d); return 0; } Wrong answer test #1 "<=" and ">=" in those ifs. there is one more case where a >= c where you need to return a. [Code deleted by moderator] Edited by moderator 04.03.2012 00:14 If you will not stop posting your source code to the webboard, you will be banned. -- Timus Online Judge admins #include<iostream> using namespace std; int main() {int a,b,c,d; cin>>a>>b>>c>>d; while(a<=c) { a=a+b; if(a>c) a=c; c=c-d; } cout<<a; return 0; } #include "stdio.h" #include "conio.h" #include "iostream" #include "math.h" using namespace std; void main() { int GP,P,GT,S,y=1; scanf("%i",&GP);scanf("%i",&P);scanf("%i",>);scanf("%i",&S); if((GP+P>=GT)||(GP>=GT)) { if(GP>=GT) printf("%i",GP); else if(GP+P>=GT) printf("%i",GT); } else { while(y!=0) { if((GP<GT)&&(y!=0)&&(GP+P<=GT)) GP+=P; else y=0; if((GT>GP)&&(y!=0)&&(GT-S>=GP)) GT-=S; else y=0; } //if(GP>=GT)printf("%i",GP); //else printf("%i",GT); if(GP+P<=GT) printf("%i",GP); else { if(GT-S<=GP) printf("%i",GP); else printf("%i",GT); } } getch(); } Hello! I have wa #2. But i don't undestand my mistake.can somebody help me? listnig is below import java.util.Scanner; public class q1607 { /** * @param args */ public static void main(String[] args) { Scanner in1 = new Scanner(System.in); int a=in1.nextInt(); int b=in1.nextInt(); int c=in1.nextInt(); int d=in1.nextInt(); a=a-b; c=c+d; while (a<=c-d) { a=a+b; if (a>=c-d) {break;} c=c-d; } System.out.println(a); } } I wonder why the solution with Arithmetic progression is impossible. a:=a+b c:=c-d ... ... and several times isn't that equals to a:=a+bx and c:=c-dx ?? Because they can stop after a:=a+b c:=c-d ... ... a:=a+b It equals to a:=a+bx c:=c-d(x-1) Edited by author 13.03.2010 01:16 /////////////////////////////////////////////////////////// #include"iostream.h" #include"math.h" double a,d1,b,d2,m; int i,j; int main() { cin>>a>>d1>>b>>d2; if(a>=b){cout<<a<<endl;goto u;} if(a+d1>=b){cout<<b<<endl;goto u;} while(a<b) { a=a+d1; if(a>=b || a+d1>=b) { cout<<a<<endl; break; } b=b-d2; if(a>=b) { cout<<b<<endl; break; } } u: return 0; } ///////////////////////////////////////////////////////// #include<iostream.h> #include<math.h> int main() { int a1,b1,a2,b2; cin>>a1>>b1>>a2>>b2; if(a2<=a1) cout<<a1; else if(abs(a1-a2)<b1) cout<<a2; else{ while(a1<a2) { a1+=b1; a2-=b2; } if(a1>a2) cout<<a1; else cout<<a2; } return 0; } Where I'm wrong?Please help!Thank in advance!!! Maxim Dvoynishnikov (Dnipropetrovsk NU) * [3] // Problem 1607. Taxi 8 Mar 2008 00:39 For test "1 4 10 2" right answer is 8. why is it 8? Maxim Dvoynishnikov (Dnipropetrovsk NU) Re: * // Problem 1607. Taxi 14 Mar 2009 02:39 >> 1 << 10 >> 5 << 8 >> 9, but 8 var u1, u2, d1, d2: longint; K: real; begin readln(u1, d1, u2, d2); if u1>u2 then write(u1) else begin k:= (u2-u1)/(d1+d2); write(int(k)*d1 +u1 + d1:0:0);end; end. Check these cases 1 4 2 2 answer: 2 1 3 5 2 answer: 4 I think the answer is 5 because Petr's offer 1 + 4 = 5 driver's offer = 2 - 2 = 0 #include <iostream.h> int main() { int P,p,T,t; cin>>P>>p>>T>>t; while(T>P) {
P+=p; T-=t; } P-=p; T+=t; if(P+p>=T) { cout<<T; return 0; } if(P+p<T) { cout<<P+p; return 0; } if(P+p==T) { cout<<P; return 0; } return 0; } #include <iostream.h> int main() {int a,b,c,d; cin>>a>>b>>c>>d; if(a>=c) cout<<a; else {while(((a+b)<=c) && ((c-d)>(a+b))) {a+=b; c-=d;} if((a+b)>c) cout<<c; else cout<<a;} return 0;} #include <stdio.h> int calculate(int a,int b,int c,int d); void main(){ int a=0,b=0,c=0,d=0; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n",calculate(a,b,c,d)); } int calculate(int a,int b,int c,int d){ bool m=true; if (a>c) return a; if (a==c||a+b>c) return c; if (c-d<a) return a+b;
while(1){ if (m){//c-a>=b){ a+=b;m=false; if (a+b>c-d) return a; } else if (!m){//&&c-a>=d){ c-=d;m=true; if (c<a+b) return c; } //else return a; } } #include <stdio.h> int calculate(int a,int b,int c,int d); void main(){ int a=0,b=0,c=0,d=0; scanf("%d%d%d%d", &a, &b, &c, &d); printf("%d\n",calculate(a,b,c,d)); } int calculate(int a,int b,int c,int d){ bool m=true; if (a>c) return a; if (a==c||a+b>c) return c; if (c-d<a) return a+b;
while(1){ if (m&&c-a>=b){ a+=b;m=false; if (a+b>c) return a; } else if (!m&&c-a>=d){ c-=d;m=true; if (a+b>c) return c; } else return a; } } CODE: var a,b,c,d:word; begin {$IFNDEF ONLINE_JUDGE} assign(input, 'input.txt'); reset(input); assign(output, 'output.txt'); rewrite(output); {$ENDIF} read(a,b,c,d); while ((c>=(a+b)) and (a<=(c-d))) do begin a:=a+b; c:=c-d; end; If a<=c then writeln(c); If c<a then writeln(a); {$IFNDEF ONLINE_JUDGE} close(input); close(output); {$ENDIF} end. Wrong answer 2
for exanmple try test 1000 2 2000 3 answer is 1400 1 2 12 3 6 100 100 150 20 150 2 1 1 1 2 150 50 1000 100 450 What then error? I see an error- Like, you are saying- "if a<=c then writeln(c)" I think it is wrong. If a+b<=c then answer may be (a+b). for example, a = 10, b = 7, c = 20, d = 15 Now, the answer is 17. |
|