Common BoardThe most important functions are listed below: // Judge if there exist a parabola passing P[a] and P[b] // The validation of direction of the parabola is included in the positive sign bool Valid(int a, int b) { if (P[a].x == P[b].x) return false; else return (P[a].x - P[b].x) * (P[a].x * P[b].y - P[b].x * P[a].y) > 0; } // Judge if the parabola passing P[a] and P[b] also passes P[c] // Using the determinant for judgement bool Pass(int a, int b, int c) { return (P[a].x * P[a].x) * P[b].x * P[c].y + P[a].x * P[b].y * (P[c].x * P[c].x) + P[a].y * (P[b].x * P[b].x) * P[c].x - (P[a].x * P[a].x) * P[b].y * P[c].x - P[a].x * (P[b].x * P[b].x) * P[c].y - P[a].y * P[b].x * (P[c].x * P[c].x) == 0; } Note: using long integers (64-bit) to avoid overflow. Good luck. Do not derive them by hand, use Maxima: p: a*x^2+b*x=y; s: solve([ev(p,x=x1,y=y1),ev(p,x=x2,y=y2)],[a,b])[1]; a < 0,s; m: denom(lhs(ev(p,s,ratsimp))); e: ev(p,s) * m, ratsimp; to print as source code use fortran(e); It is also a good idea to use macro to avoid typos: bool on_par(int a, int b, int c){ // [c] on the same parabola as [a] and [b] # define _(a,b,c) x[c]*x[a]*(x[c]-x[a])*y[b] return _(a,b,c) - _(b,a,c) == _(a,c,b); # undef _ } I've got AC then complete test for a<0 && b!=0: 1 999 2 999 3 0 4 1 5 2 answ 3... Good Luck! Edited by author 23.10.2011 01:27 Edited by author 23.10.2011 04:20 This is not correct test =) In russian vertion of problem "В каждой из пяти строк входа находится пара целых положительных(!!!!) чисел, не превосходящих" There are no points with negative x. Use assert to test such things. Test 5 is likely about points that have the same x. For each pair of points, consider the family of lines parallel to the line that connects the points. Project all the points on the line perpendicular to the family, sort the coordinate, and find the smallest coordinate distance that covers k points. Note that since at least one line on the border must contain two points, instead of sorting one can use partition and nth_element. That is the time complexity does not need logarithm: O(n^3). EDIT: Finally passed with Python in 0.109s. deque() really works for this problem. The key insight is to recognise how we design the pop() and popleft() to make sure the first element of the list is the largest element which has not expired. Whether or not the middle elements have expired does not matter. Edited by author 01.04.2018 15:32 Hi. Can anyone help me? 5 4 4 1 4 1 2 Why answer 3 2 ?? why it isn't 3 1? i can cast power = 2, then i'll destroy three coin (1, 1, 2) which is equal to 4, and i can survive. But i can't cast with power 4, because then i take (4,4) = 8 damage.
Edited by author 31.03.2018 04:18 Edited by author 31.03.2018 04:18 Edited by author 31.03.2018 04:20 >If we destroy k coins, the response will be k times stronger than our spell This means, if we destroy 3 coins (1, 1, 2) with power 2, we'll take 3*2=6 damage. Так до сих пор и не выяснилось, что делать с окончанием ввода? Или измените условия так, чтобы окончание ввода оканчивалось явно - например пустой строкой или -1, или же уточните, нужно ли это делать с помощью файла. Перенаправление ввода из файла, например в bash, не воспринимает символ конца файла EOF. А ваш сайт при тесте делает расчет на то, что ввод окончится EOFом. Думаю по этой проблеме так мало успешных попыток Could anyone give me some tests for this one? One of the solutions would involve sorting and stacks. I've tried to use reb-black tree, but it seems to have problems with dublicate-keys. Edited by author 14.08.2015 22:05 I got AC by iterating all the ranges and putting them in a stack. Basically, if next range fits into previous one, put it in a stack. If it does not, remove previous ranges from the stack until it does (or the stack gets empty). At each step, update the answers to relevant queries. Binary search is good enough for finding them. it's possible to solve this problem with segment tree. Just put all answers into segment tree with meaning -1 and then update it with segments, sorted by range HINT1: solution always exist HINT2: try to solve this problem with end. HINT3: this problem can solve <= O(n logn) I tried implementing mergesort which probably had recursion depth runtime error; bisect insertion to save some memory, but too slow for python list (perhaps a good alternative if I have access to pointer?); heapq is much faster but instable. What are other options? import java.io.InputStreamReader; import java.text.DecimalFormat; import java.util.Scanner; public class Reverse { private static void printer(double value){ String pattern = "###0.0000"; DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); System.out.println(output); } public static void main(String[] args) { Scanner sc = new Scanner(new InputStreamReader(System.in)); long a,b,c,d; a = sc.nextLong(); b = sc.nextLong(); c = sc.nextLong(); d = sc.nextLong(); printer(Math.sqrt(d)); printer(Math.sqrt(c)); printer(Math.sqrt(b)); printer(Math.sqrt(a)); } } In your solution, it is possible just 4 numbers (a,b,c,d). Suggestion: try using a loop instead of a,b,c,d and finish the loop when the user type something different than a number It's very easy problem, but many people don't understand how to solve it ... :) 7 lines : #include <iostream> using namespace std; int main(){ unsigned long long N; cin >> N; cout << N*N << endl << N; return 0; } 5 lines: #include <iostream> void main() { unsigned long long N; std::cin >> N; std::cout << N*N << std::endl << N; } 4 lines: public class solver { public static void main(String[] args) { long n = new java.util.Scanner(System.in).nextInt(); System.out.println(n*n + "\n"+n);}} var n:int64; begin read(n); writeln(n*n); write(n) end. Edited by author 06.10.2014 22:49 OMG, i made prime factorization of n, searching for odd powers, multiplying to get k got AC, but now I see it was not neccassary Also for 18 i got 12 and 2, as in example. Edited by author 27.11.2015 02:00 1 line, no ";" tricks to put multiple lines into one :) print (lambda x : str(int(x) * int(x)) + '\n' + x)(raw_input()) My code fails with WA#1 although it passes every test cases that I've found in comments. Any hints? Why isn't the output for 1 just: 1 ? It is equivalent to: 0 X * 1 + ... but it is shorter. The problem asks for minimal length doesn't it? Problem solved. Was using a greedy solution which omitted some of the possibilities. Edited by author 26.03.2018 11:18 Всем привет. Пишу на с++. И возникла проблема с вводом широты и долготы без перехода на новую строку. Выходит: <X1> ^<X2> '... что не очень красиво. Хотелось бы так <X1>^<X2>'<X3>" <NL/SL> но не знаю как реализовать. Спасибо. scanf("%d^%d'%d\" %cL", &x1, &x2, &x3, &ch); how can i see my submission list? Edited by author 23.03.2018 17:43 Edited by author 23.03.2018 17:43 |
|