50 50.1 Answer: 501 10 20 Answer: 6 0.05 5.02 Answer: 20 0.05 5 Answer: 21 99.98 99.99 Answer: 5001 25 50 Answer: 3 13 14.1 Answer: 15 92 93.4 Answer: 13 30.2 50.01 Answer: 2 0.01 0.02 Answer: 5001 45.55 45.56 Answer: 90 49.09 50.01 Answer: 2 0.01 99.99 Answer: 2 0.29 0.3 Answer: 334 60 70 Answer: 3 Edited by author 08.02.2023 14:48 With e=0.0000001 I have WA#14 with 0.000001 i got AC with 0.000001 i got AC Me too. round(v, 6) in Python. read(p,q); for i:=2 to 10000000 do begin a:=i/100*p; b:=i/100*q; a1:=trunc(a); b1:=trunc(b); if (b1-a1)>=0.99 then begin write(i); halt; end; end; why WA ? Me,too! Edited by author 24.04.2021 19:44 Input in the task looks like: 13 14.1 Not like: 13 14.1 So change input in your program to p,q=map(float, input().split()) Hello! Seems there is a duplication in english statement of the problem: >> We know that there are more than P% conductors and less than Q% conductors of all citizens of Ekaterinburg. >>By percentage, we know that there are more than P% conductors and less than Q% conductors of all Russian citizens in this city получил АС, долго искал где долбанный баг, т.к. ТЕСТ 22 выдавал ошибку по времени, если у вас такая же проблема и вы используете преобразование double в int то в 22 тесте точность P и Q 3 знака, поэтому ТЛ и выдает, вероятно на вход подаются какие нибудь числа 22.333 и 22.334 удачи You are wrong! P and Q are given with up to 2 digits after decimal point in all tests. похожая фигня, точности 2 знаков после запятой не хватало, впилил третий знак, всё заработало code like: size_t out = 0; printf ("%zu\n", out); result - > wa#1 ((( if i use printf ("%d\n", out); all test accepted (( Why? https://wandbox.org/ & gcc 7.1 - The first version works correctly ((( less than can't be equal! Можно просто перебирать ответ наименьшего возможного, двойки, пока не найдем нужное значение. Для данного количества жителей можно за log этого количества по времени найти требуемое количество кондукторов. Здесь пишут про int_64, про "не использовать double" и "использовать epsilon=1e-9". В моём варианте такое не нужно Хватило int_32 и double. Никакого epsilon, сравнения непосредственно оператором <=. #include <bits/stdc++.h> using namespace std; float p,q,t1,t2,t3,l1,l2; int main() { cin>>p>>q; for(int i=1; i<=1000000; i++){ t1=(p*(float)i)/(float)100; t2=(q*(float)i)/(float)100; l1=(int)t1; l2=(int)t2; if(l1==t1||l2==t2||l1!=l2){ if(l1!=t1) l1=l1+1; for(int j=l1; j<=l2; j++){ t3=((float)j/(float)i)*(float)100; if(p-0.000001<t3&&t3<q+0.000001){ cout<<i; return 0; } } } } } The follwing is my pgm. Could some give a test case not satisfied here? var s1,i:integer; f:boolean; a2,b2,a1,b1,a,b:real; begin f:=false; read(a); read(b); a1:=a/100; b1:=b/100; if b<>0 then i:=trunc(1/b1); a2:=a1*(i); b2:=b1*(i); while not f do begin if (((trunc(b2)<>trunc(a2)))and (frac(b2)<>0) then f:=true; a2:=a2+a1; b2:=b2+b1; i:=i+1; end; i:=i-1; writeln(i);
end. Got ac by using double not float by accepting the input, so wired. When I run the code it gives me a runtime error. Why? Python3 for problem 1011. from math import ceil, floor a = float(input()) b = float(input()) if a>b: a, b = b, a num = 1 while ceil((a/100)*num) != floor((b/100)*num): num += 1 print(num) Edited by author 06.05.2016 11:07 1)Not use double format; 2)Use int64; Submitted following solution, but WA on 1st test. I tried very different inputs and works fine actually. def get_input_number gets.chomp.to_f end def calculate_conductors(low_percent, high_percent) (2..10000).each do |citizens| konduktors = (low_percent*citizens).ceil if (low_percent*citizens < konduktors) && (konduktors < high_percent*citizens) return citizens end end end def prepare_input_and_go lower_border = get_input_number/100 upper_border = get_input_number/100 puts calculate_conductors(lower_border, upper_border) end prepare_input_and_go // 严格按照题目来 #include <stdio.h> #include <stdlib.h> #include <math.h> #include <algorithm> using namespace std; const int p = 10000; double xs, ys; int x, y, ans; int main(void) { scanf ("%lf%lf", &xs, &ys); ans = 1, x = y = 0; // 严格按照题目来 (more than ... ; less than ... ) ys -= 1E-10, xs += 1E-10; while (x == y) ans++, x = int (ans * xs) / 100, y = int (ans * (ys)) / 100; printf ("%d", ans); return 0; }
想知道为什么ys是减1E-10,而xs是加1E-10! 想知道为什么ys是减1E-10,而xs是加1E-10! because it said "more than P%" and "less than Q%", so it can't be equal, you have to shorten interval, just add or sub 1E-10 (因为题目是说“more than P%” 和 “less than Q%”,因此不能相等,所以两边的区间都要往里面再缩小一点,只要加或减1E-10就行) import java.util.Scanner; public class _1011 { public static void main(String[] args) throws Exception { Scanner s = new Scanner(System.in); double p, q; p = Double.parseDouble(s.nextLine()); q = Double.parseDouble(s.nextLine()); p /= 100; q /= 100; answer(p, q, 1, 1, 0); } public static void answer(double p, double q, double m, double mp, long n) { long t = (long) (m / q) + 1; if (p * t < mp) { System.out.println(n + t); } else { answer(p, q, 1 - q * t + m, 1 - p * t + mp, n + t); } } } Why I have Runtime error? I use C#. Code is here. using System; using System.Globalization; class EntryPoint { static void Main() { CultureInfo ci = new CultureInfo("en-US"); double p = Convert.ToDouble(Console.ReadLine(),ci); double q = Convert.ToDouble(Console.ReadLine(),ci); int x = 1; while (true) { if ((int)(q * x / 100) - (int)(p * x / 100) > 0) break; x++; } Console.WriteLine(x); } } Quote from problem description: "These numbers are separated by some spaces or "end of line" symbols" #include<iostream> using namespace std; int main() { double p,q; cin>>p; cin.get(); cin>>q; long tmp_q = 1,tmp_p = 0; for(int i = 1;i < size_t(-1); ++i) { tmp_p = p * i * 100; tmp_q = q * i * 100; long res = (int)(tmp_p/10000); ++res; if(tmp_q % 10000 == 0) { if(res < (int)(tmp_q/10000)) { cout<<i<<endl; break; } } else { if(res <= (int)(tmp_q/10000)) { cout<<i<<endl; break; } } } } some hints?? where's the problem??? I do not see error here, but didn't pass the 17'th test var p,q: extended; a,b: longint; BEGIN read(p,q); p:=p/100; q:=q/100; a:=1; while (true) do begin b:=1; while (a/b>=q) do inc(b); if (a/b>p) then begin write(b); halt(0); end else inc(a); end; END. Me, too. I'm getting insane. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!!!!!!!!!!!!! Use epsilon! Instead of >= q and > p use >= q-eps and > p+eps and you'll get AC. Good luck! ;) ??? Use epsilon! Instead of >= q and > p use >= q-eps and > p+eps and you'll get AC. Good luck! ;) who can say me, what is epsilon??? how to use it eps=0.000000001 Thank You!!! I got AC!!! with eps! |
|