| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| решение без сортировки, на основе ассоциативного массива, где индексами выступают баллы ACCEPTED | Иван | 1100. Таблица результатов | 5 июн 2014 17:44 | 1 |
Edited by author 05.06.2014 17:45 Edited by author 05.06.2014 18:23 Edited by author 05.06.2014 18:41 Edited by author 05.06.2014 18:53 |
| Help in Java 1.7 | Axmadjon | 1213. Тараканы! | 5 июн 2014 16:20 | 1 |
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.Scanner; public class Test { public static void main(String[] args) throws IOException { new Test().solve(); } private static Scanner s = new Scanner(System.in); static int n = 0; void solve() throws IOException { String input = null; String[] strArray = new String[30]; while (true) { input = getString(); if (input.equals("#")) { break; } else { saveItToArray(strArray, input); } } checkOutIdentical(strArray); System.out.println(n - 1); } private static String getString() throws IOException {
String input; input = s.nextLine(); return (input); } void saveItToArray(String[] strArray, String input) { boolean isDash = false; for (int i = 0; i < input.length(); i++) { if (input.charAt(i) == '-') { strArray[n++] = input.substring(0, i); strArray[n++] = input.substring(i + 1, input.length()); isDash = true; break; } else { isDash = false; } } if (!isDash) { strArray[n++] = input; } } void checkOutIdentical(String[] strArray) { int count = 0; count = n; for (int i = 1; i < count; i++) { for (int j = i - 1; j >= 0; j--) { if (!strArray[i].equals(" ") && !strArray[j].equals(" ") && strArray[i].equals(strArray[j])) { strArray[i] = " "; n--; } } } } } |
| Why Runtime error (access violation) ? | Kimbizin | 1423. Басня о строке | 4 июн 2014 22:18 | 1 |
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_READ 250000 #define MASIVE(a, b) (b *) malloc(sizeof(b *)*(a)) #define STRING(a) MASIVE((a), char); #define R_CONCAT(T,S,A) strcat(A, T); \ strcat(A, " "); \ strcat(A, S); \ int * Z_simple(char * str, int len) { int * z = MASIVE(len, int); for (int i = 1; i < len; i++) { int * val = z + i; *val = 0; for (int j = 0; i + j < len; j++) { if (str[i + j] != str[j]) { break; } (*val)++; } } return z; } int * Z(char * str, int len) { int * z = MASIVE(len, int); int l = 0, r = 0; for (int k = 1; k < len; k++) { if (k > r) { l = k; int pos = 0; while (k + pos < len && str[pos] == str[k + pos]) { pos++; } if (pos == 0) { r = l; z[k] = 0; } else { r = k + pos - 1; z[k] = pos; } } else { int m = k - l; int b = z[l] - m; if (z[m] < b) { z[k] = z[m]; } else { int pos1 = b; int pos2 = k + b; int pos = 0; while(pos2 + pos < len && str[pos1 + pos] == str[pos2+pos]) { pos ++; } if (pos != 0) { l = k; r = pos2 + pos - 1; z[k] = b + pos; } else { z[k] = b; } } } } return z; } int main() {
int n; int result = -1; scanf("%d", &n); char * T = STRING(n); char * S = STRING(n); scanf("%s%s", T, S); int len_N = 2*n + 1; char * N = STRING(len_N);
R_CONCAT(T,S,N); int * z = Z(N, len_N); z = z + (n + 1); for (int i = 0; i < n; i++) { if (z[i] == n - i) { int k = z[i]; int b = 0; for (int j = 0; j < i; j++) { if (T[k + j] != S[j]) { b = 1; break; } } if (b == 0) result = i; break; } } printf("%d", result); } |
| WA1 | Kirill Luchikhin | 1269. Антимат | 4 июн 2014 19:30 | 1 |
WA1 Kirill Luchikhin 4 июн 2014 19:30 Edited by author 04.06.2014 19:39 |
| AC program DP idea | lakerka | 1117. Иерархия | 4 июн 2014 18:03 | 1 |
Main idea: Number tree levels from bottom to top like: 0th, 1st, 2nd ... We can traverse the whole tree, but it would take at most 2^31 vertexes to visit. I call [traversing the whole tree]: going from bottom left vertex to bottom right vertex of the tree. So we can observe that we can skip traversing some part of the tree. Since traversing tree A of level AL is the same as traversing two smaller trees with levels (AL-1) + 2*(cost to go from bottom to top (highest) vertex of tree A). Example: +-----+4+----+ + + ++2++ ++6++ + + + + 1 3 5 7 To traverse tree A (from 1 to 7) with level 2 is the same as traversing tree B (from 1 - 3) with level 1 twice and adding costs: from 3 to 4, from 4 to 5. Let's call m[level of tree] = min cost to traverse tree with such level from bottom left to bottom right of tree. Then we could find out what is traversal cost for each tree with arbitrary level like: for 1..MAX_LEVEL_OF_TREE: m[i] = 2 * m[i - 1] + 2 * (i - 1); We traverse tree from left to right. We shall call destination vertex d, current vertex c and level of tree where we can find c: cl. Initially c is vertex we start from. We know that if we are standing at c, vertex number that is one level above c is: upRight = c + 2^cl. So if d >= upRight we have to go to upRight vertex, because here: [c ; upRight-1] is no destination vertex. Similarly we know that if we are standing at c, vertex number that is at 0th level to the right of c is: downRight = c + 1. We should go to downRight if: d < upRight. So finally: cost(v) - cost by going directly from bottom vertex to v. Example: cost(8) = 2, cost(16) = 3. We go up right if d >= upRight : [whole cost] = [whole cost] + m[cl - 1] + cost(c) + cost(upRight) c = c + 2^cl We go down right if if d < upRight: [whole cost] = [whole cost] + cost(c) c = c + 1 Complexity similar to log(n)^2 |
| Wrong Answer [PASCAL] | Armstrong091 | 1001. Обратный корень | 4 июн 2014 11:20 | 5 |
procedure do; var n:int64; begin if eof then exit; read(n); do; writeln(sqrt(n):0:4); end; begin do; end. I think this problem is quite easy. Please tell me why it gives wrong answer, thank you! var a:real; begin read(a); writeln(sqrt(a):0:4) end. why is my answer wrong?? 1.Файл входной не превышает 256 кб 2. В обратном порядке выводишь ты числа I think your input problem. But it is easy to correct it! procedure do; |
| where is mistake? | Vadim_Egorov | 1869. Новогодний круиз | 4 июн 2014 08:54 | 1 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1869_2 { class Program { static void Main(string[] args) { Random random = new Random(); int rand; int i, j, k, max;
int N = int.Parse(Console.ReadLine()); int[,] A = new int[100, 100]; for (i = 0; i <N; ++i) for (j = 0; j <N; ++j) { if (i == j) A[i, j] = 0; else { rand = random.Next(0, 1000); A[i, j] = rand; } } for (i = 0; i < N; i++) for (j = 0; j < N; j++) { if (A[i,j] == 0) continue; // Vladi -> Moscow if (i < j && j - i > 1) { for (k = i; k < j; k++) { A[k,k + 1] += A[i,j]; } } // Moscow -> Vladi else if (i > j && i - j > 1) { for (k = i; k > j; k--) { A[k,k - 1] += A[i,j]; } } }; // get maximum for each pair of stations max = 0; for (i = 0; i < N - 1; i++) { if (Math.Max(A[i,i + 1], A[i + 1,i]) > max) { max = Math.Max(A[i, i + 1], A[i + 1, i]); } } if (max % 36 == 0) { max /= 36; Console.WriteLine(max); } else { max /= 36; max = max + 1; Console.WriteLine(max); } //Console.ReadKey(); } } } |
| For whom, who get WA 6,7 | Gleb_Kazantaev(NNSTU) | 1823. Идеальный газ | 4 июн 2014 03:04 | 1 |
double res = (bpi*bvi)/(bti*R); cout << "n = "; if(res < 1) printf("%.0f", res); else printf("%.6f", res); When res (n) < 1 u should cout 0 else u should cout number with an error. Good Luck! |
| It's greedy~ | ZLqiang | 1203. Научная конференция | 4 июн 2014 00:54 | 7 |
Greedy can pass this problem quickly. Edited by author 11.11.2012 02:32 of course greedy is correct. First sort the data according to finish time,than starting time. Suppose I have sorted the data by finish time and then by start time. Now what are you doing with the data? Are you binary searching over the data for each of the N events of the array? Please specify more. Useful test: 3 1 6 2 3 4 5 Answer: 2 Why won't greedy pass? Exactly this problem is used to teach greedy in most of all text books(all I have ever read). |
| easy solution | sonamon | 2011. Длинное условие | 4 июн 2014 00:09 | 1 |
if you deal with n>5 and n<=5 cases separately. The former does not require any factorial calculation |
| WA on TEST#18 in G++ but AC in VC++ | __dynamic | 1519. Формула 1 | 3 июн 2014 21:26 | 3 |
That's magical and I don't think there's any undefined behaviors etc. in my code.. Those who are puzzled in ridiculous WA may try to change the compiler. Code pasted here:fayaa.com/code/view/28059/ Maybe you use "%lld" to output the answer? I think the compiler in Ural may be based on Windows. |
| crc16 hash table | Иван | 1563. Баяны | 3 июн 2014 17:52 | 1 |
crc16 hash table is not working on test 7. someone solved using hash tables? |
| Thanks! | Gorb_Roman | 1196. Экзамен по истории | 2 июн 2014 21:54 | 1 |
Thanks! Gorb_Roman 2 июн 2014 21:54 |
| AC program test cases | lakerka | 1036. Счастливые билеты | 2 июн 2014 19:58 | 1 |
10 0 1 2 1 0 30 95 0 3 4 36 3 6 100 10 30 1657615050256 15 30 5988336077235600 20 100 475696100826892995150152084506564 50 300 3660144008320861404705392514284143308670326732628084621145897204106027006076468826991924409 |
| advice. pascal | Evgeniy_Rus | 1020. Ниточка | 1 июн 2014 20:08 | 1 |
тем, у кого не получилось, советую поменять операции writeln и readln на write и read. Тоже не понимал, почему не получается, испробовал кучу входных данных - все было правильно. но программа давала WA в первом же тесте. Однако, как только сделал так, как указал выше, все сразу получилось. Edited by author 01.06.2014 20:08 Edited by author 01.06.2014 20:08 |
| WA # 5 | ROHAN GULATI | 1018. Двоичная яблоня | 1 июн 2014 05:46 | 3 |
WA # 5 ROHAN GULATI 17 фев 2013 22:59 Can anyone please tell me what is test case #5....My code is giving the correct ans for all the tests in the forum.. I got WA#5. the reason is I forgot to count the apples in the branches to children nodes...hope it helps. same here man , did you find any bug?? |
| WA test case 5 | surajkvm007 | 1018. Двоичная яблоня | 1 июн 2014 05:42 | 2 |
can anyone please explain what test case 5 is i have tried many times but iam not able to pass it |
| Is there any wrong in my code for this problem | AKdeBerg | 1000. A+B Problem | 1 июн 2014 02:02 | 4 |
#include<iostream> using namespace std ; int main() { int a, b ; cout<<"Plz enter two numbers: "<<'\n' ; cin>> a >> b ; cout<<"Here is your output: "<< a + b <<'\n' ; return 0 ; } what's the wrong!!! I've written this code in c++ and submitted under visual c++2010 but they don't accept it..why????? Because you write some text in output. Remove all text. #include<iostream> using namespace std ; int main() { int a, b ; cin>> a >> b ; cout<< a + b ; return 0 ; } Like this thanks for your answer :) |
| Подcкажите (Help me, please) | Alexandr | 1001. Обратный корень | 1 июн 2014 00:18 | 1 |
Что не так с моей прогой? На третьем тесте дает не правильный ответ. (What is wrong with my program? It is wrong on the 3rd test.) #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main(void) { vector<long double> b; vector<long double>::iterator it; long double tmp; while(!cin.eof()) { cin >> tmp; b.insert(b.end(), tmp); } int ololo; cout.setf(ios::fixed); for (ololo = b.size()-2; ololo >= 0; ololo--) cout << sqrt(b[ololo]) << endl;
system("PAUSE"); return 0; } Edited by author 01.06.2014 00:19 |
| No subject | Svetlana | 1880. Собственные числа Psych Up | 31 май 2014 22:41 | 1 |
Edited by author 10.06.2014 00:57 |