বৃহস্পতিবার, ২২ অক্টোবর, ২০১৫

[Non Standard] uva The easiest way

Problem id : uva The easiest way



It's just an ad-hoc problem.I didn't even use my geometry template :-P .The solution is to take the max possible area for all of these cases.

Code :



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <bits/stdc++.h>
#define sqr(x) (x*x)
using namespace std;

int main()
{
   int N;
   while(scanf("%d",&N)==1)
   {
       if(N==0)break;

       ///possible answers : w/2 , w , h/4
       ///For all pieces of papers we'll calculate maximum
       ///possible area of the 4 paper birds them and store
       ///them with their index .And finally we'll find the max
       ///of them
       int idx = 0;int ans = 1;
       double max_area=0.00000000f;
       while(N--)
       {
           idx++;
           int t_w,t_h;
           scanf("%d %d",&t_w,&t_h);
           int w,h;
           h = max(t_h,t_w);
           w = t_w+t_h - h;
           double t_area;
           if(h/4*1.00000000f < w)
           t_area = sqr(h/4*1.0000000f);
           else
            t_area = sqr(w);
           if(sqr(w/2*1.000000000f) > t_area)
            t_area = sqr(w/2*1.0000000f);

           if(t_area > max_area)
           {
               ans = idx;
               max_area = t_area;
           }

       }



       printf("%d\n",ans);

   }
    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন