ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

poj1113--Wall(͹°ü)
2015-07-20 17:22:58 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:1´Î
Tags£ºpoj1113--Wall ͹°ü
Wall
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 30701 Accepted: 10340

Description

Once upon a time there was a greedy King who ordered his chief Architect to build a wall around the King's castle. The King was so greedy, that he would not listen to his Architect's proposals to build a beautiful brick wall with a perfect shape and nice tall towers. Instead, he ordered to build the wall around the whole castle using the least amount of stone and labor, but demanded that the wall should not come closer to the castle than a certain distance. If the King finds that the Architect has used more resources to build the wall than it was absolutely necessary to satisfy those requirements, then the Architect will loose his head. Moreover, he demanded Architect to introduce at once a plan of the wall listing the exact amount of resources that are needed to build the wall.
\

Your task is to help poZ??http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vciBBcmNoaXRlY3QgdG8gc2F2ZSBoaXMgaGVhZCwgYnkgd3JpdGluZyBhIHByb2dyYW0gdGhhdCB3aWxsIGZpbmQgdGhlIG1pbmltdW0gcG9zc2libGUgbGVuZ3RoIG9mIHRoZSB3YWxsIHRoYXQgaGUgY291bGQgYnVpbGQgYXJvdW5kIHRoZSBjYXN0bGUgdG8gc2F0aXNmeSBLaW5n"s requirements.

The task is somewhat simplified by the fact, that the King's castle has a polygonal shape and is situated on a flat ground. The Architect has already established a Cartesian coordinate system and has precisely measured the coordinates of all castle's vertices in feet.

Input

The first line of the input file contains two integer numbers N and L separated by a space. N (3 <= N <= 1000) is the number of vertices in the King's castle, and L (1 <= L <= 1000) is the minimal number of feet that King allows for the wall to come close to the castle.

Next N lines describe coordinates of castle's vertices in a clockwise order. Each line contains two integer numbers Xi and Yi separated by a space (-10000 <= Xi, Yi <= 10000) that represent the coordinates of ith vertex. All vertices are different and the sides of the castle do not intersect anywhere except for vertices.

Output

Write to the output file the single number that represents the minimal possible length of the wall in feet that could be built around the castle to satisfy King's requirements. You must present the integer number of feet to the King, because the floating numbers are not invented yet. However, you must round the result in such a way, that it is accurate to 8 inches (1 foot is equal to 12 inches), since the King will not tolerate larger error in the estimates.

Sample Input

9 100
200 400
300 400
300 300
400 300
400 400
500 400
500 200
350 200
200 200

Sample Output

1628

Hint

½á¹ûËÄÉáÎåÈë¾Í¿ÉÒÔÁË

Source

Northeastern Europe 2001

Çó³öΧסÕâ¸ö³Ç±¤µÄΧǽµÄ×îСֵ£¬Î§Ç½¾àÀë³Ç±¤×îµÍ²»ÄÜСÓÚl

ËùÒÔ½á¹û= ³Ç±¤µÄ͹°ü±ß³¤ + lµÄÔ²Öܳ¤¡£

ÔÚÕâ¸öÌâÖÐÇó͹°üµÄʱºò£¬½øÐм«½ÇÅÅÐò->ѹÈë½Úµã->·ÖÀàÈç¹ûmul(q2,q1,p[i]) = 1 Ö±½ÓѹÈë->= 0 Å׳öÕ»Ê׵Ľڵ㣬ѹÈëнڵã-> = -1Ö»Å׳öÕ»Ê׵Ľڵãi--¡£

#include 
  
   
#include 
   
     #include 
    
      #include 
     
       #include 
      
        using namespace std ; #define eps 1e-8 #define PI 3.141592653589793238462643383279502884197169399375105820974944 struct node{ double x , y ; }p[11000] , q , q1 , q2 ; stack 
       
         sta ; node sub(node a,node b) { a.x -= b.x ; a.y -= b.y ; return a ; } int mul(node q,node a,node b) { a = sub(a,q) ; b = sub(b,q) ; double x = a.x*b.y - a.y*b.x ; if( fabs(x) < eps ) return 0 ; else if( x > 0 ) return 1 ; return -1 ; } int dis(node q,node a,node b) { a = sub(a,q) ; b = sub(b,q) ; double k1 = a.x*a.x + a.y*a.y , k2 = b.x*b.x + b.y*b.y ; if( fabs(k1-k2) < eps ) return 0 ; else if( k1-k2 > eps ) return 1 ; return -1 ; } int cmp(node a,node b) { int k1 = mul(q,a,b) , k2 = dis(q,a,b) ; return k1 == 1 || (k1 == 0 && k2 == -1) ; } int main() { int n , i , j ; double r , ans ; while( scanf("%d %lf", &n, &r) != EOF ) { q.x = q.y = 11000.0 ; for(i = 0 ; i < n ; i++) { scanf("%lf %lf", &p[i].x, &p[i].y) ; if( p[i].y < q.y || ( fabs(p[i].y-q.y ) < eps && p[i].x < q.x ) ) q = p[i] ; } sort(p,p+n,cmp) ; while( !sta.empty() ) sta.pop() ; sta.push(p[0]) ; sta.push(p[1]) ; for(i = 2 ; i < n ; i++) { //printf("%lf %lf*\n", p[i].x, p[i].y) ; q1 = sta.top() ; sta.pop() ; q2 = sta.top() ; sta.pop() ; int k = mul(q2,q1,p[i]) ; if( k == 1 ) { sta.push(q2) ; sta.push(q1) ; sta.push(p[i]) ; } else if( k == 0 ) { sta.push(q2) ; sta.push(p[i]) ; } else { sta.push(q2) ; i-- ; } } n = 1 ; while( !sta.empty() ) { p[n++] = sta.top() ; //printf("%lf %lf\n", p[n-1].x, p[n-1].y); sta.pop() ; } ans = 2.0*PI*r ; for(i = 0 ; i < n-1 ; i++) { ans += sqrt( (p[i].x-p[i+1].x)*(p[i].x-p[i+1].x)*1.0 + (p[i].y-p[i+1].y)*(p[i].y-p[i+1].y)*1.0 ) * 1.0 ; } printf("%.0f\n", ans) ; } return 0; } 
       
      
     
    
   
  

¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºCodeforces Round #288 (Div. 2) ÏÂһƪ£º(hdu step 1.3.1)FatMouse' T..

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)