Common BoardНе понимаю где ошибка. Занимаюсь в целом программированием 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. ??? solved. you should calculate everything in int64 not doubles 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 public class Pan { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); int k = scanner.nextInt(); int m = 2*n; if (m%k == 0){ System.out.println(m/k); } else{ System.out.println(m/k+1); } } } why Wrong Answer? Is test #6 checking something interesting, or is it just precision-test? At least, which solid is used in this test? const long double eps=1e-12; using long double... RT what's the principle of the solution? i've tried to construct laser-lines one after another with the smallest distance, and then to find dots of intersections line[i] and line[i+1], then find intersection of line[i+1] and line[i+2] and after that find the distance between dot[1] and dot[2], dot[2] and dot[3] and so on. But that's a big problem: line[i] can intersect line[i+1] in dot[1], that can later occur outside of the figure, formed with intersects of line[i+1000] and line[i+1001]. What's the solution? you can try to find intersection point of lines x1,y1, x2,y2 x1+dt*cos(theta1),y1+dt*sin(theta1),x2+dt*cos(theta2), y2+dt*sin(theta2) x1=fx1+t*cos(theta1),y1=fy1+t*sin(theta1) x2=fx2+t*cos(theta2),y2=fy2+t*sin(theta2) point (fx1,fy1) and (fx2,fy2) is the point on the convex polygon you can the intersection point x(t),y(t) by limit dt--->0 then length of args is sqrt((dx/dt)^+(dy/dt)^2) dt ,you can find the Primitive function of sqrt((dx/dt)^+(dy/dt)^2) and compute the integral by O(1) 1. Segment tree. 2. Fenwick tree. 3. Partial sums (b[i] = SUM(a[0], ..., a[i])). 4. Sqrt decomposition. Hope, it helps to understand how to solve this task. Edited by author 28.02.2017 15:25 1. Modification of a deque, which allows to find a min element in O(1). 2. Segment tree. 3. Min/max heap (was too slow for me). 4. Sparse table. 5. Sqrt decomposition. Hope, it helps to understand how to solve this task. Edited by author 28.02.2017 15:25 |
|