Common Boardimport java.util.*; public class Math{     public static void main(String[] args){         Scanner scanner = new Scanner(System.in);         int a = scanner.nextByte();         int b = scanner.nextByte();         System.out.print(a + b);     } }   Почему Runtime error?? Попробуй nextInt вместо nextByte. В подавляющем большинстве случаев в задачах на тимусе чаще встречаются 4-байтные переменные, чем 1-байтные. Всем привет! Я написал реализацию программы на Java. Проверка выдает Runtime error. Программа принимает n, после чего слушает ввод и после каждого введенного слова выводит ответ. Выглядит это так:   9 0010100011 //мой ввод 001000011  //вывод программы 00010010   //мой ввод 000100101  //вывод программы   Ctrl - C   Скажите, правильно ли реализовал ввод/вывод данных? Спасибо!   Edited by author 30.12.2015 22:15 Да, так можно делать, не ожидать завершения ввода, прежде чем делать вывод. Но без кода не понять, где рантайм. Я точно не уверена, т. к. у меня нет большого опыта в джаве, но возможно, проблема вот здесь while(true) {     a = input();     if (a.length() > 0) {         System.out.println(toSource(a));     } } Как я вижу, программа никогда не выходит из цикла, и в некоторый момент пытается что-то читать после того, как входные данные заканчиваются. Я исправила while(true) на while(in.hasNextLine) (входные данные не закончены, имеется следующая строка) и class на public class (иначе выдаёт compilation error). Теперь получается WA #1. Честно говоря, непонятно почему, вроде на тестовых данных в других ветках обсуждения нормально проходит. Может кто-то более опытный сможет подсказать. Ну уже хотя бы не Runtime. Спасибо. Ввод верный (его несложно подправить и под не Pascal):   const nmax=1111; var  a:array[1..nmax] of char;  n,i,j,len:longint;  ch:char; ..... begin  readln(n);  while not eof do begin   len:=0;   read(ch);   if(ch='0')or(ch='1') then begin       //началось считывание очередного слова    len:=1;    a[len]:=ch;    read(ch);    while(ch=' ')or(ch='1')or(ch='0') do begin     if(ch='1')or(ch='0') then begin      inc(len);      a[len]:=ch;     end;     read(ch);    end;    Solve(len);    readln;                  //перевод строки   end;  end; end. can you find other sequence like this , input = output No, it isn't.   1 2 3 -> 3 2 1 -> 3 2 1   'input = output' when the input sequence is already sorted by non-increasing. Please publish here some tests All test cases invented by me passed but I have got here WA on test 3 i meet the same WA#5.may be the reason is you assume if distance of start and end is less than L3 then cost is C3. but it may be c1+c2 c1+c1 or c2+c2 instead. 3 6 8 20 30 40 7 1 6 3 7 8 13 15 23 //answer: 80
  3 6 8 20 30 40 7 3 6 3 7 8 13 15 23 //answer: 40
  3 6 8 20 30 40 7 2 5 3 7 8 13 15 23 //answer: 60
  1 2 3 1 1000 1000000000 2 1 2 1 //answer: 1
  1 2 3 1 1000 1000000000 2 2 1 1 //answer: 1 all test case passed.but meet WA5 #include<iostream> #include<conio.h> #include<string> using namespace std; char unCAPS(int state, char symbel) {     char out_symb;     if (((int)symbel >= 65 && (int)symbel <= 90) && state ==0)     {         out_symb = (char)(symbel + 32);         return out_symb;     }
      if (((int)symbel >= 97 && (int)symbel <=122 ) && state == 1)     {         out_symb = (char)(symbel - 32);         return out_symb;     }
      return symbel; }   int main() {     char str[10000] = { NULL }, str2[10000] = { NULL };     int state = 1;     cin.get(str, 10000);     for (size_t i = 0; i < strlen(str); i++)     {         str2[i] = unCAPS(state, str[i]);         if ((int)str[i] != 32)         {             state = 0;         }         if ((int)str[i] == 46 || (int)str[i] == 33 || (int)str[i] == 63)         {             state = 1;         }
      }     for (size_t i = 0; i < strlen(str2); i++)     {         cout << str2[i];     }
      return 0; } Ты тестировал локально? Если нет, то попробуй. В  http://acm.timus.ru/help.aspx?topic=cpp в самом конце указано, как пользоваться #ifndef ONLINE_JUDGE (на сервере этот код не выполнится, а у себя на компьютере тестировать удобно). И смотри, нет ли на выводе, например, лишних пробелов в конце или вроде того. You don't need conio.h You should use csting or string.h for strcpy. Did you really try to compile and run it?   You shouldn't use ascii codes. "str[i] == '.'" is better then "(int)str[i] == 46". Why do you think that first non-space symbol in sentence is word? Why not "-"? You should read task carefuly. 2 lines in example is 1 test. You only process first line.   Try this test: 3 1 1000 0 1000 6 100 10 2 5   answer is: 1985.0 I compose n from sums of digits of the numbers: 99999 (sum of digits = 45) 99998 (44) 99997 ..... 99990 (36) 99989 (44) .....   until i gain total sum of digits = n. I take the numbers in such an order because the greatest sums (in average) are in that part of valid range.   I suppose you can start from little numbers but i didn't try. Increasing order causes WA#6. More funny solution without WA: use n for n and so on(recursively) > Increasing order causes WA#6.   But why?! However, decreasing order is more greedy, but still don't know why it works.   p.s. also got 0.046s AC with 100% solution using map<int,list<int>,greater<int> > container and its lower_bound method.   Edited by author 27.10.2011 05:53 thank you for idea that increasing order idea This problem has simple brutforce solution. Just sum all numbers from 1 , while sum <= n Me too.I use c++ because of it's STL, use multimap can slove it   Edited by author 11.11.2012 18:00 It is even enough to start from n, not from 99999.   I guess in that case the solution will be more generic, it'll work for any positive n.   Edited by author 04.04.2010 17:06 here is my way to solve this problem: 1. count sum of digits for every number from 1 to 99999 2. sort then 3. find some unmarked close number and add it to the answer(with binary search) 4. n=n-a[number] =) that's all btw there is no "-1" answer Just take n and decrease it by it sum of digits, keep doing this until n = 0 First observation we need to make is to see that the highest sum of digits within 10^5 has the number "99999" and it's value is 45. This means that if the input number of digits is more or equal than 45 we can use any number and it will always fit.   We want to make everything quickly so it's best to start from numbers with a lot of nines in them.   99999 (sum = 45) 99998 (sum = 44) ... 96742 (sum = 28) 96741 (sum = 27)   We subtract the sum one by one until we are left with a number of digits that's lower than 45.   Second observation is to see that 9+8+7+6+5+4+3+2+1=45 and that there always is a combination of 9,8,7,6,5,4,3,2,1 that You can sum up to any number lower or equal to 45.   That way we end up with something like this: Input: 55 3 99999 9 1   Edited by author 12.07.2016 19:56 #include <iostream> #include <cmath> using namespace std; void main(){     int a[100001];     char s[100001];     gets_s(s);     int max = 0;     for (int i = 0; i <= strlen(s); i++)     {         if (s[i] >= 'A'&& s[i] <= 'Z'){             a[i] = s[i] - 55;             if (max < a[i]){                 max = a[i];             }         }         else{////if digits             a[i] = s[i] - 48;             if (max < a[i]){                 max = a[i];             }         };     };     int k;     long long res;     max++;     bool found = 1;     for (k = max; k <= 36; k++)     {         res = 0;         for (int i = strlen(s) - 1; i >= 0; i--)         {             res = res + pow(k, i)*a[i];         }         if (res % (k - 1) == 0){             found = 0;             break;         }     }     if (found==0){         cout << k;     }     else{         cout << "No solution.";     }     system("pause"); } I think that problem in large numbers in tests, am I right? Edited by author 09.07.2016 22:05   Edited by author 09.07.2016 22:26 According to the description the input can have 10^6 digits this means that the input string can be a million characters long. This will definitely overflow even "long long" :)   There is a solution to this problem described below. They shown a proof that all the calculations that You need to do is summing up the digits. I'm experimenting with a different approach. I try to simulate "pen and paper" division, and get the remainder.   And finally I got AC with my approach.   Edited by author 12.07.2016 14:48     Edited by author 21.05.2017 17:19 See on one iteration of "for": let be x and y on start:x1 and y1. then after each change it'll be for x1 x2...x3; for y1 y2...y3; so you have to find out x3 and y3 through x and y on start(x1 and y1); Something like that x3=y1. Good luck and sorry if my English is not enough good for explaining it) 5 777 313 465 99 1   in the test above, how Daenerys  can win ??? While we can divide: #Daenerys  777 -> 3 heaps (259) - 313 -> can't divide #Stannis  465 -> 3 heaps (155) #Daenerys 99  -> 3 heaps (33) #Stannis  33 -> 3 heaps (11) - 1   -> can't devide ==> Stannis  is the winner 5 777 313 465 99 1   in the test above, how Daenerys  can win ??? While we can divide: #Daenerys  777 -> 3 heaps (259) - 313 -> can't divide #Stannis  465 -> 3 heaps (155) #Daenerys 99  -> 3 heaps (33) #Stannis  33 -> 3 heaps (11) - 1   -> can't devide ==> Stannis  is the winner  99 / 3 = 33 we put 33 3 times in array and can make a move and others too "313" can be divided into three heaps with odd number of nuts like this: "313 = 311 + 1 + 1" It doesn't have to equal number of nuts. +++ bad test I don't know how to use my program at this task I don't understand how the answer can be 15.   Since the first 2 people got 0 correct predictions and the last person got 1 correct prediction, shouldn't the amount paid only be 5? First two people got more then 0 correct predictions because: "four sets of gold medals, four sets of silver medals, and four sets of bronze medals are awarded" dp[i][j] - represents number of staircases with i cubes and with the height of last block j. Answer is dp[n][1] + dp[n][2] + dp[n][3] ... dp[n][n]. can u help me with some algorithm better than dp(which works in O(n^2))   Edited by author 11.07.2016 03:57 At first check all tests with n<=4. If all of them cheked already then try to check all cells for n=8 (1/1; 1/2; 1/3; 1/4; 2/2; 2/3....)and for n=9. Don't be afraid you'll find your mistake on first tests))   Edited by author 10.07.2016 14:33 can someone give me some tips or tests? You can only use both modifiers once during whole process; you can't restock between "take" operations. For example, answer for test   4 208 100 208 100   is IMPOSSIBLE (at least according to my AC program): you can take 208, 100 by using deodorant on 208, but you can't do it twice. #include <iostream> #include <math.h> #include <iomanip>   using namespace std;   int main() {     double a[100000];     int i, n;     cin >>n;     for (i=1; i<=n; ++i)     {         cin>>a[i];     }     for (i=1; i<=n; ++i)     {         a[i] = sqrt(a[i]);     }     for (i=n; i>=1; --i)     {         cout << fixed << setprecision(4) << (a[i]) << endl;     } } Прочитай внимательно графу исходные данные, у тебя первое число задаёт количество чисел которое ты будешь вводить, а там такого нету   What is the criterion of optimality of the partition ? Minimum of maximum of 4 numbers, read problem Also, instead of «The i-th number in the j-th row» there should be «The j-th number in the i-th row» (unless, judging by the title, this is intended, haha)  |  
  |