| Показать все ветки Спрятать все ветки Показать все сообщения Спрятать все сообщения |
| I really don't know why it is wrong(Java Scrip) | Hufeng Zhou | 1001. Обратный корень | 18 авг 2010 06:20 | 3 |
Hi, I tried to use java to solve this problem but failed, yet do not know where is the bug, I have pasted the source code here, wish someone can help me out. I am very very grateful. public class ReversRoot1001 { public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new FileReader("ReversRoot1001.txt")); Vector<Integer> record = new Vector<Integer>(); String line; while((line = br.readLine())!=null){ Scanner sc = new Scanner(line); int a = sc.nextInt(); record.add(a); // if(sc.hasNext()){ // int b = sc.nextInt(); // //int c = sc.nextInt(); // record.add(b); // } while(sc.hasNext()){ int b = sc.nextInt(); record.add(b); } } for(int i = record.size();i<record.size();i--){ System.out.println(record.get(i)); } br.close(); } } Use standart input/output. And don't use Scanner - it's very slow. Look: BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); StringTokenizer tok = null; String readToken() throws IOException { // reads the token; to read a full line use in.readLine() while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); // sometimes it's better to use nextToken(String) method here } int readInt() throws IOException { // write readDouble(), readLong(), readBigInteger() methods if necessary return Integer.parseInt(readToken()); } And, finally, don't forget to write out.flush() at the end of your program! Edited by author 17.08.2010 21:26 Moonstone Thank you so much for your help. I am very grateful! Edited by author 18.08.2010 06:21 |
| answer plz | 72VanVector[SevNTU] | 1111. Квадраты | 18 авг 2010 01:18 | 2 |
what would be the distance between point (0,0) and square (1,0) (-1,0)?? Is it equal 0 or 0.7?? "If P is inside the square then the distance is zero" So, the distance is 0. |
| WA in Test 6 | Jorge Alejandro Millán Chang | 1404. Легко взломать! | 17 авг 2010 12:15 | 2 |
Does anyone knows what is tested in the test 6??? Or anyone have examples???? I had WA#6 too. Didn't use 'string' object because it is have char size of i-th element (-128,127), but you need more. Edited by author 17.08.2010 12:17 |
| Test #7 | 2lazy | 1424. Маршрутка | 17 авг 2010 08:45 | 5 |
Gettin' wrong answer. Can anybody post it, please!? 10 2 5 1 1 6 1 4 4 5 5 8 7 9 Answer: 5 1 2 3 4 5 May be test 7 is another thing.I don't know exactly. Edited by author 16.05.2009 11:57 I got wa7 too. But my algo give right answers in all tests at timus :( I use sort and greedy :( I don't understand why sort and greedy not work? this is not test 7 this test works for me i also use sort + greedy and i dont know why i get wa7 Try this one: 10 3 5 1 1 2 1 5 1 7 6 8 4 9 The answer is: 5 1 2 3 4 5 |
| C# Compiler Upgraded to Visual C# 2010 (.NET 4.0) | Vladimir Yakovlev (USU) | | 17 авг 2010 02:54 | 3 |
If you encounter any problems please describe it in this thread. The default stack size is set to 64 MB now. |
| Test 16 incorrect? | pperm | 1477. Самолёты | 16 авг 2010 12:02 | 2 |
I think that test 16 have at least two codirectional vectors. Incorrect test is fixed. Thank you. |
| new test should be added | Pasky | 1627. Join | 16 авг 2010 11:08 | 2 |
My AC solution crashes on this test 2 2 ** ** Problem statement is updated. Read "Site news". |
| got wa#3?? strange... | Ivan | 1111. Квадраты | 16 авг 2010 04:19 | 1 |
#include <stdio.h> #include <math.h> #define M_PI_4 0.785398163397448309616 double d[51] = {0}; char printed[51] = {0}; struct point { double x; double y; }; struct square { point a; point b; } squares[51]; point rotate(point a, double d_al){ point _a; _a.x = a.x * cos(d_al) - a.y * sin(d_al); _a.y = a.x * sin(d_al) + a.y * cos(d_al); return _a; } double get_d(point a, point p) { return sqrt((double)((a.x - p.x)*(a.x-p.x) + (a.y -p.y)*(a.y - p.y))); } int main () { int n; scanf("%d",&n); point p; int i; for (i=1;i<=n;i++) { scanf("%lf%lf%lf%lf", &squares[i].a.x,&squares[i].a.y,&squares[i].b.x,&squares[i].b.y); } scanf("%lf%lf", &p.x,&p.y); double tn; double alpha,d_al; point _a,_b,_p,a,b,temp; for(i=1;i<=n;i++) { b = squares[i].b; a = squares[i].a; if(a.x == b.x && a.y == b.y) { d[i] = get_d(p,a); continue; } tn = (double)(b.y - a.y)/(double)(b.x - a.x); alpha = atan(tn); d_al = M_PI_4 - alpha; _a = rotate(a,d_al); _b = rotate(b,d_al); _p = rotate(p,d_al); if( _a.x > _b.x) { temp = _b; _b = _a; _a = temp; } if(_p.y > _b.y) { if(_p.x < _a.x) { temp.x = _a.x; temp.y = _b.y; d[i] = get_d(_p,temp); continue; } if(_p.x > _b.x) { d[i] = get_d(_p,_b); continue; } d[i] = _p.y - _b.y; continue; } if(_p.y < _a.y) { if(_p.x > _b.x) { temp.x = _b.x; temp.y = _a.y; d[i] = get_d(_p,temp); continue; } if(_p.x < _a.x) { d[i] = get_d(_p,_a); continue; } d[i] = _a.y - _p.y; continue; } if(_p.x < _a.x) { d[i] = _a.x - _p.x; continue; } if(_p.x > _b.x) { d[i] = _p.x - _b.x; continue; } d[i] = 0; } double min; int j,k; for(i=1;i<=n;i++) { min = 99999999999999999; k = 0; for(j=1;j<=n;j++) if(!printed[j] && min > d[j]) { min = d[j]; k = j; } printed[k] = 1; printf("%d ", k); } return 0;} |
| No subject | Zayakin Andrey[PermSU] | 1746. Гиперладья | 16 авг 2010 03:57 | 1 |
No subject Zayakin Andrey[PermSU] 16 авг 2010 03:57 Don`t forget about d = 0 and p = 1, =) Edited by author 16.08.2010 03:58 |
| I don't understand problem 1193. Please help me! | raxtinhac | 1193. Очередь на зачёт | 15 авг 2010 14:01 | 13 |
What change if shift beginning time of the exam to more early time ? Please explain to me. Thank! > What change if shift beginning time of the exam to more early > time ? Please explain to me. Thank! 70 + 40 = 110 // first student (70 40 150) 110 + 15 = 125 //second one (99 15 400) 125 + 10 = 135 // third one (100 10 120), he is 15 min late, (he's to be free at 120) i hope it helps. > > What change if shift beginning time of the exam to more early > > time ? Please explain to me. Thank! > > 70 + 40 = 110 // first student (70 40 150) > 110 + 15 = 125 //second one (99 15 400) > 125 + 10 = 135 // third one (100 10 120), > he is 15 min late, (he's to be free at 120) > > i hope it helps. > does this mean third should start at 110 and second start at 110+10=120? > > > What change if shift beginning time of the exam to more early > > > time ? Please explain to me. Thank! > > > > 70 + 40 = 110 // first student (70 40 150) > > 110 + 15 = 125 //second one (99 15 400) > > 125 + 10 = 135 // third one (100 10 120), > > he is 15 min late, (he's to be free at 120) > > > > i hope it helps. > > > does this mean third should start at 110 and second start at > 110+10=120? students should start the exam as fast as they are ready (by the order of T1) so second student cannot enter the room after third one ( i suppose ;) ) if the input is 4 100 10 120 70 40 150 99 15 400 101 50 160 what's to output and why Solution: 1st) #2 starting at 70 ending at 110 2nd) #3 starting at 110 ending at 125 3rd) #1 starting at 125 ending at 135 (a +15 shift) 4th) #4 starting at 135 ending at 185 (a +25 shift) That way the answer should be 25 > if the input is > 4 > 100 10 120 > 70 40 150 > 99 15 400 > 101 50 160 > what's to output and why > if the input is > 4 > 100 10 120 > 70 40 150 > 99 15 400 > 101 50 160 > what's to output and why let's see 70 + 40 = 110 (70 40 150) 110 + 15 = 125 (99 15 400) 125 + 10 = 135 (100 10 120) 15 min late 135 + 50 = 185 (101 50 160) 25 min late if examenator shifts the beginning of the exam by 25 minutes then every student will pass the exam before T3.
> if the input is > 4 > 100 10 120 > 70 40 150 > 99 15 400 > 101 50 160 > what's to output and why Thank you hajime, I got AC. 70 + 40 = 110 // first student (70 40 150) 110 + 10 = 120 //second one (100 10 120) 129 + 10 = 139 // third one (99 15 400), he is free at 139? wait =0; > 70 + 40 = 110 // first student (70 40 150) > 110 + 10 = 120 //second one (100 10 120) > 129 + 10 = 139 // third one (99 15 400), > he is free at 139? > wait =0; Oleg i think thirs student comes in queue before second as his t1 is 99 and thirds is 100 agree? Thank all the people above! |
| I do not understand! | Jizhu3 | 1157. Юный плиточник | 15 авг 2010 09:51 | 15 |
who can explain the problem? this problem is easy, A hint: If you have a square of 16 1*16 2*8 3..no, 3 no. 4*4... and that's all...just 3... Hope this help you! :) I understand now. Thank you very much! I also understand. Thank you. :) The Big Bad Wolf (Cristina Stancu-Mara) 18 фев 2005 18:48 Thanks. Me understand too 8-) My understands these good also. Tenk u for solveishn Yeah...it's a very clever hint thank you very-very much! |
| Too simple Ac,may be checker wrong | svr | 1591. Абстрактное мышление | 14 авг 2010 20:46 | 8 |
Let S4(n),S5(n),S6(n)- number of different 4-poligons,5-poligons and 6-poligons in n poligon. I have AC using formula F(n)=4*S4(n)+5*S5(n)+S6(n). But this formula can not be right because in different 6-poligons 3 hords may intersect in the same point and this triangle will be counted more the once. Your worry is superfluous This condition (put mentally n points on its periphery at equal distances) can guarantee that there will not be different 6-poligons 3 hords may intersect in the same point and this triangle will be counted more the once P.S My English is so poor... My suspictions based on considering ideal 12-poligon in which exist two ideal 6- sub-poligons which different and distinvished by rotation and having common centre in which their hord intersected. Edited by author 01.11.2007 22:26 I doubt anyone can mentally put 2000 points on a circle =) Hah, I on the other hand believe everyone can mentally (and not only) put infinitely many points on a circle. After all - isn't that the definition of a circle? (Infinitely many points with equal distance from one other point - the center?) :D F(n)=4*S4(n)+5*S5(n)+S6(n) Why is it true and how to guess about it? a picture is needed to understand ! please assist Yes, I was thinking about it too and I understand it now. In fact, it's said in statement that interesting triangle is not a triangle but "any three different chords from this set that intersect pairwise" and "at least one of their intersection points lies inside the circle". Therefore, three segments intersecting in one point are interesting triangle( and not a triangle). It's like saying that interesting triangle is a four-sided figure =) |
| What is the output for N=1 ? | Grigor Gevorgian | 1120. Сумма последовательных чисел | 14 авг 2010 06:24 | 14 |
But if A=1,P=1 A+P-1=1, so A+(A+P-1)=2 NOT 1?Am I wrong? The sequence is an arithmetic progression upto p terms. So, when n=1, only 1 term is required ie p=1. Hope you could understand. This is my code. It gets WA#7,but I cant find my mistake.Could you help,pls? #include<iostream.h> int main() { int n,i,j,s; cin>>n; if(n==1) { cout<<"1 1"; return 0; } if(n==2) { cout<<"2 1"; return 0; } for(i=1;i<=n/2;i++) { s=i; for(j=i+1;s<n;j++) s+=j; if(s==n) { cout<<i<<" "<<j-i; return 0; } } cout<<n/2<<" "<<1; return 0; } Maximum value of a is n not n/2. Your program gives wrong answer for n=4. Your output is 2 1 while correct one is 4 1. TLE #9 Grigor Gevorgian 26 май 2008 01:27 Thanks a lot,I passed WA,but now TLE #9.This algo is too slow :( try to manipulate this : N = P*(2A + (P-1))/2 N = input A & P = output loop P to find A Right answer for 1 is 0 2 not 1 0 !!! right answer is 1 1 , because 1=1+(1-1) ok i think this should be 2 2 Maximum value of a is n not n/2. Your program gives wrong answer for n=4. Your output is 2 1 while correct one is 4 1. |
| what is the fastest algorithm? | Klyuchnikov Nikita | 1720. Summit Online Judge | 13 авг 2010 18:40 | 2 |
To do calculations while [kx,ky] and [(k+1)x,(k+1)y] not intersect is very slow solution There is an O(1) solution. |
| Why WA test 5? | Wade-Leo | 1029. Министерство | 13 авг 2010 14:42 | 2 |
Try to check array range. I got WA#5 because of the next mistake: I created array d[501][101] to count an answer (first digit is for number of stage, second - for room), but then I noticed mistake and changed it for d[101][501]. After that I got AC! |
| To people who WA#5 ! A sample test helps me AC !!! | Phan Hoài Nam - Đại học Ngoại ngữ Tin Học TP.HCM | 1078. Отрезки | 13 авг 2010 13:58 | 1 |
input : 5 1 6 2 5 3 4 10 100 20 30 wrong output : 2 5 4 right output : 3 3 2 1 Edited by author 13.08.2010 14:02 |
| After changing while(!cin.eof()) into while(1), finally accepted ! Happy : ) | Phan Hoài Nam - Đại học Ngoại ngữ Tin Học TP.HCM | 1050. Подготавливая статью | 13 авг 2010 10:06 | 1 |
|
| No subject | Zayakin Andrey[PermSU] | 1580. Долги декана | 13 авг 2010 03:35 | 1 |
No subject Zayakin Andrey[PermSU] 13 авг 2010 03:35 4 4 1 2 0 2 3 0 3 4 0 4 1 0 Impossible |
| What is Wa2? | MNKY-SU | 1012. K-ичные числа. Версия 2 | 12 авг 2010 20:58 | 1 |
|
| Can a square of an integer number be negative? | Sergey Baskakov, Raphail and Denis | 1103. Карандаши и окружности | 12 авг 2010 17:32 | 2 |
My solution resulted in Crash {FLT_INVALID_OPERATION} several times, before I understood, that the square of an integer number can be negative! Oh! What a stupid mistake!-) The crash mentioned above was caused by the following function in my source code: function Dist( const p1, p2: Point ): extended; begin Result := sqrt( sqr(p2.x-p1.x) + sqr(p2.y-p1.y) ); end; I couldn't even imagine, that sqr() function can produce negative results! So, If you get Crash on test #6, just use extended (^: Holy crap I can't believe either!! Thanks |