Common Boardimport java.util.Scanner; public class JavaThieves877 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int c1 = Integer.parseInt(scanner.next()); int c2 = Integer.parseInt(scanner.next()); if (c1 % 2 == 0 || c2 % 2 != 0) { System.out.print("Yes"); } else if (c1 % 2 != 0 || c2 % 2 == 0) { System.out.print("No"); } } } If you use formula in C++, you don't need the long arithmetics. Use long double and you'll get AC. i used long double, 2 4 6 29 -1000 but my answer is -6.00693e+208, is it correct or not? you should turn off siencetific notation My approach goes like this: lets choose a big random prime P > 10^16, and calculate F_(i+1)%P. bits/stdc++.h -> TLE on Test #4 cstdio -> TLE on Test #4 stdio.h -> AC Compiled with: G++ 4.9 C++11 Can anyone give an explanation? var podschet,a,b,i:integer; begin a:=1; for i:=1 to 10 do begin readln(b); a:=a*b; end; for i:=1 to a do begin if a mod i=0 then podschet:=podschet+1; end; if podschet>9 then podschet:=podschet div 10; writeln(podschet); end. Edited by author 11.12.2014 15:46 Mistake is in this line: if podschet>9 then podschet:=podschet div 10; To take last digit you should be using mod instead of div. Edited by author 15.02.2015 23:31 Edited by author 15.02.2015 23:31 Here's my code: import math a = input() a = a.replace('\n', ' ') a = a.split() a.reverse() for i in a: print(math.sqrt(float(i))) Edited by author 10.05.2014 16:59 What we are inputting is a stream of inputs, that may contain '\n'. On the other hand, input() cannot contain newline character. #include<iostream> using namespace std; int main() { long int N,i,sum=0; cin >> N; if (N > 10000 || N < -10000) { cout<<sum; return 0; } if(N>0) for(i= N; i>= 1; i-- ) sum=sum+i; if(N<0) for(i= N; i<=1; i++) sum=sum+i; cout<<sum; } What kind of projection? Orthographic or perspective? Edited by author 15.02.2015 14:43 import java.util.*; public class TurnForMEGA { public static void main(String[] args) { Scanner in=new Scanner(System.in); int k=in.nextInt(); int n=in.nextInt(); int sum=0,temp=0; int result=0; int[] array =new int[100]; for(int i=0;i<n;i++){ array[i]=in.nextInt(); } for(int i=0;i<n;i++) { temp=array[i]-k; if(temp>0) { array[i+1]+=temp; } } result=array[n-1]-k; if(result<=0) { result=0; } System.out.print(result); }
} Edited by author 15.02.2015 12:16 Edited by author 15.02.2015 12:16 according to the language of question sum of 1st 3 digits must be equal to the sum of last three digits for a number to be lucky. so am i missing some point? please help! According to statement digit count must be divisible by 2, source: "Output should contain a number of tickets such that the sum of the first half of digits is equal to the sum of the second half of digits." #include <iostream> using namespace std; int main(){ int a,b,c,d,k=0; cin >> a >> b >> c >> d; while(a<c){ if(k==0){ k = 1; a += b; cout << a << " "; } else { k = 0; c -= d; cout << c << " "; } } cout << a ; return 0; } can anyone provides some testcases? #include <iostream> using namespace std; int main() { int arr[4] = {10, 670, 55252, 4816030}; short m; cin >> m; cout << arr[m / 2 - 1]; return 0; } //hey; can you guess how i got these values?(think of the simplest solution) Edited by author 15.02.2013 04:31 if we are not too creative to calculate this on paper and there is no forum to take solution just do backtracking it works fine 1 second and something #include <iostream> using namespace std; int x[10], n, cont = 0; void back(int k) { if(k == n) { int s1 = 0, s2 = 0; for(int i = 0; i < n / 2; i++) { s1 += x[i]; } for(int i = n / 2; i <= n; i++) { s2 += x[i]; } if(s2 == s1) cont++; } else for(int i = 0; i <= 9; i++) { x[k] = i; back(k + 1); } } int main () { cin >> n; back(0); cout << cont; return 0; } I'm using KMP I don't know why I get TLE? #include <iostream> int main(int argc, const char * argv[]) { long long int NumofChars; long long int finAns=-1;
scanf("%lld",&NumofChars);
char lettersS[2*NumofChars]; char lettersT[NumofChars]; char letter_tmp;
for (long long int i=0;i<NumofChars;i++) { scanf(" %c",&letter_tmp); lettersT[i]=letter_tmp; }
for (long long int i=0;i<NumofChars;i++) { scanf(" %c",&letter_tmp); lettersS[i]=letter_tmp; lettersS[i+NumofChars]=letter_tmp; }
long long int prefix[NumofChars]; prefix[0]=0; prefix[1]=0;
long long int pi=0; long long int pj=1;
while(pj<NumofChars-1) { if(lettersT[pi]==lettersT[pj]) { prefix[pj+1]=prefix[pj]+1; pi++; pj++;
} else {
pi=0; if(lettersT[pi]==lettersT[pj]) { prefix[pj+1]=1; pi++; pj++;
} else { prefix[pj+1]=0; pj++;
}
} }
finAns=-1;
long long int i=0; while(i<NumofChars) {
long long int Matchcount=0; long long int j_init=0; for (long long int j=j_init;j<NumofChars;j++) { if(lettersS[i+j]==lettersT[j]) { Matchcount++; } else { if(j-prefix[j]>0) { i=i+j-prefix[j]; j_init=prefix[j];
} else { i++; }
break; } }
if(Matchcount==NumofChars) { finAns=i;
break; } } std::cout<<finAns; return 0; } Whoever thought of this problem haven't fried steaks in real life. The only way to get an acceptable solution to 1820 is to cook the steaks somewhat similar to this order: Minute 1: St1A, St2A Minute 2: St1B, St3A Minute 3: St2B, St3B (where there are three steaks: St1, St2 and St3, and each having side A and side B). The problem with this is: After St2A side is cooked, it will be taken off the heat and cool down for one minute before cooking the other side, thus in the end the steak will be less cooked than stake 1 and 3. That's all sorts of wrong, you'll be ruining a good steak! :-D For those who get TLE #17 try to use scanf/printf instead of cin/cout Thank you Petru, your advice helped me to pass from TLE 17 to TLE 29 :) Explain me please, why if n=4, the answer is 204. I get 2513. 1031 is not a THREE-PRIME nummber. 103 is THREE-PRIME nummber, but 031 isn't, it's TWO-PRIME number Thank you for question and answers. It help to understand the task. Here is my code: ----- [The code was here] ----- I've got the point. Thank you. Edited by author 17.07.2011 18:48 |
|