Common Board| Show all threads Hide all threads Show all messages Hide all messages | | Precision problem... again | Vlad | 1084. Goat in the Garden | 25 Jan 2014 01:54 | 1 | #include <iostream> #include <fstream> #include <cmath> #define PI 3.14159265358979323846 using namespace std; #ifndef ONLINE_JUDGE #define cin fin ifstream fin("input"); #endif double N, R; int main() { cin >> N >> R; N /= 2.0;
if (R <= N) { cout << PI * R * R << '\n'; return 0; } if (R >= N * sqrt(2.0)) { cout << 4.0 * N * N << '\n'; return 0; }
double A, B, C; A = N; C = R; B = sqrt(C * C - A * A); double angle = 90.0 - (acos(A / C) * 180.0 / PI) * 2.0;
printf("%.3lf\n", 4.0 * (A * B + PI * R * R * angle / 360.0)); } This program works fine on all the tests I saw on the forum. But I get WA #1 probably because of the wrong precision. I printed the value with 4 and 6 decimals but I get the same WA #1. Could anyone tell me please how can I solve the "error" ? It's annoying to have a good solution and take WA. Thanks a lot! LATER EDIT: It seems I succeeded with such a function: inline void precise(double X, const int &decimals) { cout << (int)(X); cout << '.'; X = X - (int)(X); for (int i = 1; i <= decimals; ++i) { X = X * 10.0; cout << (int)(X); X = X - (int)(X); } cout << '\n'; } ... precise((double)(4.0 * (A * B + PI * R * R * angle / 360.0)), 3); Have fun! Edited by author 25.01.2014 04:19 | | Why stack overflow? Help me, please! | Daniil | 1510. Order | 24 Jan 2014 22:35 | 2 | #include<iostream> using namespace std; int main () { int n,a[500000],d,max=0,maxi; cin>>n; for (int i=0;i<n;i++) { cin>>d; a[d]++; if (a[d]>max) { max=a[d]; maxi=d; } } cout<<maxi; return 0; } 0 ≤ K ≤ 10^9 Edited by author 20.05.2014 20:54 | | ac c++ | lhyx1990 | 1197. Lonesome Knight | 24 Jan 2014 20:07 | 1 | ac c++ lhyx1990 24 Jan 2014 20:07 #include <iostream> #include <stdio.h> #include <vector> using namespace std; class Place { public: char x; int y;
bool isOnboard() { if (x < 'a' || x > 'h' || y < 1 || y > 8) return false; return true; }
Place(char x, int y) { this->x = x; this->y = y; }
}; int main(int argc, const char * argv[]) { int N; cin >> N;
vector<Place> places;
for (int i = 0; i < N; i++) { char x; int y; cin.get(x);
if (x == '\n') { i--; continue; }
cin >> y;
Place place (x, y); places.push_back(place);
}
for (int i = 0; i < N; i++) { Place place = places[i]; int moves = 0;
//left 2 up 1 place.x -= 2; place.y -= 1; moves += place.isOnboard();
//left 2 down 1 place.y += 2; moves += place.isOnboard();
//right 2 down 1 place.x += 4; moves += place.isOnboard(); //right 2 up 1 place.y -= 2; moves += place.isOnboard(); //right 1 up 2 place.x -= 1; place.y -= 1; moves += place.isOnboard(); //left 1 up 2 place.x -= 2; moves += place.isOnboard(); //left 1 down 2 place.y += 4; moves += place.isOnboard(); //right 1 down 2 place.x += 2; moves += place.isOnboard();
cout << moves << endl;
}
} Edited by author 24.01.2014 20:07 | | Solution for larger input | mylyanyk.ivan[Lviv_NU] | 1152. False Mirrors | 24 Jan 2014 14:31 | 3 | Hi, I'm interested if there is solution for larger N like 1000 and even more? Thanks. Edited by author 25.03.2013 01:28 Edited by author 24.01.2014 14:55 Edited by author 24.01.2014 14:33 | | Why WA1? | Andrew Sboev | 1471. Distance in the Tree | 24 Jan 2014 13:26 | 4 | I'm using Floyd-Warshall algorithm, and my program correctcly passes different tests, but i have WA1. Why? Floyd-Warshall algorithm? But it's too slow. Use LCA. Maybe it is slow, but it works correctly :)Should be TLE, not WA1 :) Use std::cout. I had such problem when I used <fstream> | | wrong answer on test 1 | kirill | 1471. Distance in the Tree | 24 Jan 2014 13:18 | 1 | My program works true on test from conditions and on two my tests. Tell me please, what's a problem? | | What's the correct answer for these tests? Have a look... | Alexey | 1244. Gentlemen | 23 Jan 2014 21:29 | 8 | 1) 3 2 1 2 2) 614 13 627 861 527 911 751 658 568 846 998 188 923 426 685 3) 1560 19 580 594 644 62 963 718 291 532 293 77 356 984 384 182 986 915 18 671 920 4) 555 27 816 170 523 595 471 313 970 877 465 50 819 517 721 143 394 872 905 462 346 639 193 902 945 927 133 401 410 5) 800 15 10 20 30 40 50 60 70 80 90 100 110 120 130 200 350 6) 1458 17 802 204 451 575 158 168 247 15 50 100 1000 257 354 125 358 125 268 Thanks. Edited by author 22.06.2006 19:08 Edited by author 23.06.2006 12:20 My answer: 1. -1 2. 1 2 3 4 5 6 7 8 9 11 13 3. 2 3 4 5 6 8 9 10 11 12 13 14 15 16 19 4. 0 At me now wrong answer 12. Give me tests. I used DP, but I have found a mistake{an error} at a conclusion-1. Can give me what that ideas! Help!!! Thanks 1)0 2)1 2 3 4 5 6 7 8 9 11 13 3)-1 4)0 5)-1 6)-1 Your test#1 doesn't match the description that "It's guaranteed that the total weight of all cards in the complete pack is strictly greater than the weight of the incomplete pack." | | NEED translate into RUSSIAN (to admins) | daminus | 1058. Chocolate | 23 Jan 2014 20:12 | 2 | Please, write there translated (RUSSIAN) version of this problem!!!! or you can send there for my adress daminus_corp@mail.ru > Thanks!!!! Вам даны координаты вершин полигона, надо найти такую линию, концы которой лежат на сторонах или вершинах многоугольника, что она разделит данный многоугольник на два равных по площади многоугольника. | | Brainbreaking text, brainless task. | Komendantian Grant Mikaelovich SSAU | 1228. Array | 23 Jan 2014 19:52 | 8 | Absolutely right, Grant! I entirely agree with you. Easy when you understand it. It took me the monthes to understand how stupid this problem is. I wanted do this problem with brute force, by recursion, a lot of different ways, until I understood. Any way, this problem is really stupid.)) i solved it but still didn't get what the problem is "Brainbreaking text, brainless task" - exactly It took me 20 minutes to solve it.)) (the hardest part is to read the text and to write the code). )) This problem doesn't help improving any algorithm but it improves your mind to translate your understanding to easy code. (I think) Edited by author 23.01.2014 19:53 | | Why WA#25???? My alg is correct 100%!!! | Akshin Salimov | 1348. Goat in the Garden 2 | 22 Jan 2014 15:05 | 14 | Oh no WA#25! Please help me! var a1,a2,a3,h,s,aa,bb:real; a:array[1..3,1..2] of integer; i,l:integer; procedure readdata; begin readln(a[1,1],a[1,2],a[2,1],a[2,2]); readln(a[3,1],a[3,2],l); end; procedure writedata; begin if aa>=0 then writeln(aa:0:2) else writeln('0.00'); if bb>=0 then writeln(bb:0:2) else writeln('0.00'); end; function d(x1,y1,x2,y2:integer):real; begin d:=sqrt(sqr(x1-x2)+sqr(y1-y2)); end; procedure square; var p:real; begin a1:=d(a[1,1],a[1,2],a[2,1],a[2,2]); a2:=d(a[3,1],a[3,2],a[2,1],a[2,2]); a3:=d(a[1,1],a[1,2],a[3,1],a[3,2]); p:=(a1+a2+a3)/2; s:=sqrt(p*(p-a1)*(p-a2)*(p-a2)); end; begin readdata; square; if (a[1,1]=a[2,1]) and (a[1,2]=a[2,2]) then begin aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); bb:=aa; end else begin if (a1*a1+a2*a2<a3*a3) or (a2*a2+a3*a3<a1*a1) or (a1*a1+a3*a3<a2*a2) then begin aa:=d(a[1,1],a[1,2],a[3,1],a[3,2]); if d(a[2,1],a[2,2],a[3,1],a[3,2])<aa then aa:=d(a[2,1],a[2,2],a[3,1],a[3,2]); end else begin h:=d(a[1,1],a[1,2],a[2,1],a[2,2]); aa:=s/(0.5*h); end; bb:=d(a[3,1],a[3,2],a[2,1],a[2,2]); if d(a[3,1],a[3,2],a[1,1],a[1,2])>bb then bb:=d(a[3,1],a[3,2],a[1,1],a[1,2]); end; aa:=aa-l; bb:=bb-l; writedata; end. Try this test: ---input -5 0 5 0 1 0 1 ---correct output 0.00 5.00 No, you are mistaken correct answer is 3.00 5.00 Here is explanation: * is 0 point A B C are points. <-----A----*C---B-----> ... ... = 3.00 I dont know how you got 0.00 , please explain, maybe you are right. Edited by author 16.04.2005 23:03 Distance from A up to B = 0 And to get up to point A and B a cord it is necessary to extend on 5.00 Can we discuss this problem via e-mail? akshinioi@yahoo.com Edited by author 17.04.2005 02:15 yes i know russian language. " And to get up to point A and B a cord it is necessary to extend on 5.00 " - I agree with that. But distance between A and B isnt 0, if -5+5=0 that doesnt mean that the distance equal to nil! OR explain in details how did you get this --> "Distance from A up to B = 0 " "... There is a bed of pineapples that he loves very much. The bed is a **line segment** with the ends A and B... " Point C is situated on segment AB, so there are no grounds to stretch the roap - goat anyhow can eat some pine apples, even if rope has length 0. There are infinite amount of pine apples on segment! Mail me to dkorduban[at]ukr[dot]net if you still have questions. Sorry for my English. I'm sorry, I understood my mistake. When I use linear equation for this case, i got WA#3!!! I dont know why. Please help me, how to make my program to get AC? 1) Read this nice article (in Russian): http://g6prog.narod.ru/cgeom.rar 2) Completely rewrite your program. Try to create more general program, without dozens of special cases. That's general and very useful rule (imho) for geometrical problems. For example, there is only one special case in my program - when A = B. Of course, I can send you my AC code, if you need. Thx for this test! WA #4 fixed now :) Послано Korduban [Kiev] 16 апр 2005 19:04 Try this test: ---input -5 0 5 0 1 0 1 ---correct output 0.00 5.00 Edited by author 07.11.2013 20:49 Btw, some pretty test is: 5 0 5 0 1 0 1 Correct output is 3.00 3.00 | | WA 6.... | Pushkar Mishra | 1452. Pascal vs. C++ | 22 Jan 2014 11:18 | 2 | WA 6.... Pushkar Mishra 21 Mar 2013 10:02 Can anybody suggest me the 6th test case? В натуре спотыкается.В чем соль? Где зарыта собака? Edited by author 22.01.2014 11:56 | | Recursion ? | ZamNick | 1152. False Mirrors | 22 Jan 2014 03:53 | 1 | I've wrote recursion and got AC with 0.109 s ..... Can anybody tell me how to solve it using DP ? | | WA on #16 | Evgeniy_Chernobrovkin(MUCTR-2013) | 1723. Sandro's Book | 22 Jan 2014 03:45 | 1 | WA on #16 Evgeniy_Chernobrovkin(MUCTR-2013) 22 Jan 2014 03:45 | | accepted | Sunnat | 1200. Horns and Hoofs | 21 Jan 2014 03:50 | 3 | 0.156s O(k) How to solve it faster? P.S. Cool problem) Edited by author 09.01.2013 16:32 | | Be attentive to take AC | Evgeniy_Chernobrovkin(MUCTR-2013) | 1335. White Thesis | 21 Jan 2014 03:33 | 1 | It takes 15 minutes to me to understand, that output line have to be in decrease order! | | cin/cout hint | ASK | 1915. Titan Ruins: Reconstruction of Bygones | 21 Jan 2014 00:26 | 1 | No need for scanf/printf, just do cin.sync_with_stdio(false) and get 0.5 seconds with 13 lines of code (hint: use deque). | | AC (cpp) | lhyx1990 | 1787. Turn for MEGA | 20 Jan 2014 23:51 | 2 | // // main.cpp // p1787 // // Created by Huan Lin on 21/1/14. // Copyright (c) 2014 Huan Lin. All rights reserved. // #include <iostream> #include <stdio.h> using namespace std; int main(int argc, const char * argv[]) { int k,n; cin >> k >> n;
int jam = 0; for (int i = 0; i < n; i++) { int num; cin >> num;
jam = jam + num - k; if (jam < 0) jam = 0;
}
cout << jam; } | | Compilation error...why?? (Java 1.7) | 151382OF | 1000. A+B Problem | 20 Jan 2014 23:35 | 1 | package timus; class timus {
public static void main (String args[]) { int a = 1,b = 5; System.out.println(a+b); } } Edited by author 20.01.2014 23:38 Edited by author 20.01.2014 23:38 | | почему не правильно? задача 1820 | arianavaleria | | 20 Jan 2014 21:41 | 1 | var n,k: integer; x,t:real; begin read(n,k); x:=n/k; if (Frac(x)>0) then if (Frac(x)>0.5) then t:=(trunc(x)+1)*2 else if (trunc(x)=0) then t:=2 else t:=trunc(x)*2+1 else t:=x*2; writeln('t=',t); end. | | #WA 5. Help! | Anatoly | 1433. Diamonds | 20 Jan 2014 19:56 | 1 | Please give any tests. I tried some but my program succesfully done them.. |
|
|