Общий форум Edited by author 21.01.2016 20:56 Edited by author 21.01.2016 20:56 неправильно: n=3 k=10 =>891 n=4 k=10 =>8829 ещё тесты: n=16 k=2 =>1597 n=8 k=8 => 13464808 и ещё:использовать лучше самый большой тип For me, this was reading outside the field (likely at N = 100). import java.text.*; import java.util.*; public class Main { public static final int TREAD_MAX_SIZE = 262144; public static void main (String[] args) { DecimalFormatSymbols s = new DecimalFormatSymbols(); s.setDecimalSeparator('.'); DecimalFormat f = new DecimalFormat("0.0000",s); Scanner scan = new Scanner(System.in); int size = 0; String string = ""; while (scan.hasNextLine()) { String line = scan.nextLine(); int sizeline = line.length(); size += sizeline; if (size <= TREAD_MAX_SIZE) { string += line; } else { break; } } scan.close(); double min = 0; double max = Math.pow(10, 18); String[] str = string.trim().split("\\s+"); for (int i = str.length - 1; i >= 0; i--) { Double val = Double.valueOf(str[i]); if (val >= min && val <= max) { val = Math.sqrt(val); System.out.println(f.format(val)); } } } } What's wrong? Code without checking the boundary conditions passed test (0 ≤ Ai ≤ 10^18 and 256КB)! Why? Edited by author 28.01.2016 14:06 I used segment tree with update func and HashMap for indexes of elements(+). Java AC 0.34sec Edited by author 27.01.2016 19:10 Edited by author 27.01.2016 19:38 Edited by author 27.01.2016 19:49 vector of segments and binary search also must work i have WA on test #3 my code here: #include <iostream> using namespace std; int main() { int n, s = 0; cin >> n;
string *arr = new string[n]; string a; getline(cin, a); for(int i = 0; i < n; i++) { getline(cin, a); for(int j = 0; j < i; j++) { if(a == arr[j]) { s++; break; } else arr[i] = a; } }
cout << s << endl;
return 0; } Edited by author 26.01.2016 21:58 Try test: 2 a a - Your answer is 1, expected is 0 Also your solution has O(n*n) complexity. I expect (or at least hope) you will have TLE. Edited by author 27.01.2016 18:07 Can't edit prev message. > Your answer is 1, expected is 0 Should be: Your answer is 0, expected is 1 #include <iostream> #include <cmath> #include <vector> using namespace std; int main() { cout.setf(cout.fixed); cout.setf(cout.showpoint); cout.precision(4); vector <double> a; double c; while(cin>>c) { a.push_back(sqrt(c)); } for(int i = a.size()-1;i>=0;i--) cout << a[i] << endl; } You should use long long instead of double Probably gcc? Try to select MSVC compiler. Also you can try using printf/scanf instead of cin/cout. i have wa on 2 test.can someone help me.i'm trying to solve it with fenwick. import java.util.Scanner; /** * Created by Oxygen! on 25.01.2016. */ public class BitvaUBolota1991Var2 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int x=0,y=0; int n=sc.nextInt(); int k=sc.nextInt(); int a[]=new int[n]; for(int i=0; i<n; i++) { a[i]=sc.nextInt(); if(a[i]<=0) { y+=k-a[i]; } else { x+=a[i]-k; } System.out.println(x+" "+y); } } } import java.util.Scanner; public class T1048 { public static void main(String[] args){ Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int[] mas=new int[a]; int[] mas1=new int[a]; String b=""; String b1=""; for(int i=0;i<a;i++) { mas[i]=sc.nextInt(); b+=mas[i]; mas1[i]=sc.nextInt(); b1+=mas1[i]; } int v=Integer.parseInt(b); int v1=Integer.parseInt(b1); System.out.println(v+v1); }} Timus text "Runtime error" №2 Task: > The first line contains a single integer N that is the length of the given integers (1 ≤ N ≤ 1 000 000) Your code: > int v=Integer.parseInt(b); How many digits can be placed into int v? Edited by author 22.01.2016 17:19 Edited by author 09.04.2016 11:42 How to solve it without of using brute force? It works, but, I've heard, there is better solution. This is a famous problem known as "interval scheduling". Yes. I have WA on test 22 too. Hello! I had WA on 22 test too. But later I realized that the two numbers in the input N and M mean N - the number of boxes verticaly and M - the number of boxes horizontaly. While I read the input as if they were the opposite. So, if you are wondering why your program doesn't work check this :). Maybe all the previous tests (1-21) hare N=M i don't know. yes, me too, WA on 22. I flipped M and N and AC. I flipped M and n and AC,too! Maybe the problem's description is wrong... I use the fomula to find average of n values X[i], i=1...n if I know the average of (n-1) values X[i], i=1...(n-1): AVE(X, n) = ((n-1)AVE(X, n-1) + X[n]) / n This doesn't help. 1.sort(X[]). 2.add (X[i+1]-X[i])*i*(n-i). Brilliant idea. I've got it. Thanks. i've got smth similar but i don't understand how to sort it... pls help I don't have any ideea... how did you solve this problem? I've got TLE ... I use brute force.. LOL Doesn't work with 4 10 10 10 20 20 10 20 20! 1.sort(X[]). 2.add (X[i+1]-X[i])*i*(n-i). Edited by author 07.04.2011 01:25 how do you sort it, what is min and what is max after sort... i've got WA for 3 20 20 30 30 50 10 must work! segment[X[i],X[i+1]] is passed by all pairs from [1..i]*[i+1,..n] or i*(n-i) times where i in[1..n-1] i still don't get it... pls send me your source at lerh_91@live.com Because for a given point i we can only go to another point vertically or horizontally and that's a great hint. Consider an input file that contains 7 points (index from 1 to n), and now we have sorted them by x[] in ascending order. Now let's consider the segment between point 5 and point 6, denoted by S(S=x[6]-x[5], remember that we have sorted the points by x[]). Now if we want to go from point 2 to point 6, we must pass through S, and likewise, if we want to go from point 1,2,3,4,5 to point 6,7, we have to pass through S. Inversely, from point 6,7 to point 1,2,3,4,5, we must pass through S. Actually, for a given segment x[i+1]-x[i], we have to pass through this segment i*(n-i)*2 times, for there are i points before and including the ith point and (n-i) points after the ith point, and we have to go from left to right and from right to left. This analysis is also true for the y coordinate. By this method we can get the total distance from every point to every other point. Finally just divide the total distance by (n*(n-1)) to get the average distance because there are n points and each point has (n-1) road to the other points. In conclusion, the solution would be : for(i = 1 to n-1) { ans += (x[i+1]-x[i]) * i * (n-i) * 2; ans += (y[i+1]-y[i]) * i * (n-i) * 2; // or ans += (x[i+1]-x[i] + y[i+1]-y[i]) * i * (n-1) * 2; } ans /= ( n*(n-1) ) Be careful about the data type of ans, int is not enough, use long long I solved this problem theoretically and checked ability of a jump by counting the discriminant of square equation. I got WA on tests 30-32 using floating point numbers and trying to find good precision (type double in C) and rewrote my program using long integer type (long long) with no precisions. The first thing I noticed is that I got WA on test 20 when I say that jump is possible if D>=0. If I check D>0, I get WA on test 32. I'm sure it's not correct, because if D=0 exactly jump is still possible. I thought the problem could be in overflowing. Despite long long must be enough, I rewrote the program in Python 3 to avoid overflowing for sure and nothing changed. So I think I am right and there are wrong tests. I can show my source code if needed. Edited by author 20.07.2015 18:27 By the way, I got AC on FreePascal using the condition that is less strict because of precisions. Approve this. Only condition D >= 0 allows test like this 0 0 1 0 0 0 2 There is additional check needed. This magic works: L^2*g^2<=(V^2-g*(y2-y1))^2 implem. in long long(g=98/10) I got a wrong answer on 25 but I don't know why. Is there someone could give me some tests? import java.util.Scanner; /** * Created by Oxygen! on 19.01.2016. */ public class ProstoeVirajenie2066Var3 { // 2066. Простое выражение public static void main(String[] args) { Scanner sc=new Scanner(System.in); int a=sc.nextInt(); int b=sc.nextInt(); int c=sc.nextInt(); if(0<=a && a==b && a==c || a>b || a>c || b==c || a>=c && b>a || a==b && b<c && c<=100) { System.out.print(a-b-c); } else if(0<=a && a<b && b<c || b>c && c<=100) { System.out.print(a-b*c); } else { System.out.print("error"); } } } Thinking of kittens and doors rather than Dodecahedrons helped me to find O(N) solution :) |
|