Discussion of Problem 1607. Taxii kinda changed the variables a = the first sum suggested by petr b = the ---------------------- taxi driver c = amount added by petr everytime d = ---------------- taxi driver we can say that at step n of bargaining: petr -> a + n*c taxi -> b - n*d where looking for a time when petr's suggestion is less than the drivers which means a + nc <= c - n*d but there sometime when petr suggest more than what the driver suggest the previous time. that's why i am comparing between the last petr's suggestion and the previous one of the driver a+c*n > b-d*(n-1). in this case petr says ok to the taxi driver and do not suggest more than that. void solve() { int a, c, b, d; cin >> a >> c >> b >> d; if (a >= b) { cout << a; return; } int n = (b-a)/(c+d); if ((b-1)%(c+d)!=0) n++; if (a+c*n > b-d*(n-1)) { cout << b - d*(n-1) << ln; } else { cout << a + n*c << ln; } } Edited by author 10.09.2022 21:11 could you help explain why: if ((b-1)%(c+d)!=0) n++; this is more simply code: int a, b, c, d; cin >> a >> b >> c >> d; if (a >= c) { cout << a; return; } int l = (c - a) / (b + d); a += b * l; c -= d * l; if (a + b <= c) cout << a + b; else cout << c; Очень хитрая задача, так как в условии не сказано или а меньше с или с меньше а поэтому нужно рассматривать 2 варианта. Вот правильный код: #include<iostream> using namespace std; int main() { int a,b,c,d,e; cin >> a >> b >> c >> d; if( a <= c) { while(a <= c) { if( a + b <= c) { a = a + b; e = a; } else {e = c;break;} if( c -d >= a) { c = c - d; e = c; } else {e = a;break;} } cout << e << endl; } else cout << a << endl; return 0; } del Edited by author 25.10.2023 21:07 #include <bits/stdc++.h> using namespace std; #define go ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; int main() { go int a, b, c, d; cin >> a >> b >> c >> d; while(a < c){ if(a+b > c) break; a += b; c -= d; } cout << max(a, c);
return 0; } The key to solve is that : Driver won't take less than offered, and Petr won't pay more than asked. So if you using a loop for example in each step a will be always min(a + b, c) and c will always be max(c - d, a) #include <iostream> using namespace std; int main() { long long a, b, c, d; int r = 0, g; cin >> a >> b; cin >> c >> d; g = (a + b * (c - a + d) / (b + d)) - ((a + b * (c - a + d) / (b + d)) % b); cout << g << endl; return 0; } Edited by author 02.10.2020 16:52 Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var tokens = Console.ReadLine().Trim(). Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); var a = int.Parse(tokens[0]); var b = int.Parse(tokens[1]); var c = int.Parse(tokens[2]); var d = int.Parse(tokens[3]); var min = a + (c - a) / (b + d) * b; var max = c - (c - a) / (b + d) * d; min = Math.Min(min + b, Math.Max(min, max)); max = Math.Max(max - d, min); Console.WriteLine(max); Corrected, see !!! sign Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; var tokens = Console.ReadLine().Trim(). Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); var a = int.Parse(tokens[0]); var b = int.Parse(tokens[1]); var c = Math.Max(int.Parse(tokens[2]), a); // !!!! var d = int.Parse(tokens[3]); var min = a + (c - a) / (b + d) * b; var max = c - (c - a) / (b + d) * d; min = Math.Min(min + b, max); max = Math.Max(max - d, min); Console.WriteLine(max); } This is strange: "The driver would not ask a sum that is less than that offered by Petr." #include<bits/stdc++.h> using namespace std; int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } int main() { int a,b,c,d; cin>>a>>b>>c>>d; int carry=(c-a)%(b+d); int res=(c-a)/(b+d); if(carry==0){ cout<<a+res*b<<'\n'; } else if(carry>=b){ cout<<a+(res+1)*b<<'\n'; } else if(carry<b){ cout<<c-res*d<<'\n'; } } why wrong ans in test #6? #include<iostream> using namespace std; int main(){ int petr,a,taxi,b; int temp; while(cin>>petr>>a>>taxi>>b){ if(petr>=taxi)cout<<petr<<endl;
else{ temp=taxi-petr; if(a<=b){ while(temp>b){ petr+=a,taxi-=b; temp=taxi-petr; } cout<<petr+a<<endl; } else{ while(temp>a){ petr+=a,taxi-=b; temp=taxi-petr; } cout<<taxi<<endl; } } } } i pass all the test that the discuss give but i still get wa at #4 could u give me some new test? if(a<=b) ---> if(a<b) but i still get wa at #13 for exanmple try test 1000 2 2000 3 the right answer is 1400 but your prog output 1402 or try this 1 2 12 3 right is 6 but yours is 7 Edited by author 20.03.2008 17:57 thanks for 2nd test, it really helpfull) Thanks a lot... ^_^ // solve #include <iostream> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; while(a< c) { if(a+b > c) { a=c; break; } a= a+b; if(c <= a) { break; } c = c-d; }
cout<<a<<endl; return 0; } Please help me.I always have WA#4. Give me any tests. THAnk!!!>< Try this: 1) 100 100 150 20 Answer is 150 2) 100 100 50 20 Answer is 100 Now I've WA#14.Please give some new tests.Thank!!! Edited by author 03.03.2008 20:06 denton> Thanks for the first test. It really helped me!!! I think the answer is 200!!! Posted by denton March 02, 2008 15:11 Try this: 1) 100 100 150 20 Answer is 150 2) 100 100 50 20 Answer is 100 re:::: at test 2 the answer is 50 becouse the taxi driver ofer him 50 and in less then 100 :D Edited by author 29.12.2008 22:58 Edited by author 29.12.2008 22:58 You are wrong, 'cause first turn is Petr and after that the turn of driver, but I think driver wasn't stupid one and he would not offer Petr smoller summ. Accepted Test: 3 3 5 2 5 Edited by author 29.11.2014 20:35 thanks a lot, your tests helped me Hi, I have issue with the case "100 100 50 20"... Because logically the drivers shouldnt ask a price < price offer from Peter.. thanks for the test, helped to get AC after WA#4 Edited by author 12.03.2019 23:16 Inpt : 1 2 12 3 Output : 5 1 2 12 3 answer 6 Edited by author 12.12.2018 21:22 Что нужно поправить,чтобы эта программа реализовывала тест '60 100 300 1'?вообще она ломается на 10 тесте при сдаче, но после того как я посмотрела обсуждения и прогнала её по найденным тестам поняла что не могу реализовать только один выше сказанный ответ кстати (как я думаю) 298. вот тесты на которых пробовала. к стати я очень невнимательная, поэтому сильно на меня не ругаться ))) 150 50 1000 100 ответ - 450 1 4 2 2 ответ - 2 1 3 5 2 ответ - 4 2 1 1 1 ответ - 2 1 3 4 3 ответ - 4 1000 2 2000 3 ответ - 140 11 1 10 2 ответ - 11 4 3 6 1 ответ - 6 1 2 12 3 ответ - 6 var a,b,c,d:integer; begin read(a,b,c,d); if a>c then write(a) else begin while a<>c do begin a:=a+b; if (a>c-d)and(c>a) then c:=a else if a+b>c then a:=c else if a=c then break else c:=c-d; end; write(c); end; end. Заранее спасибо)♥_♥ Edited by author 28.12.2017 21:55 Edited by author 28.12.2017 21:56 Let's take a look at this simple test: 32 36 80 4 The process goes like this: 32 -> 80 -> 32+36=68 -> 80-4=76 -> 68+36=104>76, so the end result is 76. Now, let's take a look at how you handle it. a=32 b=36 c=80 d=4 a:=a+b; -> a = 68 now if (a>c-d)and(c>a) then c:=a -> 68>80-4 is false, so this doesn't trigger else if a+b>c then a:=c -> 68+36=104>80, a becomes 80 here. then, while a<>c is checked again, a = c = 80 at this point, so it jumps to write(c). However, answer is 76 and not 80. Hope this helps you to figure out the problem! 150 50 1000 100 Why in this test answer is 450 (not 500) ? var a,b,c,d,cen,k:integer; begin read(a,b,c,d); while k<>1 do begin if (a+b>c) then begin k:=1;cen:=c;end else a:=a+b; if(c-d<a)then begin k:=1;cen:=a;end else c:=c-d;end; writeln(cen); end. #include <iostream> using namespace std; int main() { int a,b,c,d; cin>>a>>b>>c>>d; for (int i=0;a<c;i++) { a+=b; c=c-d; } cout<<a; } what's the problem??? help me please same program as me !just debug with this test data:60 100 300 1 Edited by author 10.10.2017 07:40 1. Petr offers first. 2. The driver would not ask a sum that is less than that offered by Petr var a,b,c,d:integer; begin Read(a,b,c,d); While a<>c do begin a:=a+b; c:=c-d end; a:=c; WriteLn(a); end. Почемууу(( Why((( Карочь хрень полная Поможете?? Help me? Edited by author 25.03.2016 14:04 Have you tried to run your program on task sample locally, using debugger? Or at least print A and C values at the end of each cycle iteration? Why no? You should try. Edited by author 25.03.2016 15:29 Refer the example. I'm just a novice programmer. I try very hard. Help. I don't understand. ( YANDEX translator) "Refer the example" И чо? "Я отладила программу на примере, пытаюсь сдать acm, получаю WA. Почему?"? "При локальном запуске, на примере, получаю неправильный ответ/программа зависает. Почему?"? "Что такое debugger?"? В общем, телепаты в отпуске. P.S. Посмотрел попытки на acm.timus.ru. Все TLE 1. Патамушта цЫкл While a<>c do begin a:=a+b; c:=c-d end; бесконечный, как и ожидается. Edited by author 26.03.2016 03:04 Ну да :D Бывает. А ты на янде переводил? Особенно это выдал яндекс Патамушта цЫкл Они никогда не будут равны, если не состыкуются. Возьмем данные 150 50 1000 100 200(+50) 900 (-100) 250 800 300 700 350 600 400 500 450 400!!!! Edited by author 10.06.2017 17:58 #include<iostream> #include<math.h> #include<algorithm> #include<string.h> using namespace std; int a,b,c,d; int main() { cin >> a >> b >> c >> d; int h = c; if(a >= c) { cout << a; return 0; } while(1) { if(a == c) { cout << a; return 0; } a+=b; if(c-d >= a) c-=d; else { if(a > h) cout << h; else cout << a; return 0; } } return 0; } #include<stdio.h> #include<math.h> int main() { int a,b,c,d,i,t; scanf("%d %d %d %d",&a,&b,&c,&d);
for(i=1;i<10000;i++) { a=a+b; if(a>c) { t=c; break; } c=c-d; if(a>=c) { t=a; break; } } printf("%d",t); return 0; } for 150 400 1000 200: 150 1000 550 800* 950 600 how is the answer 800 and not 950 ?? for 100 100 150 20: 100 150* 200 130 why is the answer 150 and not 200 ?? for 1 2 12 3: 1 12 3 9 5 6* 7 5 why is the answer 6 and not 7 ?? for 3 3 5 2: 3 5* 6 3 why is the answer 5 and not 6 ?? Please help! Edited by author 16.03.2015 23:24 Read one more time the problem and thank you for good tests) "Таксист не станет называть цену ниже той, которую предложит Петя. В этом случае он согласится с его ценой. Аналогичным образом поступит и Петя." Could someone tell me what WA - 3 is. all the test cases are working with the expected output but still get WA 3. NOt sure where the problem is. Kindly help. I myself have found the solution for test case - 3. Try: 1 3 4 3 the answer should be 4 Test 1: 150 50 1000 100 200 900 250 800 300 700 350 600 400 500 450 400 Answer:450 Test 2: 1 2 12 3 3 9 5 6 7 3 Answer:6 Test 3: 4 3 6 1 Answer:6 Test 4: 11 1 10 2 Answer:11 Test 5: 1000 2 2000 3 ............. ............. 1388 1418 1390 1415 1392 1412 1394 1409 1396 1406 1398 1403 1400 1400 Answer:1400 Hi, Can you please explain the test cases 2, 3, 4, 5 from your list on how do they work ? I have queries on how these answers come to the above asked test cases with respect to the logic given in the question. kindly help please! Thanks I Understood the logic myself.:) :D here's my text: program Project2; var a,b,c,d:longint; begin readln (a,b,c,d); while c>a do begin a:=a+b; c:=c-d; end; if c=a+b then writeln (c) else writeln (a);
end. what's the problem??? help me please 4 3 6 1 correct answer: 6 thanks but now wa is #6 can't understand what ellse I've missed. give me your code program Project2; var a,b,c,d:longint; begin readln (a,b,c,d); if c<a+b then writeln (c) else begin while c>a do begin a:=a+b; c:=c-d; end; writeln (a); end;
end. If a>c in the beginning then answer is a not c. Also check whether a>c after adding b each time. Here is correct code var a,b,c,d:integer; begin Readln(a,b,c,d); While a<=c do begin a:=a+b; if a>c then a:=c; c:=c-d; end; Write(a); end. Edited by author 09.11.2009 14:56 correct answer is 7. 4 3 6 1 correct answer is 7 WHY??? Petr offers 4 Taxi says 6 Petr won't increase because 4+3>6 => the answer is 7 correct answer is 6! Read the task carefully!! No correct answer must be 6. Because, Peter offer: 4 but when you add 3 it will be 7>6 in this case a must be equal 6. Beacause driver satisfy 6 money. In this case put this condition to your iterator: if(a>c) a=c; #include <iostream> using namespace std; int main(){ int a,b,c,d,k=0; cin >> a >> b >> c >> d; while(a<c){ if(k==0){ k = 1; a += b; cout << a << " "; } else { k = 0; c -= d; cout << c << " "; } } cout << a ; return 0; } hi everybody! i have wa 5 but i don't understand my mistake. can anybody who knows some tests help me? |
|