|
|
back to boardDiscussion of Problem 1607. TaxiWhy test # 6 is wrong? Posted by AlexRad 22 Mar 2015 14:34 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); Re: Why test # 6 is wrong? Posted by AlexRad 22 Mar 2015 14:51 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); } Re: Why test # 6 is wrong? This is strange: "The driver would not ask a sum that is less than that offered by Petr." Re: Why test # 6 is wrong? Posted by avro01 14 Sep 2020 18:26 #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? |
|
|