Common Boardimport java.util.Scanner; public class SMSspam2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s =in.nextLine(); char a[] = s.toCharArray();
int count = 0; for(int i=0;i<s.length();i++){ count = count+getCount(a[i]); } System.out.println(count); in.close(); } private static int getCount(char a) { int count =0; if (a == 'a' || a == 'd' || a == 'g' || a== 'j' || a== 'm' || a == 'p' || a == 's' || a== 'v' || a == 'y' || a== '.' || a== ' ') { count++; } if (a== 'b' || a == 'e' || a== 'h' || a == 'k' || a == 'n' || a == 'q' || a== 't' || a== 'w' || a== 'z' || a == ',') { count = count + 2; } if (a== 'c' || a== 'f' || a == 'i' || a == 'l' || a== 'o' || a== 'r' || a == 'u' || a== 'x' || a == '!') { count = count+ 3; } return count; } } #include <stdio.h> int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int n; scanf("%d", &n); long *sections = new long[n]; for (int i = 0; i < n; i++){ scanf("%ld", §ions[i]); } if (n==3){ printf("%ld %d", sections[0] + sections[1] + sections[2], 2); } else{ int i = 0; int maxpoint = i; while (i + 3 < n){ int j = i + 1; if (sections[i] + sections[i+1] + sections[i+2] < sections[j] + sections[j+1] + sections[j+2]){ maxpoint = j; } i++; } printf("%ld %d", sections[maxpoint] + sections[maxpoint+1] + sections[maxpoint+2], maxpoint+2); } return 0; } Input: 5 1 2 3 4 5 Output: 12 4 ENG: Read carefully the terms. Numbers do not necessarily have to be the same. (Google Translate) RUS: Внимательно читайте условие. Числа не обязательно должны быть одинаковыми. You should not compare sum with the previous sum, but the max sum. Considering sequence: 1 6 6 6 1 1 1 2 2 2 var a, x: extended; begin readln (a); x:= sqrt (a); writeln (x); end. Выдаёт неправильный ответ. Firstly you should read task carefully. How many numbers are in input? How many numbers your program process? import java.util.Scanner; public class Digitals { public static void main(String[] args) { Scanner in = new Scanner(System.in); int N = in.nextInt(); int a[] = new int[N]; int b[] = new int[N]; int sum = 0; for (int i = 0; i < N; i++) { a[i] = in.nextInt(); sum = 1; for (int j = 0;; j++) { sum = sum + j; if (sum == a[i]) { b[i] = 1; break; } if (sum > a[i]) { b[i] = 0; break; } } } for (int p = 0; p < N - 1; p++) System.out.print(b[p] + " "); System.out.println(b[N - 1]); in.close(); } } How do it more fast? #include <iostream> using namespace std; int main() { int x, y, c;
cin >> x >> y >> c;
if((x + y) < c) { cout << "Impossible" << endl; } else { for(int i = 0; i <= x; i++) { for(int j = 0; j <= y; j++) { if((i + j) == c) { cout << i << " " << j << endl; return 0; } } } } } Edited by author 13.10.2015 20:23 Edited by author 13.10.2015 20:23 Here is other way to solve If U have X u do not need finding Y Edited by author 20.04.2016 18:25 There are 21 steps in this sequence: 1, 2, 3, 4, 5, 6, out, 6, 7, 8, 9, 10, 11, 12, out, 12, 11, 12, 13, 14, 15 a = int(input()) b = int(input()) print (a+b) _____________________ почему не правильно пишет? Execute example as is - use one line input - "1<space>5<eol>". You will see your solution doesn't work. Должно быть правильно... Я так же писала Не правильно потому, что ввод должен быть не: а - интер, b - интер, а: а - пробел b - интер.. I'm using BS + Dijkstra but I'm getting TLE, why? I optimized solution by using edges that have capacity >= 3 * 10^6, implemented BS with iterations (without "while"), but keep getting TLE. I had TLE 46 when i was checking for time[N] <= 1440 only after my BFS was complete. But when i moved this condition inside my BFS, to check on it after getting every new wave of vertices, i got AC in 0.078! Truly surprising, wasn't expecting to make that much difference by moving a single line. My BFS shouldn't really be that bad either... what if k=7? Is l=2? No. Because we know that if k=3 then answer 2. So we can remove 3 buttons from bunch. And find answer for k=4, but answer for this input will be 3. So 2!=3 and such answer is wrong. So answer will be 6 (cause we can't divide it on groups answer for those we know). Just list all of cases like x>=y>=c or y>=x>=c and you'll understand //1152 #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { int n, x0, y0, index0; cin >> n; if (n == 2){ cout << 1 + ' ' + 2; } else { vector<vector<int>> p(n, vector<int>(2)); // [x, y] vector<double> k(n); for (int i = 0; i < n; i++) { cin >> p[i][0] >> p[i][1]; } x0 = y0 = 2147483647; for (int i = 0; i < n; i++) { if (p[i][0] < x0 ||p[i][0] == x0 && p[i][1] < y0){ x0 = p[i][0]; y0 = p[i][1]; index0 = i; } } for (int i = 0; i < n; i++) { //y = kx + m if (i == index0) { k[i] = 9223372036854775807; } else { if (x0 == p[i][0]) { k[i] = 9223372036854775807; } else { k[i] = (p[i][1] - y0) / (p[i][0] - x0); } } }
vector<int> d(n); for (int i = 0; i < n; i++) { d[i] = i; } double tempD; int tempI; for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < i; j++) { if (k[j + 1] < k[j]) { tempD = k[j + 1]; k[j + 1] = k[j]; k[j] = tempD; tempI = d[j + 1]; d[j + 1] = d[j]; d[j] = tempI; } } } cout << index0 + 1 << ' ' << d[n / 2 -1] + 1; } return 0; } I wrote program on Python 3, but second test is wrong for me. Why? I need a hint. Maybe, you can wrote test for my program? Idea: 1. sort length descending 2. take first that smaller SUM in row 3. reduce SUM and colored ship 4. take next 5. finally for SUM if they == 0 -> go to next row My solution: [n, m] = [ int(x) for x in input().split() ] a = [] for i in range(n): a.append(int(input())) b = [] for i in range(m): b.append(int(input())) a.sort(reverse=True) color = [-1 for x in range(n)] i = 0 while i < m: s = b[i] z = 0 while z < n: aa = [] j = z while s > 0: while j < n and a[j] > s : j += 1 if j >= n: for ee in aa: s += a[ee] color[ee] = -1 aa = [] break elif color[j] != -1: j += 1 else: s = s - a[j] aa.append(j) color[j] = i z += 1 if s == 0: break i += 1 for i in range(m): aa = [] cnt = 0 for j in range(n): if color[j] == i: aa.append(a[j]) cnt += 1 print(cnt) aa.sort(reverse=True) ab = [str(x) for x in aa] ss = " ".join(ab) print(ss) please, never post your code here! use pastebin or ideone! The statement describes the precision as 10^-9, but in the second example I see "1.41421356237309" This number has 14 digits behind decimal point. I tried submitting answers with precision 9, 14 and 16. They all WA#1 even though my calculations have to be correct. Does someone know what's the correct precision? Edited by author 14.04.2016 15:20 Edited by author 14.04.2016 15:20 Are you using a high enough precision type? And hopefully don't output anything extra like "result="? Show your code or something. var a,b,c,d,e,f,g,h : real begin read(a,b,c,d); e := sqrt(a); f := sqrt(b); g := sqrt(c); h := sqrt(d); writeln(h:0:4); writeln(g:0:4); writeln(f:0:4); writeln(e:0:4); end. why is my answer wrong? Have you read task? Why no? You should try. >Input > The input stream contains a set of integer numbers. The numbers are > separated by any number of spaces and line breaks. A size of the input > stream does not exceed 256 KB. Edited by author 13.04.2016 13:14 i racked my brain, but i unable found solution so can i look your source code in pascal? Sure no. 1) Why do you think I know pascal? 2) Problem is 2nd easiest here. You should be able to solve it yourself. What problem do you have? How to read numbers from stream? http://acm.timus.ru/help.aspx?topic=pascal"How to read input data until the end of stream" topic How to estimate max input size? It's about 256K/2 numbers. How to print results in reverse order? Pff. Give up for a while and learn programming. Edited by author 13.04.2016 14:00Where the stop position if there is only one input? I am confused, please explain the problems. For those who using prime numbers! Search biggest prime number that <= max!!! NOT first prime number that >=min !! У меня получилось вот что I have this: > http://ideone.com/8CHWDd Почему проверка считает что ответ неверен Why it's wrong? test 11.please give me some test.thx! |
|