Page 1 Check the way how you find the upper radius if h>d. Had WA 16 because i checked if the plates can fit with > instead of >= (the upper part of the plates can touch.) Also, if the height of the box is smaller than the plates, and the plates margin fall out of the box, don't forget that their full margins can't touch each other! Example test: 4 8 1 1 3 1 3 2 Answer: NO God bless you man! This is what I forgot to check an I got WA#28. This post should be more appreciated! //package timus; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Scanner; public class p1793 { public static void main(String[] args) { InputStream is = System.in; Scanner sc = new Scanner(new InputStreamReader(is)); double a,b,h,r1,r2,R1,R2,H,rr1,rr2,x1,y1,x2,y2,D,d; boolean inside1,inside2; a = sc.nextInt(); b = sc.nextInt(); h = sc.nextInt(); r1 = sc.nextInt(); R1 = sc.nextInt(); r2 = sc.nextInt(); R2 = sc.nextInt(); H = sc.nextInt(); rr1 = R1; rr2 = R2; if (H >= h) { double d1,d2; d1 = (R1-r1)/2.0; d2 = (R2-r2)/2.0; rr1 = 2*d1 * h / H + r1; rr2 = 2*d2 * h / H + r2; } inside1 = 2.0 * rr1 <= a && 2.0 * rr2 <= b; inside2 = 2.0 * rr1 <= b && 2.0 * rr2 <= a; if (!inside1 || !inside2) { System.out.println("NO"); return; } x1 = rr1; y1 = rr1; x2 = a - rr2; y2 = b - rr2; D = R1 + R2; d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1); if (d >= D * D) { if ((x2 - x1 + rr1 + rr2) <= a && (y2 - y1 + rr1 + rr2) <= b) System.out.println("YES"); else System.out.println("NO"); } else { System.out.println("NO"); } } } You can solve this with as little as two if statements (and one use of the min function) - first, check where the center of the trays need to be in relation to the sides, and second, make sure that the plates don't overlap. Anton Chaplygin [Kungur] [Psych Up club] WA 15 [1] // Problem 1793. Tray 2 11 Aug 2012 20:58 If you have WA15, you should think about the height of the plate and the height of the box. I don't think so. I think about it and I have WA15. Can anybody help me? I have the same WA :( Help anybody, please ! :D To get AC you should guess, that you could rotate plates upside down! that is absurd, as I think for plates with a lunch! I see a lot of talking about precision. that you should use integer instead of floating point. but I've got AC using "double" after I accidently understood what the real problem is. You are wrong. The plates are actually with lunch and could't be rotated upside down. :) So, I've deleted "rotation" and got WA20. If you are right it means that I used to get AC by wrong algo. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Тарелки2 { class Program { static void Main(string[] args) { string[] parampidn = Console.ReadLine().Split(' '); int a = int.Parse(parampidn[0]); int b = int.Parse(parampidn[1]); int d = int.Parse(parampidn[2]); string[] muska1 = Console.ReadLine().Split(' '); int r1 = int.Parse(muska1[0]); int r2 = int.Parse(muska1[1]); int minradmuska1 = 0, maxradmuska1 = 0; if (r1 > r2) { maxradmuska1=r1; } else r2 = maxradmuska1; if (r2 > r1) { minradmuska1 = r1; } else minradmuska1 = r2; string[] muska2 = Console.ReadLine().Split(' '); int R1 = int.Parse(muska2[0]); int R2 = int.Parse(muska2[1]); int minradmuska2=0, maxradmuska2=0; if (R1 > R2) { maxradmuska2 = R1; } else maxradmuska2 = R2; if (R2 > R1) { minradmuska2 = R1; } else minradmuska2 = R2; int h = int.Parse(Console.ReadLine()); int minst=0, maxst=0, maxradvel12; if (maxradmuska1>maxradmuska2) { maxradvel12=maxradmuska1; } else maxradvel12=maxradmuska2; if (a>b) { minst=b; } else minst =a; if (a>b) { maxst=a; } else maxst=b; if (((2*maxradmuska1+2*maxradmuska2)<=maxst)&&(2*maxradvel12<=minst)&&(2*maxradmuska1+2*maxradmuska2<= Math.Sqrt((double)a*a+(double)b*b))) { Console.WriteLine("YES"); } else { Console.WriteLine("NO"); } } } } Hi, my solution is: #include <iostream> #include <cstdio> #include <cmath> #include <stdlib.h> #include <valarray> using namespace std; double const pi=acos(-1.0); int main() { long long a,b,d; cin >> a >> b >> d; long long R1, r1, R2, r2, h; cin>>r1>>R1>>r2>>R2>>h; if( pi*R1*R1+pi*R2*R2>a*b || 2* max(r1,r2) > min(a,b)) { cout<<"NO"<<endl; return 0; } if(d>=h && 2*max(R1,R2) > min(a,b)) { cout<<"NO"<<endl; return 0; } else cout <<"YES"<<endl; return 0; } But is wrong, ofcourse. Add new tests, please =) Please, give me any test for WA #13 Never mind... Edited by author 21.11.2011 18:09 Edited by author 21.11.2011 18:10 In fact, it cost me 4 submissions to get accepted. However, I still think that this is a problem with simple geometry. However, some confusion in the problem statement rather made a big trouble for me. The problem statement said that the plates had the shape of truncated cones. However, it still remains a problem, that which bottom of the truncated cone is larger. By the common sense, the upper bottom of the cone should be larger, and it is indeed so in the testdata (I have submitted a checker for this), but the fact does not appear in the statements. PS: even if the lower bottom is larger, my program could still give the correct results. Secondly, the height of the tray need NOT be larger than (or equal with) the height of the cones. If the height of tray is smaller, the plates could still fit in the tray, and in this situation, some part of the plates could even be outside the tray. So important the condition is, it doesn't appear in the problem statements at all! I could not understand this. And, at last, I want to give the last hint to all authors: try to solve this problem by 64-bit integers. Floating point numbers might bring in errors, which you don't want to see. Oops! Of course, the radius of plate's edge is greater than the radius of plate's bottom. I have fixed the problem statement. Well, I think that correcting the second confusion could be more important. Or, is this an intentional trap of this problem? It's good idea to use 64-bit fractional arithmetic. #include <iostream> #include <algorithm> using namespace std; __int64 gcd( __int64 a, __int64 b ) { return b? gcd( b, a%b ) : a ; } class drobT { public : __int64 u, d; drobT() { u = 0; d = 1; } friend drobT socr ( drobT a ) { __int64 div, x, y; x = (a.u>=0)? a.u : -1*a.u; y = (a.d>=0)? a.d : -1*a.d; div = gcd( max(x,y), min(x,y) ); a.u /= div; a.d /= div; return a; } friend drobT operator + ( const drobT& a, const drobT& b ) { drobT c; c.u = a.u * b.d + b.u * a.d; c.d = a.d * b.d; return socr(c); } friend drobT operator - ( const drobT& a, const drobT& b ) { drobT c; c.u = a.u * b.d - b.u * a.d; c.d = a.d * b.d; return socr(c); } friend drobT operator * ( const drobT& a, const drobT& b ) { drobT c; c.u = a.u * b.u; c.d = a.d * b.d; return socr(c); } friend drobT operator * ( const __int64& a, const drobT& b ) { drobT c; c.u = a * b.u; c.d = b.d; return socr(c); } friend drobT operator / ( const drobT& a, const drobT& b ) { drobT c = b; if( c.u < 0 ) { c.u = -c.u; c.d = -c.d; } swap( c.d, c.u ); return socr(c * a); } friend bool operator <= ( drobT a, drobT b ) { return a.u*b.d <= a.d*b.u;} friend bool operator <= ( const __int64 a, drobT b ) { return a*b.d <= b.u;} friend bool operator < ( drobT a, drobT b ) { return a.u*b.d < a.d*b.u; } friend bool operator < ( const __int64 num, drobT b ) { return num*b.d < b.u; } friend drobT pow2( const drobT& a ){ return a*a; } }; //input istream& operator >> ( istream& cin, drobT& dr ) { cin >> dr.u; dr.d = 1; return cin; } /* secret code) */ Wow, it's a good template for double-precision calculations. However, this problem could be solved with single-precision __int64 numbers. Can anyone tell me my mistake. Here is my code. Thanks #include <iostream> #include <sstream> #include <string> #include <vector> #include <deque> #include <queue> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <cstring> //#include <conio.h> using namespace std; #define oo 1000000000 #define fi first #define se second #define sqr(a) ((a)*(a)) #define FR(i,n) for (int i = 0; i < (n); i++) #define DN(i,a) for(int i = (a)-1; i >= 0; i--) #define FOR(i,a,b) for (int i = (a); i <= (b); i++) #define DOWN(i,a,b) for(int i = (a); i >= (b); i--) #define FORV(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end(); i++) typedef pair<int, int> PII; typedef vector<int> VI; double kc(double x1, double y1, double x2, double y2) { return sqrt(sqr(x1 - x2) + sqr(y1 - y2)); } int main () { double a, b, d, r11, r12, r21, r22, h; cin >> a >> b >> d; cin >> r11 >> r12 >> r21 >> r22 >> h; if (2 * max(r21, r11) > min(a, b)) { cout << "NO" << endl; return 0; } double x1 = r11, y1 = r11; double x2 = a - r21, y2 = b - r21; if (kc(x1, y1, x2, y2) < r11 + r21) { cout << "NO" << endl; return 0; } if (d >= h) { if (2 * max(r12, r22) > min(a, b)) { cout << "NO" << endl; return 0; } double x1 = r12, y1 = r12; double x2 = a - r22, y2 = b - r22; if (kc(x1, y1, x2, y2) < r12 + r22) { cout << "NO" << endl; return 0; } } if (d < h) { double r1m = d * (r12 - r11) / h + r11; double r2m = d * (r22 - r21) / h + r21; if (2 * max(r1m, r2m) > min(a, b)) { cout << "NO" << endl; return 0; } double x1 = r1m, y1 = r1m; double x2 = a - r2m, y2 = b - r2m; if (kc(x1, y1, x2, y2) < r1m + r2m) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; return 0; } You're using sqrt which loses precision. you should use int64. I really appreciate your help guys, please give a test, I spend so much time to solve this problem, now I don't wanna leave it like that. Now I have WA23, any ideas? Если вы отсекли тарелки (мысленно), они все равно не могут быть ближе чем им позволяют их настоящие радиусы Thank you very much. You helped me a lot. Edited by author 22.08.2011 04:12 Are there exactly two plates to be put on the tray or can there be more/less than two? Can someone clarify this for me? Thanks! #include <iostream> #include <cmath> using namespace std; int max (int a,int b) { return a>b? a:b;} int min (int a,int b) { return a>b? b:a;} double const pi=acos(-1.0); int main() { int a,b,d; int r1,r2,R1,R2,h; cin>>a>>b>>d>>r1>>R1>>r2>>R2>>h; if (2*max(R1,R2)<=min(a,b) && pi*R1*R1+pi*R2*R2<=a*b) { cout<<"YES"; return 0; } cout<<"NO"; return 0; } Edited by author 03.07.2011 21:46 Don't forget about case when h > d (so trays are touching plate a little bit lower) and try to place trays in opposite corners of plate. WA 28 Why??? please help me... cause you're an asshole lol =D people! who has any ideas? What about test 13? What is test ??!?!?! Check if the plate fits in the tray I check plate if in tray but WA 13 !!! people! who has any ideas? Do you found test or reason for WA 25? I also had that problem but when I checked if big plate is placed in tray (2 * r > b here r is the radius of cone at the height d (d < h) and b is small side of tray). But now I have wa on test31 good luck I also had that problem but when I checked if big plate is placed in tray (2 * r > b here r is the radius of cone at the height d (d < h) and b is small side of tray). But now I have wa on test31 good luck Thanks. I can add, that we must check: 0 <= x + r && x + r <= w && 0 <= x - r && x - r <= w && 0 <= y + r && y + r <= h && 0 <= y - r && y - r <= h; for both plate x,y - coordinates of plate center's, r - minimal radius of plate, w,h - max(a,b), min(a,b) Test: 2 10 1 1 3 1 3 2 Ans: NO Edited by author 17.10.2010 03:31thanks your test helped me a lot. Thanks again I've read all the advice: my code meets all of them. Any other suggestions on WA25? Maybe someone is ready to look at my code? My e-mail is in my info. Thanks for any help. I made a stupid mistake while reading the input data. First I read bottom sides and then top sides. Surprisingly, this solution bring me to WA25 and half-an-hour debugging. It turned out I had read data in the same wrong manner and also got WA25! MAK, your advice was the most useful in this discussion )) Edited by author 17.10.2010 03:39 Yes! It was a very stupid mistake! I checked if radius of plates on the height d is not greater than a and not grater than b. But I should check their diameter instead it! This fact costed me 13 fail submissions... Try this test: 9 15 1 1 2 1 5 1 Answer is NO. Why NO? First (d=2)koord: 2 2 Second (d=5) koord: 4 10 I think YES, but WA 25... This test helped me on WA25: 20 28 1 1 2 11 12 1 Answer: NO. Pages: 1 |
|