poj 1113 Wall (凸包),poj1113wall凸包

來源:互聯網
上載者:User

poj 1113 Wall (凸包),poj1113wall凸包

連結:poj 1113

題意:給定多邊形城堡的n個頂點,繞城堡外面建一個圍牆,圍住所有點,

並且牆與所有點的距離至少為L,求這個牆最小的長度

思路:最小長度=城堡頂點構成的凸包的總邊長+半徑為L的圓的周長

先用Graham演算法求出凸包,再枚舉其頂點求兩兩之間的邊長,記得加上第一個頂點和最後一個頂點的邊長

最後要輸出四捨五入的整數結果,可以用double存,最後用%.0lf輸出

#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;struct stu{    int x,y;}p[1010],s[1010];int m,top;int chaji(struct stu p1,struct stu p2,struct stu p3){    return (p1.x-p2.x)*(p3.y-p2.y)-(p3.x-p2.x)*(p1.y-p2.y);}double dis(struct stu p1,struct stu p2){    return sqrt((p1.x-p2.x)*(p1.x-p2.x)*1.0+(p1.y-p2.y)*(p1.y-p2.y));}int cmp(struct stu p1,struct stu p2){    int k;    k=chaji(p1,p[0],p2);    if(k>0||(k==0&&dis(p1,p[0])<dis(p2,p[0])))        return 1;    return 0;}void graham(){    struct stu t;    int k=0,i;    for(i=1;i<m;i++)        if(p[i].y<p[k].y||(p[i].y==p[k].y&&p[i].x<p[k].x))            k=i;    t=p[k];    p[k]=p[0];    p[0]=t;    sort(p+1,p+m,cmp);    s[0]=p[0];    s[1]=p[1];    top=1;    for(i=2;i<m;i++){        while(top>=1&&chaji(s[top-1],s[top],p[i])>=0)            top--;        top++;        s[top]=p[i];    }}int main(){    int n,i;    double sum;    while(scanf("%d%d",&m,&n)!=EOF){        for(i=0;i<m;i++)            scanf("%d%d",&p[i].x,&p[i].y);        graham();        sum=dis(s[0],s[top])+2*3.1415926*n;        for(i=1;i<=top;i++)            sum+=dis(s[i-1],s[i]);        printf("%.0lf\n",sum);    }    return 0;}



poj1113資料

POJ的資料貌似不外露。。
 
ACM解題報告

一個POJ題目分類
主流演算法:
1.搜尋 //回溯
2.DP(動態規劃)
3.貪心
4.圖論 //Dijkstra、最小產生樹、網路流
5.數論 //解模線性方程
6.計算幾何 //凸殼、同等安置矩形的並的面積與周長
7.組合數學 //Polya 定理
8.類比
9.資料結構 //並查集、堆
10.博弈論
1、 排序
1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376,
2377, 2380, 1318, 1877,1928, 1971, 1974, 1990, 2001, 2002, 2092, 2379,
1002(需要字元處理,排序用快排即可) 1007(穩定的排序) 2159(題意較難懂)
2231 2371(簡單排序) 2388(順序統計演算法) 2418(二叉排序樹)
2、 搜尋、回溯、遍曆
1022,1111,1118,1129,1190,1562,1564,1573,1655,2184 ,2225,2243,2312,2362,2378,2386,1010,1011,1018,1020,1054,1062,1256,1321,1363,1501,1650,1659,1664,1753,2078,2083,2303,2310,2329
簡單:1128, 1166, 1176, 1231, 1256, 1270, 1321, 1543, 1606, 1664,
1731, 1742, 1745, 1847,1915, 1950, 2038, 2157, 2182, 2183, 2381, 2386, 2426
不易:1024, 1054, 1117, 1167, 1708, 1746, 1775, 1878, 1903, 1966, 2046,
2197, 2349
推薦:1011, 1190, 1191, 1416, 1579, 1632, 1639, 1659, 1680, 1683, 1691,
1709, 1714, 1753,1771, 1826, 1855, 1856, 1890, 1924, 1935, 1948, 1979, 1980, 2170,2288, 2331, 2339,2340,1979(和迷宮類似),1980(對剪枝要求較高)
3、 曆法
1008 2080 (這種題要小心)
4、 枚舉
1012,1046, 1387, 1411, 2245, 2326, 2363, 2381,1054(剪枝要求較高),1650 (小數的精度問題)
5、 資料結構的典型演算法
容易:1182, 1656, 2021, 2023, 2051, 2153, 2227, 2236, 2247, 2352,
2395
不易:1145, 1177, 1195, 1227, 1661, 1834
推薦:1330, 1338, 1451, 1470, 1634, 1689, 1693, 1703, 1724, 1988, 2004,
2010, 2119, 2274
1125(弗洛伊德演算法) ,2421(圖的最小產生樹)
6、 動態規劃
1037 A decorative fence、
1050 To the Max、
1088 滑雪、
1125 Stockbroker Grapevine、
1141 Brackets Sequence、
1159 Palindrom......餘下全文>>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.