Общий форум1000 13 0 10 14 12 14 9 12 1 0 9 9 16 14 14 10 9 0 9 14 14 14 14 13 13 15 10 14 14 13 14 0 14 9 13 0 7 15 13 9 1 1 0 14 9 10 10 10 14 0 14 12 10 14 0 14 1 13 11 6 10 0 9 0 12 4 9 9 4 6 10 14 4 7 7 14 15 13 13 14 14 12 1 14 6 14 14 16 4 14 16 0 0 16 7 10 12 10 12 14 7 10 14 14 7 10 14 14 13 9 9 0 13 14 15 9 9 9 14 10 1 9 0 14 9 9 10 16 10 9 14 13 13 12 0 14 4 14 9 7 13 13 13 10 9 14 0 13 12 11 4 14 1 4 0 1 9 14 14 14 10 10 0 10 14 0 12 10 0 16 16 15 9 6 0 16 14 1 14 0 9 16 7 14 10 10 16 8 10 13 14 10 14 7 13 7 14 16 4 12 9 14 14 14 1 9 14 15 10 0 13 13 14 7 14 14 16 9 10 12 12 13 9 16 7 16 9 13 7 13 0 14 9 14 12 0 10 0 9 7 9 12 0 14 9 14 16 16 16 10 13 1 0 13 13 16 14 0 14 10 10 13 0 14 14 10 7 14 0 5 13 16 14 12 10 1 1 14 14 13 14 0 13 14 16 0 9 10 10 14 10 13 14 7 0 9 14 7 16 7 6 1 9 7 14 14 1 15 11 9 16 0 14 12 14 9 9 7 14 12 0 7 10 0 14 12 14 1 9 14 10 14 14 9 13 0 14 1 0 9 12 14 14 14 0 13 13 16 15 9 0 14 7 7 0 13 14 14 9 8 14 14 10 14 10 10 13 10 4 4 12 16 12 14 14 11 4 7 12 14 4 0 14 10 16 14 7 7 8 13 16 7 9 1 1 13 8 13 9 0 16 10 1 10 7 15 13 14 14 14 10 1 9 14 14 4 14 16 1 14 8 16 9 14 13 14 0 14 7 14 9 15 10 10 13 14 9 9 0 16 13 13 1 16 7 1 14 7 14 10 0 14 13 15 9 13 10 12 14 10 16 13 14 14 13 10 16 16 14 14 14 14 10 0 13 10 4 14 7 13 9 16 11 13 0 4 10 15 14 14 0 0 13 0 14 14 14 13 16 0 1 13 14 0 9 16 0 16 10 16 9 0 0 13 0 7 16 14 8 13 16 14 13 0 14 9 16 9 13 14 14 14 14 0 9 7 10 0 12 13 16 9 9 14 13 14 1 14 13 14 12 0 13 7 15 15 9 14 12 0 10 13 14 4 16 14 14 12 14 0 9 12 9 14 7 10 1 1 13 10 0 14 9 15 16 15 16 14 12 14 0 12 14 1 12 12 14 0 5 14 14 12 14 16 16 1 6 14 13 8 10 10 13 16 10 14 16 13 1 12 10 14 13 16 10 13 15 7 13 12 0 4 14 1 0 0 16 14 7 9 9 10 16 13 3 4 9 12 7 13 9 12 4 14 15 10 14 7 14 1 14 14 16 12 13 0 0 14 16 14 14 10 8 14 13 14 13 14 0 7 10 0 10 14 10 12 16 16 13 7 12 10 14 14 14 9 7 10 7 13 13 12 14 9 14 12 16 6 7 14 9 14 13 10 0 16 0 14 14 10 15 6 9 14 10 9 10 10 1 14 15 10 14 14 14 1 14 14 14 14 16 15 16 14 6 9 14 13 10 10 12 9 14 16 10 12 16 0 10 14 16 10 14 0 0 7 8 0 13 16 10 14 14 7 0 0 11 15 15 14 13 10 16 12 16 15 16 14 13 4 13 14 14 5 7 0 11 0 13 16 1 13 16 14 14 16 16 16 0 14 10 14 6 14 16 14 13 14 14 16 13 9 14 14 1 9 16 14 12 14 13 14 15 7 14 8 14 13 9 14 7 0 13 1 15 16 0 10 13 14 12 14 14 0 10 7 13 13 13 8 14 9 10 16 7 8 14 14 16 13 7 16 7 9 13 16 14 14 12 0 13 13 9 9 8 15 14 14 14 13 14 13 13 16 14 0 14 16 13 14 8 1 1 1 9 14 9 16 10 14 14 8 0 0 9 6 13 9 0 7 15 8 9 0 14 0 14 14 9 14 12 13 16 14 3 10 14 10 14 11 1 14 14 9 9 9 0 16 0 7 0 16 14 9 14 9 13 14 16 0 0 9 16 14 14 14 10 9 14 1 9 9 14 8 11 15 0 14 11 14 14 0 7 0 14 1 9 14 14 14 14 14 8 16 0 10 0 7 8 14 16364 thanks This test is incorrect, because all a[i]>0. Please, add a comma after "digits" in the phrase "an amount of valid K based numbers, containing N digits, modulo M". I decided "modulo M" is related to "K based numbers", but it's related to "an amount". #include <iostream> using namespace std; struct duy{ long long x; int y; }; int n,x,last[1001]; long long y; duy m[100001]; char s[5]; int main() { cin.tie(NULL); cout.tie(NULL); cin>>n; for(int i=1; i<=n; i++){ cin>>s>>x; if(s[1]=='U'){ cin>>y; m[i].x=y; m[i].y=last[x]; last[x]=i; } else{ cout<<m[last[x]].x; last[x]=m[last[x]].y; } } } By task description, B is an integer (0 ≤ B ≤ 10^9). So "int x", not "long long x". But it shouldn't be enough. Please estimate (or just type from local run) sizeof(duy) and sizeof(m). Then read task memory restriction. Assume that even "empty main()" program spends about 100 Kb (see successful runs of "1000 A+B" problem for your compiler). In this case duy can hold not only one x, but bucket - ~30 values for example. More, 30 bits are required to save B. So it's possible to save 32 values into "int x[30]" array. Edited by author 10.03.2017 15:50 On Java I reccomend to use ArrayList instead Stack. It saved me about 0.4 sec. Edited by author 10.03.2017 00:06 Что за 4 тест??? не могу понять, где что неправильно... n=1 Thank you so much!!!!!!!!!!!!!!!!!!!! Without your kind answer I may never know why I was wrong!! Не понимаю где ошибка. Занимаюсь в целом программированием 3 недели (как хобби) Проверял на исходном примере и на примерах, которые нашел на форуме. Ответы верны. Сюда загружаю выдаёт ошибку. example = {'i' : 1, 'j' : 1, 'a' : 2, 'b' : 2, 'c' : 2, 'd' : 3, 'e' : 3, 'f' : 3, 'g' : 4, 'h' : 4, 'k' : 5, 'l' : 5, 'm' : 6, 'n' : 6, 'p' : 7, 'r' : 7, 's' : 7, 't' : 8, 'u' : 8, 'v' : 8, 'w' : 9, 'x' : 9, 'y' : 9, 'o' : 0, 'q' : 0, 'z' : 0} while True: number = input() if int(number) == -1: break num_words = int(input()) words = {} k = 500 for i in range(num_words): word = input() if len(word) < k: k = len(word) key_word = "" for a in word: key_word += str(example.get(a)) words[int(key_word)] = word answer = [] loser = "" while True: copy = number[len("".join(answer)):] x = len(copy) while x >= k: if int(copy[:x]) in words.keys(): if words[int(copy[:x])] != loser: answer.append(words[int(copy[:x])]) copy = copy[x:] x = len(copy) + 1 x -= 1 if len(answer) == 0: break elif len("".join(answer)) != len(number): loser = answer.pop() elif len("".join(answer)) == len(number): break if len(answer) == 0: print("No solution.") else: ans = " ".join(answer) print(ans) 12345 5 iad i adgk g k -1 should print "i adgk" instead of "iad g k" Ребята, если не сложно, подскажите, почему здесь используем именно Console.In.ReadToEnd() вместо привычного Console.ReadLine() ? Edited by author 26.01.2017 19:15 there can be several numbers in each line. that's why we fistly have to read all the input data and then parse it Edited by author 04.03.2017 21:51 Plesae! Give me some tests for check my program. 10 1 2 3 4 5 6 7 8 9 0 1 1 So what is the answer ? Is it 45 0 ? Yes, it should be "45 0". #include<iostream> using namespace std; int main() { int CityCount, RoutesCount; cin >> CityCount; int *Road = new int[(CityCount - 1)*2]; //Roads for (int i = 0; i < (CityCount - 1)*2; i++) { cin >> Road[i]; }
cin >> RoutesCount; int *Route = new int[RoutesCount*2]; //Routes for (int i = 0; i < RoutesCount*2; i++) { cin >> Route[i]; } //Road Matrix int j = 0; int **RMatrix= new int*[CityCount]; for (int i = 0; i < CityCount; i++) { int *LineofMatrix = new int[CityCount]; for (int i = 0; i < (CityCount - 1) * 2; i += 2) { if (Road[i] == j + 1) LineofMatrix[Road[i + 1] - 1] = 1; if (Road[i + 1] == j + 1) LineofMatrix[Road[i] - 1] = 1; } j++; RMatrix[i] = LineofMatrix; } //Output Road Matrix /* cout << endl; for (int i = 0; i < CityCount; i++) { for (int j = 0; j < CityCount; j++) if (RMatrix[i][j]>0) cout << RMatrix[i][j] << ' '; else { RMatrix[i][j] = 0; cout << 0 << ' '; } cout << endl; } cout << endl; */ // alghoritm int *Value = new int[CityCount]; int Vl = 0; int *Locked = new int[CityCount]; int Lock = 0; bool BLock = false; int Bu = 0; int Final; int Cur; int PreCur=-1; int Iter=0; int min = INT_MAX; for (int i = 0; i < RoutesCount * 2; i+=2) { int *Buff = new int[CityCount * 2]; Cur = Route[i] - 1; Final = Route[i + 1] - 1; Buff[Bu++] = Cur; Buff[Bu++] = Final; if (RMatrix[Cur][Final] == 1) { goto fin; } else { for (int j = 0; j < CityCount; j++) { if ((RMatrix[Cur][j] == 1) && (j != PreCur)) { PreCur = Cur; Buff[Bu++] = j; Iter++; Cur = j; j = -1; } if (RMatrix[Cur][Final] == 1) { goto fin; } if (j == CityCount - 1) { j = Cur; Cur = PreCur; Bu -= Iter; Iter = 0; } } } fin: for (int z = 0; z < Bu; z++) { if (min > Buff[z]) { min = Buff[z]; } } Bu = 0; Iter = 0; cout << min+1 << endl; min = INT_MAX; delete[] Buff; }
//system("pause"); return 0; } I also WA#3 help me I fixed mine by changing "writeln(answer)" to "if x = y then writeln(x) else writeln(answer)". (program wasn't working correctly if start and end point were the same) OK, solved this problem but get a RE on test#6. Edited by author 08.03.2017 14:32 oh yeah, nearly 1000 submits, i dont remember so I get a conclusion: I use veronoi diagram algorithm ,it will have precision error. if you sort coordinates by x, you will get WA on test 17,if you sort it by y,you will get WA on test 21.. so I combine them together, do sort them by x,then sort them by y, and compare the minimum distance, it'll get AC.. so I get a conclusion: I use veronoi diagram algorithm ,it will have precision error. if you sort coordinates by x, you will get WA on test 17,if you sort it by y,you will get WA on test 21.. so I combine them together, do sort them by x,then sort them by y, and compare the minimum distance, it'll get AC.. gz. It is called "lexicographical sorting". Edited by author 05.03.2017 21:25 Во фрипаскале кейс не принимает стринги, насколько я помню. Попробуйте через ифы: if (a[i] = 'a1') or (a[i] = 'a8') и тд. #include "iostream" using namespace std; int main() { int a, b, rz; cin >> a >> b; if (b == 2 && a != 1 || b == 1 && a != 1) { rz = 2 * a / b; } else { if (a % b != 0) { rz = 2 * (a / b + 1); } else { rz = 2 * a / b; } } cout << rz; return 0; } i tested it a lot, pleas help may be i am so silly.... Hello) I can't understand how to work with n = 2^1 000 000, cause it's very big number. I think, this problem can be solved at stage of converting entered number, but don't know exactly how) I understood. The right way is not at converting entered binary number to decimal. Problem had tied on the fact that i used tokeniser for numbers and buffered reader for strings, Now i'm using bf reader for both strings and numbers and it gets AC. I leave it here, maybe it will useful Edited by author 05.03.2017 01:23 I checked everything 100 times but still can not understand what the problem is.(i wrote on Java) Perhaps, you don't sort the result? The same problem! What is the Test 2? Can anybody help with test 2 please? I have got this problem because i forgot to sort neighbours of vertices. Never mind, found it-it could be when no item is marked in requirement string. Can I solve this problem by natural merge sort? I solved it via following approach, split array by incrementing sub sequencies (incrementing by 1) and join it back after sorting. For example 5 1 3 2 4 Will be splited by (5) (1 2) (3 4). After sort it by first element (5) (1 2) (3 4) => (1 2) (3 4) (5) After that all sequences on odd position gos to way #1 and all other to way #2 We will have (1 2 5) in way#1 and (3 4) in way#2 and trust order in array. we will have (5 1 2) in way#1 and (3 4) in way#2. And after join in will be (5 1 2 3 4). Iterate such approach till not get (1 .. N) Example of output for N=16 and decreasing array. 4 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 13 9 5 1 14 10 6 2 15 11 7 3 16 12 8 4 9 1 10 2 11 3 12 4 13 5 14 6 15 7 16 8 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|