|
|
Common Boardimport sys n = input() arr = bytearray(n) i = 0 while i < n: line = raw_input().split() arr[i] = (int(line[0]) + int(line[1])) i += 1 result = "" i = n-1 while i > 0: if arr[i] > 9: arr[i] -= 10 arr[i-1] += 1 result = str(arr[i]) + result i -= 1
arr[0] = arr[0]%10 result = str(arr[0]) + result print result result = str(arr[i]) + result Run this code 1M iterations locally. f(x) = k * (x^2 -2(a1)x + (a1)^2 + x^2 -2(a2)x + (a2)^2 + ... + x^2 -2(an)x + (an)^2) / n = k (x^2 - (2/n)(a1 + a2 + ... + an)x + ((a1)^2 + (a2)^2 + ... + (an)^2)/n so we have f'(x) = k(2x - (2/n)(a1 + a2 + ... + an)) question: what is k? (explaining from previus post) Edited by author 05.05.2016 14:53 Edited by author 05.05.2016 14:54 Earlier I had got a WA 9 but now I'm getting a WA 5 with the same code. What's the logic? 4686044 16:50:13 21 Dec 2012 Marian Darius 1297. Palindrome C++ Accepted 0.031 108 KB Just try iterating the middle of the palindrome and extend to both ends, until you find two elements that are different. Seriously? Are you really think that you are the first who do it for O(N^2) with the same idea? And it's not the first topic in the forum about this algo. I don't know why but I get a TLE in #15 with the same approach as yours. 3 days overall. I'm your fan forever. Edited by author 03.05.2016 14:58 Can you give us some tips on your approach? Thanks in advance. Edited by author 03.05.2016 14:58 Can someone help to post test #2? Thanks 1. Sort it by endTime, if endTime equals another endTime then sort them by startTime. 2. Open one iteration from 2 to n, init just check that, is endTime<starTime, if so then ans++; 3. print ans; endTime and startTimes is one array with unchanged same index... Sorry for poor English
I don't think sorting by startTime is necessary. I think we should reverse-sort by startTime. I found hah) Edited by author 01.05.2016 17:16 What is the 12 test? Edited by author 29.11.2014 12:19 It's about time limit exceed. import math values = raw_input().split(' ') a = float(values[0]) b = float(values[1]) c = float(values[2]) d = float(values[3]) if (math.fabs(a*b-c*d)<0.001): print "Impossible."
j = 0.0 x = a**2 + b**2 #DC**2(1) y = c**2 + d**2 #DC**2(2) x1 = - 2 * a * b y1 = - 2 * c * d l = math.fabs(x - y) r = math.fabs(x1 - y1) if r == 0: False else: j = l / r #cos res = a**2.0 + b**2.0 - 2.0 * a * b *j #DC**2 res = math.sqrt(res)*1000 #DC print "Distance is %(res)d km." %{"res": res} Edited by author 29.04.2016 15:30 Edited by author 29.04.2016 16:01 new one but still WA9 package banky; import java.util.*; public class test1 { private static Scanner scan; public static void main(String [] args){ scan = new Scanner(System.in); int k=0; int r=0; int pr=0; while (scan.hasNext()){ String s = scan.nextLine(); //s = s.toUpperCase(); s = s.toLowerCase(); char c [] = s.toCharArray(); if (k<=0||r>0) c[0] -= 32; int i ; for(i=1;i<s.length();i++){ if ((c[i] == 46) || (c[i] == 33) || (c[i] == 63)) {pr= 1; c[i]=c[i];} else if (pr==1&&c[i]!=32) { c[i] -= 'a' - 'A'; pr = 0;}} for(i=0;i<s.length();i++){ if ((c[i] == 0)|| (c[i] == 14) || (c[i] == 1) || (c[i] == 31)) c[i] += 'a' - 'A';} for(i=1;i<s.length();i++){ if (((c[i-1]< 'a')&&(c[i-1]>='A'))&&((c[i]< 'a')&&(c[i]>='A'))) {c[i] += 'a' - 'A';}}
if ((c[s.length()-1] == 46) || (c[s.length()-1] == 33) || (c[s.length()-1] == 63)) {r=r+1;} else {r=0;} //System.out.println(k); //System.out.println(r); System.out.println(c); k=k+1; } } } Edited by author 30.04.2016 13:09 You are checking the only prev char for end of sentence. Why? Try "HERE!!! IS!!!!! TEST!!!!" P.S. Why "c[i]==32" better then "c[i]==' '"? Дякую, за тест. І що мені робити? :( Edited by author 29.04.2016 11:37 Implement state machine, ~2 states: 1) "at sentence begin", if char is alpha then it uppercased, state switched to "inside sentence" 2) "inside sentence", if char is alpha it lowercased; if char is ".?!" state switched to "at sentence begin". Thank you for help. But I am only beginer in java so i cant jet deal with this state machine Implement state machine, ~2 states: 1) "at sentence begin", if char is alpha then it uppercased, state switched to "inside sentence" 2) "inside sentence", if char is alpha it lowercased; if char is ".?!" state switched to "at sentence begin". I've got quadratic equation. It can be calculated if you know just what is arithmetical progression. What I should to know in maths to find max P (I found P from the equation). Edited by author 29.04.2016 01:05 Edited by author 20.12.2017 21:41 #include <iostream> using namespace std; int main() { int mashines, minutes; cin >> mashines >> minutes;
int arr[minutes];
for(int i = 0; i < minutes; ++i) {cin >> arr[i];}
int m = 0; for(int i = 0; i < minutes; ++i) { m += arr[i];
if(m - mashines >= 0) {m -= mashines;} else {m = 0;} }
cout << m; } а тебе разрешили инициализировать массив с НЕ const параметром? Edited by author 28.04.2016 09:29 Hah I decided to check all variants, but due to misprint my program become greedy) #include <iostream> using namespace std; long f[101],n; int main() { long i,t,c=0; cin>>n; for (i=1;i<=n;i++) { if (f[i]==0) f[i]=1; while (true) { cin>>t; if (t==0) break; if (f[t]==0) f[t]=1+(f[i]==1); } if (f[i]==1) c++; } cout<<c<<endl; for (i=1;i<=n;i++) if (f[i]==1) cout<<i<<" "; } why?? I had WA 11, this test helped me: 4 2 0 1 4 0 4 0 2 3 0 Edited by author 30.10.2007 04:07 What's the main idea behind it? I am getting a wrong answer in it. Can anyone please help me? #include<stdio.h> #include<stdlib.h> int main() { int m,n,a[50000],b[50000],i,j,p,c; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } scanf("%d",&m); for(i=0;i<m;i++) { scanf("%d",&b[i]); } for(j=0;j<n;j++) { for(p=0;p<m;p++) { c=a[j]+b[p]; if(c==10000) { printf("YES"); exit(0); } } } printf("NO"); return 0; } in my mind, two loops is not required. Try to use binary search in sorted array. steps: 1.Take from first array the number; 2.1000-[this number] 3.find 1000-[this number] in second array(use binary search) This way, you have only one loop. Edited by author 20.11.2015 23:45 Edited by author 20.11.2015 23:45 import java.util.Scanner; public class Factorials { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String k = in.next(); char a[] = k.toCharArray(); int length = a.length; function(n, length); in.close(); } private static void function(int n, int length) { int t = n % length; int c = (t == 0 ? length : t); int sum = n; for (int i = 1;; i++) { sum = sum * (n - i * length); if ((n - i * length) == c) { System.out.println(sum); break; } } } } If k > n then answer is n. Try "5 !!!!!!" |
|
|