Common Board#include <iostream> #include <conio.h> using namespace std; void find(int j, int i, int &k1,int &k2) { if (j==i+1) return; else { int buf = k1; k1 = k1 + k2; k2 = buf; find(j-1,i,k1,k2); } } int main() { long long Fi, Fj, f1,f2, f3; int i,j,n; cin>>i>>Fi>>j>>Fj>>n; if (j==n) {cout<<Fj<<endl; return 0;} if (i==n) {cout<<Fi<<endl; return 0;} if (i<j) { int buf = i; i = j; j = buf; buf = Fi; Fi = Fj; Fj = buf; } int k1 = 1, k2 = 1; f1 = Fj; if (i!=j+1) { find(i-1,j,k1,k2); f2 = (Fi - k2*Fj)/k1; } else f2 = Fi;
int lim; if (j<0) lim = n - j -1; else if (j == 0 ) lim = n; else lim = n - j +1; for (int count = j +1; count < lim; count++) { f3 = f1 + f2; f1 = f2; f2 = f3; } cout<<f3<<endl; return 0; } I think I have correct solution.(DP) but i got WA#11. pls give some tests. Edited by author 29.01.2007 21:21 [((((((((((((((((((((()))))))))]))))))))))))](((((((((((((((((((((((((((]))))))))))))))))))))))))))) AC answer [((((((((((((((((((((()))))))))[]))))))))))))]((((((((((((((((((((((((((([]))))))))))))))))))))))))))) Edited by author 30.01.2007 00:46 Thank you, Anton! Your test allows to debug and avoid WA as well as TLE. using System.IO; using System; class Program { static void Main() { int size = Int32.Parse(Console.ReadLine()); int[,] arr=new int[size,size]; int count=1; for(int x=size;x>=0;x--) { int y=0; int xx=x; bool exc=false; while(!exc) { try { arr[xx,y]=count; count++; xx++; y++; } catch { exc=true; break; } } }
for(int y=1;y<=size-1;y++) { int x=0; int yy=y; bool exc=false; while(!exc) { try { arr[x,yy]=count; count++; x++; yy++; } catch { exc=true; break; } } }
for(int x=0;x<size;x++) { for(int y=0;y<size;y++) { Console.Write(arr[y,x]+" "); } Console.WriteLine(); }
} } Can Anyone give me some hints for test 3, I've been working on it for 3 days but still got test 3. I give the right answers for all the tests on forum Try this test 1 1 499 999 999 answer is 3. 499 999 999 = 691*723589 The spaces shouldn't be there in the last number by the way. import java.io.BufferedReader; import java.io.InputStreamReader; public class AB { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(reader.readLine()); int b = Integer.parseInt(reader.readLine()); System.out.println(a+b); } } У меня такое же решение. Тоже не принимает... Numbers are located at the same line. So, first call of readLine() give you "a b", and second - null. I got WA at #4 by using int type but got AC by using long long I don't understand... I think the max of date is 1e6(maybe n=1e4 and every ti=100, in this way the sum time is 1e6 and it's max) Am I wrong? Who can tell me plz Edited by author 15.03.2015 21:47 Здравствуйте, уважаемые администраторы! Я очень давно изучаю язык Action Script принадлежащий компании Adobe. У меня созрел такой вопрос: Вы добавите поддержку языков Action Script или отодвините всех программистов этой отрасли? Can someone tell me the test case 2 please. I am new in here and I need some help with 1017. Staircases. Edited by author 14.03.2015 15:34 Edited by author 14.03.2015 15:34 What may it be? i've try any test i can think and any test in other discussins,but still WA #11. I tested : ------- WHAT ARE YOU DOING? - I AM EATING. - really? -Yes,(new line) REALLY! - ok, i KNOW. i TRUST YOU. ------- and my program output : ------- What are you doing? - I am eating. - Really? -Yes, really! - Ok, i know. I trust you. ------- I don't know what's wrong, help, please. It must be "i trust you." not "I trust you" For my first try I wrote this: def sum_of_digits(n) sum = 0 while (n > 0) sum += n % 10 n /= 10 end sum end num_digits = gets.chomp.to_i exponent = num_digits/2 divisor = 10**exponent limit = (10**num_digits) - 1 total = 0 0.upto(limit) do |cur| upper = cur / divisor lower = cur % divisor total += 1 if sum_of_digits(upper) == sum_of_digits(lower) end puts total # eof For 2, 4 and 6 digits it got the requisite answers of 10, 670, and 55252. There was a bit of a pause while it crunched away at the 6-digit case, though. For 8 digits it … well, I let it run and went to do something else. Then I had the bright idea to time it (on mac OS X, using the time command): 4816030 real 1m42.596s user 1m34.222s sys 0m1.837s The right answer, but the last time I checked, one minute anything was greater than two seconds. What to do? It’s pretty clear that calling sum_of_digits a bunch more times than necessary is the biggest problem. For try #2, I precomputed the sums and stuffed them into an array, and indexed the array in place of calling sum_of_digits in the main loop. Here’s the result: time ruby lucky.rb < t8.txt 4816030 real 0m19.176s user 0m18.017s sys 0m0.313s A better than 80% speedup. Most times I would kill for that, but I still need to lose 95% of the remaining run time. How to do it? I checked … initializing the array of sums takes virtually no time, even if I write out the entire array contents to a file. So the main loop is killing me, and unfortunately I need a dramatic change of algorithm but I don’t see one. So … 1. Recode in C or C++ 2. Hell if I know Taking option 1, I got Accepted, with run times around 1.1 seconds or so for 8 digits. It's a straightforward translation to C++, very brute force. Try this test: -1 -1 1 Answer: 0.00 0 0 Solved it with time of 0.5 sec and using "Trie" where I keep the name of each directory as a node. Write me novopashinwm@mail.ru Give me some input values with answers, please, so I could find out, what's wrong. if(s.equals("Blue")|| s.equals("blue")) if(s.equals("Red") || s.equals("red")) if(s.equals("Yellow") || s.equals("yellow")) Can anybody explain the combinatorial approach of this problem ??? Greetings the solution is very simple, combinatory isn't needed ;) I think it is coz brute force would be a good pain in ass with n > 9. But if u find a general solution with combinatorics it would be very efficient. I could not find one, though. import java.io.*; import java.lang.*; import java.util.*; public class MathSqrt { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); double[] array = new double[4];
for(int i = 0; i < array.length; i++) { array[i] = sc.nextDouble(); }
for(int i = array.length - 1; i >= 0 ; i--) { double b = Math.sqrt(array[i]); System.out.println(b); }
} } Edited by author 18.02.2015 17:39 Edited by author 18.02.2015 17:39 Why length of your array is 4? It's acceptable to the first test, but there is not a certain amount of numbers in the task. idea...! Hint: A string is palindrome if (and only if) its "RIGHT to LEFT" hash and "LEFT to RIGHT" hash are the same. Also for "Change" queries you need to use some data structure, such as Fenwick Tree or Segment Tree. Edited by author 06.03.2015 14:26 Edited by author 06.03.2015 14:26 |
|