Общий форумTry this tets: 1999992 2000002 1009002 1010101 Input: 2 3 RT, RT, , B, , . Output: 6 2 3 2 4 3 3 3 4 4 2 4 3 Считаем кол-во клеток ( квадрат + 2 треугольника сверху и снизу ) 156 мс, как ускорить программу? сократить формулу? найти более легкую закономерность? n = int(input()) def tr(size): ans = 0 for i in range(1, size+1): ans += i return ans for j in range(n): print() for i in range(n): if i >= j: print((n-i-1)*j + tr(j) + tr(n-i-2) + 1 + j + (n-i-1), end = ' ') else: print(n*n - (i+1)*(n-j) - tr(n-j-1) - tr(i-1) + 1, end = ' ') k, n = [int(i) for i in input().split()] a = [int(i) for i in input().split()] if sum(a) - n * k <= 0: print(0) else: print(sum(a) - n * k) Can someone give idea or hint of dynamic prog solution? Помогите ,пожалуйста , что не так? #include <iostream> #include <string> using namespace std; int main() { int n, s = 0; cin >> n; string a[1000]; for (int i = 0; i < n; i++) { getline(cin, a[0]); for (int j = n + 1; j < n; j++) { if (a[i] == a[j]) { break; s++; } } } cout << s; return 0; } Edited by author 02.12.2019 20:46 у тебя код неверный Edited by author 18.12.2019 17:14 I passed all test cases mentioned in the discussion. There are 4 tests in my algorithm: - is there a loop (from M and N) ? - is the graph connected ? - is there a cycle? - for each component of the graph: find the longest path and compare the length with S any hint? Edited by author 06.09.2017 11:02 Edited by author 06.09.2017 11:02 i had problems with 3rd test case. this input should help you: 1 1 5 1 1 2 the key here was to look closely at restrictions: 1 ≤ M ≤ 100; 1 ≤ N ≤ 10 000 assuming there could not be several ways from different x and y, and no loops from x to x, there should be at most 4950 connections between cities 3rd test contains road from X to X, so answer is "YES" 10 RGRGRBGBGB Possible answer: 7 4 6 3 6 2 6 1 6 1 7 1 8 1 9 will somebody helps me? me too.. I think here the line begins with something like: andro.... or ndroS.... I just rewritten my AC solution in python (it was originally written in Java) and I got Runtime Error on test #7. Any hint on why this happen ? Any test ? It gives me the same results as my Java solution .. I'm also got RE#1 with Python 3.3. And finally rewrite code in C++ and got AC.. Look sys.setrecursionlimit solution found 1 1 Edited by author 16.12.2019 16:48 Edited by author 16.12.2019 16:51 #include <iostream> #include <iomanip> #include <cmath> #include <vector> using namespace std; int main() { cout << setprecision(4); vector<double> v; double n; while (cin >> n) v.push_back(n); for (int i = v.size() - 1; i >= 0; i--) cout << sqrt(v[i]) << endl; } WA1 typically means your program can't even pass the task example. Let's see your: https://ideone.com/Y8Uxei - yes, output is wrong. a, b =map(int, input().split()) print(a + b) a = int(input()) c= a//7 d=c*7 print(a-d) Если мы можем оставлять часть груза в городах(любое кол-во груза), то ответ будет 24(может и меньше). Ошибка в условии или некорректно сформулировано условие? Цитата из условия: "Грузовик Платона загружается один раз в столице." Следовательно, если мы оставим часть груза в каком-то городе, то назад его погрузить уже не сможем. Messages should be written in English reshke'` , если бы он хотел, чтобы наши иностранные дружбаны его поняли, то я думаю написал бы на английском. a2ch : There is nothing called foreign friends, please remember we are global citizen first. We all are programmers and that is our identity. Please keep smiling. --------------------------- Там нет ничего, что называется иностранными друзьями, пожалуйста, помните, мы в первую очередь гражданин мира. Мы все программисты, и это наша личность. Пожалуйста, продолжай улыбаться. Please read "if a student has got satisfactory marks, the scholarship is not given" this statement again and again which means if in any of the subject a student gets 3.0 he will not get any scholarship. -------------------------------------------------- Пожалуйста, прочитайте «если студент получил удовлетворительные оценки, стипендия не предоставляется», это утверждение снова и снова означает, что если по какому-либо предмету студент получает 3,0 балла, он не получит стипендию. import java.util.Arrays; import java.util.Scanner; public class ppppp { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int g = in.nextInt(); if (0 <= n && n <= k && k <= g && g <= 100){ int[] mas = {n, k, g}; boolean isSorted = false; int buf; while (!isSorted) { { isSorted = true; for (int i = 0; i < mas.length - 1; i++) { if (mas[i] > mas[i + 1]) { isSorted = false; buf = mas[i]; mas[i] = mas[i + 1]; mas[i + 1] = buf; } } } } int da = mas[0] - mas[1] * mas[2]; System.out.println(da); } } } Да тут есть ошибка!В коде есть ошибка нужно посмотреть код заново!И выявить ошибку! ОТВЕТ ДЛЯ ЭТОЙ ЗАДАЧИ a-b-c or a-b*c это нужно вписать в код и все получится! lol Edited by author 15.12.2019 12:57 Edited by author 15.12.2019 12:57 Edited by author 15.12.2019 12:57 #include<bits/stdc++.h> using namespace std; int main() { unsigned long long int n; while(cin >> n) { cout << fixed << setprecision(9) << sqrt(n) << "\n"; } return 0; } Add test. My solution O(n^2) on python AC admins is died Edited by author 13.12.2019 06:53 |
|