Common BoardHello! 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 after 2 days, found DP solution, and AC with 0.046 s. Edited by author 15.08.2012 16:07 I tried to read data string by string and then by characters but in both cases I got Crash(access violation) on 1st test :( Edited by author 18.08.2012 20:30 Dear all, all tests I found in this discussion worked, but when I run my code I do have WA on test 7 (or 13 for another version of my code). Can someone please give a kind of inputs with some test? I checked everything I could think of and it worked. Thank you! Input: 4 4 0 3 0 4 0 0 Output: 0101 Thank you for the answer. The following tests are working, but when I submit I do have WA2. I. 3 2 0 3 0 0 result: 010 II. 4 4 0 3 0 4 0 0 result: 0101 III. 5 2 5 0 3 0 4 0 5 0 0 result:-1 IV. 5 2 3 4 5 0 0 0 0 0 result: 01111 V. 6 2 4 6 0 3 5 0 4 6 0 5 0 0 0 result: 010101 VI. 0 result :-1 I am using bfs, of course with a queue implementation. Hmm, but I used dfs and have no problems :) Maybe I will try also dfs. I still do not understand why bfs would not work (well a little modified). It seems that I have now WA#2. Does somebody knows test #2 (except those written above.)? Thank you. I have got accepted with a version of bfs modified. I also found the problem in my implementation. Once I succeeded for test below and all others from above, I got AC. Thank you for your help. 6 2 3 0 4 0 5 0 6 0 6 0 0 result: 011001
If you have WA15, you should think about the height of the plate and the height of the box. I don't think so. I think about it and I have WA15. |
|