|
|
Общий форумCan anyone give me some test cases because I really don't know where my program is wrong ? Nevermind, this test case helped me find my mistake: "ababbaa" Me too. Thanks nice test. Is there a way to know more precisely what is going on on the test machine? I've tested my python solution on my machine on large data (N=10^6) with a lot of copying operations (geometric progression) and got answer with memory used < 64Mb. #include <iostream> using namespace std; int main() { int n; cin>>n; string s; int a=1; int counter=0; for(int i=0; i<n; i++) { cin>>s; if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==2) { a=1; counter++;} else if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==3) { a=1; counter+=2;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==1){ a=2; counter++;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==3){ a=2; counter++;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==1) { a=3; counter+=2;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==2) { a=3; counter++;}
} cout<<counter; system("pause"); return 0; } my code is wrong in the test 8 but i dont know the test, can you help me? #include<iostream> #include<cstring> #include<cmath> using namespace std; int main(){ string st; int W,n,i=0,A[1000]; cin >> n; do{ cin >> st; if(((int)st[0]==65)||((int)st[0]==80)||((int)st[0]==79)||((int)st[0]==82)) A[i]=1; if(((int)st[0]==66)||((int)st[0]==77)||((int)st[0]==83)) A[i]=2; if(((int)st[0]==68)||((int)st[0]==71)||((int)st[0]==74)||((int)st[0]==75)||((int)st[0]==84)||((int)st[0]==87)) A[i]=3; i++; }while(i<n); for(i=0;i<n-1;i++) { int S; S=abs(A[i]-A[i+1]); W+=S; } cout<<W; return 0; } Please,help me!!! Edited by author 06.05.2016 18:42 import 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 #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) |
|
|