Common BoardHI I seem to be getting WA 5 everytime. Any ideas or hints on the test? Here is what i do: if start is 1 cout 1 for i=stop to start and for odd numbers for j= 2 to floor(sqrt(i)) add the divisors if it is a primeNumber cout<<i cout the number with least triviality. in test5 I = J. Try this 2 2 aswear 2. Edited by author 17.08.2012 14:07 #include <stdio.h> unsigned long get_an(unsigned long n); int main(){ unsigned long n[10],i; for(i=0; ; ++i){ scanf("%ld", &n[i]); if(!n[i]) break; n[i]=get_an(n[i]+n[i]%2-1); } for(i=0; n[i]; ++i) printf("%ld\n", n[i]); return 0; } unsigned long get_an(unsigned long n){ if(n==1) return 1; if(n%2) return ( get_an((n-1)/2)+get_an((n-1)/2+1) ); else return get_an(n/2); } I have WA #30, but on all tests and on same tests my solution give right answers. Can be there others tricks? wondering, how can executing time = 0.001 sec be gained? or at least 0.015? Which struct dictionary should have? As for me, I used lower_bound to find out needed word in dictionary (::vector) in my solution and got 0.041 sec time (memory usage is not so interesting) 0.001 sec is impossible now. Hello! The code works correctly. Checked on many examples. Most likely something with input-output. Prompt, where it is wrong and how it is better to make fraction input? Code C++ Sorry for Russian comments //структура дроби struct Fractional { //объявление целой части, числителя и знаменателя long long intPart, numerator, denomerator; } _oneFract, _twoFract, _result; //функция считывания дроби Fractional ReadFractional() { Fractional _fract; //переменная _razdel определяет, что ввели: только целую часть, только дробную часть или целую и дробную часть char _razdel; //считываем первое число scanf("%lld%c",&_fract.intPart, &_razdel); //считываем разделитель после первой цифры: если нажат Enter, то число без дробной части, //если слеш, то только дробная часть, если пробел то и целая и дробная части присутствуют if (_razdel == '\n') { _fract.numerator = 0; _fract.denomerator = 1; } else if (_razdel == ' ') { //Считываем дробную часть scanf("%lld/%lld%*c", &_fract.numerator, &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; } else if (_razdel == '/') { //Считываем знаменатель scanf("%lld%*c", &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; _fract.numerator = _fract.intPart; _fract.intPart = 0; } //Сбрасываем входной поток fflush(stdin); return _fract; } It is not clear at least 2 points: 1) "The output should contain the maximal total rating of the guests." President is the host, not a guest, so his rating is excluded. (?) 2) As the party is the president's anniversary he cannot absent. (?) Am i right? If not, correct the condition please. Answers to questions 1) President's rating should be included if he goes 2) President may not be at a party 3) Noone may go to the party P.S. I'm not an admin :) Ac!!!! 0.031 s. How to solve it? What idea? my be need to delete this link :)) import java.util.Scanner; public class my9 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Введите n"); int n=sc.nextInt(); int s=0; if ((n>0) & (Math.abs(n)<=10000)) { for (int i=1;i<=n;i++) s=s+i; } else if ((n<=0) & (Math.abs(n)<=10000)) { for (int i=n;i<=1;i++) s=s+i; } System.out.println(s); } } Убери строку : System.out.println("Введите n"); Можно вывести только ответ. public class Buttons { public static void main(String[] args) { //convert parameter into int int N = 0; try { N = Integer.parseInt(args[0]); } catch(NumberFormatException ignore) {} //find L for(int i = 3; i < Math.sqrt(N); i++) { if(N%i == 0) { System.out.println(i-1); System.exit(1); } } System.out.println(N-1); } } P.S. On my computer it works perfectly Numbers are read from stdin Please help me! I think the problem with the input / output. post the code sorry for the Russian comments. INPUT //структура дроби struct Fractional { //объявление целой части, числителя и знаменателя long long intPart, numerator, denomerator; } _oneFract, _twoFract, _result; //функция считывания дроби Fractional ReadFractional() { Fractional _fract; //переменная _razdel определяет, что ввели: только целую часть, только дробную часть или целую и дробную часть char _razdel; //считываем первое число scanf("%lld",&_fract.intPart); //считываем разделитель после первой цифры: если нажат Enter, то число без дробной части, //если слеш, то только дробная часть, если пробел то и целая и дробная части присутствуют scanf("%c", &_razdel); if (_razdel == '\n') { _fract.numerator = 0; _fract.denomerator = 1; } else if (_razdel == ' ') { //Считываем дробную часть scanf("%lld/%lld", &_fract.numerator, &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; } else if (_razdel == '/') { //Считываем знаменатель scanf("%lld", &_fract.denomerator); if (_fract.denomerator == 0) _fract.denomerator = 1; _fract.numerator = _fract.intPart; _fract.intPart = 0; } //Сбрасываем входной поток fflush(stdin); return _fract; } OUTPUT if (_result.intPart == 0) { if (_result.numerator == 0) { printf("0"); } else { printf("%lld/%lld", _result.numerator, _result.denomerator); } } else if (_result.numerator == 0) { printf("%lld",_result.intPart); } else { printf("%lld %lld/%lld",_result.intPart, _result.numerator, _result.denomerator); } The answers are checked and correct Edited by author 15.08.2012 17:22 #include<stdio.h> int main(void){ long n,m,i,j; int flag; int A[50001],B[50001]; scanf("%ld",&n); for(i=1;i<=n;i++) scanf("%d",&A[i]); scanf("%ld",&m); for(j=1;j<=m;j++) scanf("%d",&B[j]); flag=0; for(i=1;i<=n;i++) for(j=1;j<=m;j++) if(A[i]+B[j]==10000) flag=1; if(flag) printf("YES"); else printf("NO"); return 0; } not an optimal algo... O(n^2), this problem can be solved with O(n+m) you should think a little more. If you need code, send an email on andrewshmig@gmail.com Edited by author 06.05.2012 00:27 or u can use BinarySearch to search second value. for example in the first test: 1) u take -175 value, 2) try to find 10175 in second list (using binary search) (because -175 + 10175 == 10000) ... good luck! Edited by author 08.05.2012 00:20 >not an optimal algo... O(n^2), this problem can be solved with O(n+m) This problem can be solved with O(n). ) Edited by author 02.06.2012 20:52 Use the associative containers you can use HashSet, it's faster use the two-pointers method or boolean set. It's enough fast for this problem. if det(A) == 0 , what should I do ? If A - is not square matrix ( i.e. k != n ), how to calculate det(A) ? If so, please send one to ysymyth@gmail.com please! #include <stdio.h> int p,t,n,m; int main() { scanf("%d%d%d%d",&p,&t,&n,&m); if (p<2 || p>10000 || t<2 || t>200 || (t&1) || n<1 || n>10 || m<1 || m>100) return 1/(p-p); return 0; } This program gets "Crash (integer division by zero)" at test #1. http://acm.timus.ru/status.aspx?space=1&num=1526You are right, m = 0 in the 1st test. This limitation in the problem statement is fixed now. But there is a division by zero in his code! Sandro, why did you delete my post? Because the solution of Yermak is a input validator. If the system verdict on some test is Crash (division by zero), then this test is incorrect. If the test is correct, system verdict should be Wrong Answer. Sandro, look at this line of his code! There is a division by zero if condition is true, because p-p = 0! if (p<2 || p>10000 || t<2 || t>200 || (t&1) || n<1 || n>10 || m<1 || m>100) return 1/(p-p); Edited by author 13.08.2012 11:55 Captain Obvious to the rescue! Noob, oh, i understand. Edited by author 14.08.2012 00:04 is graph just full on 49 test? probably nop , cose i test prog on full 2000 less then .1sec |
|