Common BoardI tried to figure it out, how 1 tree and two sticks with the length of 2 can form the area more than 4? The largest area would be rectangle. What is the trick on this problem, can anybody explain with Geometry language. Thanks. Edited by author 30.01.2014 20:18 It keeps saying that my program produces incorrect solutions. Anyone else is having the same issue? #include <stdlib.h> #include <stdio.h> int main() { int start, change, N, sum; scanf("%d", &N); if (abs(N) <= 10000) { change = N > 1 ? 1 : -1; for (start = 1; start != (N + change); start += change) sum += start; printf("%d\n", sum); } return 0; } #include <iostream> #include <math.h> using namespace std; int main(int argc, char* argv[]) { int N,Sum=0; cout<<"Введите значение"<<endl; cin>>N; if(N>0 && N<=abs(1000)) { for(int i=0;i<=N;i++) { Sum+=i; } cout<<Sum; } if(N<0 && N<=abs(-1000)) { for(int j=0;j>=N;j--) { Sum+=j; } cout<<Sum; } getch(); return 0; } Edited by author 05.07.2013 20:36 Edited by author 05.07.2013 20:38 from the first glance: it's supposed to be 10000, not 1000 The Laplacian matrix does not have always N * M lines/columns. Извените, чо пишу на русском - по другому не умею. По поводу теста №2, в котором на вход подается 0, а правильным решением является пустая строка. Лично мое мнение: результатом должен быть массив длиной 1 с первым элементом равным 1. Объясню: В условии задачи сказано, что входными данными являются число N(длина массива) и элементы этого массива. Предполагается, что N может быть равно 0. Массив поступает в функцию, которая возвращает массив, первым элементом которого является длина входного массива. Из этого можно зделать вывод, что, если на вход задачи может поступить массив, у которого указана длина 0, то и функция при обрабоке этого массива должна вернуть массив длиной 1 с первым элементом равным длинне массива, тоесть 0. После обработки этого массива функцией и получится массив длиной 1 с первым элементом равным 1. Лично я не догадался, что результатом будет пусая строка (пришлось подсмотреть на форуме). Will Timus Online Judge support Nodejs? #include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { double t = 0; double eps; double x, y; cin>>x>>y>>eps; eps=eps*0.001; while(1) { double c = cos(t) - y; double d = sin(sqrt(t)) - x ; if( c*c+d*d > eps/2) t+=0.007; else { break; } } cout<<fixed<<setprecision(5)<<t; return 0; } Can someone tell what is wrong or give some tests?(my mail kilik94@yandex.ru) Thanks in advance! Edited by author 07.12.2013 01:58 Why "> eps/2" ? May be "> eps**2"? How to solve this problem? Edited by author 29.09.2013 08:45 Edited by author 29.09.2013 08:45 I used such variables: map<string,int> id; set<string> list[1003]; map<string,int> mp; vector<string> res; but got TL test 10. Can i get AC with same solution? Yes if instead string use struct{ int num; int row; int poz1; int poz2; }; to have deal with segments of char S[1000][125] to pass test 10 you must do 1) compare hash codes instead of string compare 2) use vectors+sort. In this case vector is way faster than std::set 3) fast I/O. 4) fast list intersection good luck! If you have WA3 try this: 1 3 5 1 4 5 7 Right answer is 1 If you have WA6 try to change sum<k to sum<=k. It helped me. Edited by author 28.01.2014 20:34 There *is* a period of 9973, but not for the given function. Let's denote 9973 as M. ////////////////////////////////////////////////////////////////////////// //In short//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// 1. g(n) is linear by f(n - 1), and g(x, y) = g(x mod M, y), which means we can find such A and B (in O(M)) that f(x + M) = (A * f(x) + B) mod M. 2. Having found such A and B, it's easy to show that for p > 0, f(p * M) = B * (A^(p-1) + A^(p-2) + .. + A^2 + A + 1) mod M. I'm not sure if the last sum can be calculated in O(1), but it surely can be found in O(M). 3. So, we calc A and B, read N, find f(N - N % M) and then iterate till N in O(M), resulting with overall O(M). ////////////////////////////////////////////////////////////////////////// //In detail/////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// ////// //1.// ////// Let's assume we know f(i) and wish to find f(i+1). Easy to see, g(x, y) = g(x mod M, y). This is why, f(i + 1) = g(i + 1, f(i)) = g((i + 1) mod M, f(i)). Let's denote (i + 1) mod M as j. f(i + 1) = g(j, f(i)) = ((f(i) - 1) * j^5 + j^3 – j * f(i) + 3 * j + 7 * f(i)) mod M f(i + 1) = f(i) * (j^5 - j + 7) + (-j^5 + j^3 + 3 * j) mod M f(i + 1) = f(i) * ((j^5 - j + 7) mod M) + (-j^5 + j^3 + 3 * j) mod M Remembering that j = (i + 1) mod M, let us denote U(i) = (j^5 - j + 7) mod M, V(i) = (-j^5 + j^3 + 3 * j) mod M. As a result: f(i + 1) = U(i) * f(i) + V(i) Note that for any i, we calculate U(i) and V(i) in O(1) time. Also note that U(i) = U(i mod M) and V(i) = V(i mod M): f(i + 1) = U(i mod M) * f(i) + V(i mod M) Let's consider some certain x, and let's denote f(x) as X. f(x+0) == X == 1 * X + 0 == (a0 * X + b0) (mod M) f(x+1) == U(0) * f(x+0) + V(0) == (a1 * X + b1) (mod M) f(x+2) == U(1) * f(x+1) + V(1) == (U(1) * a1) * X + (U(1) * b1 + V(1)) == (a2 * X + b2) (mod M) f(x+3) == U(2) * f(x+2) + V(2) == (U(2) * a2) * X + (U(2) * b2 + V(2)) == (a3 * X + b3) (mod M) f(x+4) == U(3) * f(x+3) + V(3) == (U(3) * a3) * X + (U(3) * b3 + V(3)) == (a4 * X + b4) (mod M) ... f(x+M) == (aM * X + bM)) (mod M) Note that aM and bM do not depend on x - this is the key point! Let's denote aM as A and bM as B. Each iteration above needs O(1) time, so we found A and B in O(M), such that for any x, f(x+M) = (A * f(x) + B) mod M ////// //2.// ////// Consider the following sequence f(0 * M) == 0 (mod M) f(1 * M) == A * f(0 * M) + B == B (mod M) f(2 * M) == A * f(1 * M) + B == A * B + B == B * (A + 1) (mod M) f(3 * M) == A * f(2 * M) + B == A * B * (A + 1) + B == B * (A^2 + A + 1) (mod M) ... f(p * M) == B * (A^(p-1) + A^(p-2) + .. + 1) (mod M) Function A^p mod M is periodic by p with period being divisor of M, so we can easily calculate f(p * M) in O(M) time by summing up first M items of the sequence above. Moreover, for this particular problem p (see below) is very small - less than N/M, so we may calculate this sum explicitly. ////// //3.// ////// The most pleasant part. Given N, we set p to N / M, and calculate f(p * M) with the method desribed above. N - p * M < M, so all we have to do left is explicitly apply the initial formula N - p * M times to find f(N). Edited by author 15.02.2006 18:23 that is the best solution i've ever seen ,thank you Can you explain why did you decide that the coefficients aM and bM don't depend on x? That's right I guess, but it's not evident for me. Why g(x,y) = g(x mod M,y) Correct me if I am mistaken but I think this is because U(i) = U(i mod M) and V(i) = V(i mod M). Please give me some more tests. And what is the test number 4? Please, give me some hints and idea. I write bruteForce but i see no hints. Only random 0 and 1. Length of the answer is 2^n + n - 1, it can be constructed with brute-force Thank you. Please, give me more hints. =) Above hint is more than enough to solve it. The only possible latest hint: during BF, when construct a sequence, think how to check in O(1) that the new suffix of length n didn't occur in the sequence before. #include<iostream> using namespace std; int main() { int a,b; cin>>a>>b; cout<<a+b; return 0; } after int main() need "{" #include <fstream> using namespace std; int main() { ifstream fin("INPUT.TXT"); ofstream fout("OUTPUT.TXT"); int a,b; fin >> a >> b; fout << a + b; fin.close(); fout.close(); } поидет ?? Мен агылшынша тiлде белмимын!! How to respond to the tasks in your site? a file or command line? tell me if the command line .. Read FAQ Кай жерде ' read' ? Корсетше мағам .. namespace Project1 { class Programa { static void Main() { Console.Write("Введите первое число: "); int First = Convert.ToInt32(Console.ReadLine()); Console.Write("Введите второе число: "); int Second = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Сумма числа {0} и числа {1} равна {2}", First, Second, (First + Second)); Console.ReadKey(); } } } Edited by author 18.01.2013 23:09 Edited by author 18.01.2013 23:09 or namespace Project2 { class adsf { static void Main() {
int x; int y;
x = Convert.ToInt32(Console.ReadLine()); y = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Сумма числел = " + (x+y));
Console.ReadKey(); } } } #include <iostream> int main() { using namespace std; int a, b, buffer; cin>>a>>b; int *mass=new int[b]; int *deep=new int[33180]; for (int i4=0; i4<b; i4++) { mass[i4]=0; deep[i4]=1200; } for (int i5=b; i5<33180; i5++) { deep[i5]=a; } for (int i6=0; i6<33180; i6++) { for (int i9=1; i9<33180; i9++) { if (deep[i9-1]>deep[i9]) { buffer=deep[i9-1]; deep[i9-1]=deep[i9]; deep[i9]=buffer; } } } mass[0]=a; mass[b-1]=b; for (int i=0; i<b; i++) { for (int i2=1; i2<b; i2++) { if (mass[i2-1]>mass[i2]) { buffer=mass[i2-1]; mass[i2-1]=mass[i2]; mass[i2]=buffer; } } } int sum=0; for (int i3=0; i3<b; i3++) { sum+=mass[i3]; } cout<<sum; delete []deep; delete []mass; return 0; } This solution works 1 second and output 1 if a=1 or b=1, and get AC! ab = raw_input() print int(ab[0]) + int(ab[2]) Yup, I have implemented gradient descent with time cheking only to find it fail on tests 4,5 and then (after some constants manipulations) on test 9, and then just read a forum reply and implemented that "dumb" solution. Edited by author 28.01.2014 02:39 You can use "random" function to produce a letter. I got curious and tested the "random" solution for 100000 times, and 88058 times (which is about 88%) it worked correctly. |
|