• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            pku2991 Crane 線段樹的好題

            簡述題意:
            一堆豎直依次排列,端點處連接起來?,F在給出這樣一種操作,將第i個桿子和第i+1個桿子直接的角度調整為180+degree,當然,i+1個桿子以后的桿子連著它一起轉動。求最后一個桿子的坐標
            可以這樣設置線段樹的域
            1 struct
            2 {
            3     int s,e;
            4     double x,y;
            5     int turn;
            6 }st[N];
            turn代表當前線段整體旋轉過的角度
            維護策略可以這樣寫:用到了坐標的旋轉變換矩陣:
            |cosx -sinx |
            |sinx  cosx|
             1 inline void change(double &x,double &y,double turn)
             2 {
             3     double tx=x,ty=y;
             4     x=cos(turn)*tx-sin(turn)*ty;
             5     y=sin(turn)*tx+cos(turn)*ty;
             6 }
             7 inline void update(int pos,int add)
             8 {
             9     st[pos].turn=(st[pos].turn+add)%360;
            10     change(st[pos].x,st[pos].y,degree(add%360));
            11 }
            其他標記下移什么的和普通線段樹一樣,就不贅述了,貼代碼
             1# include <cstdio>
             2# include <cmath>
             3using namespace std;
             4const int N=50000;
             5const double eps=1e-6;
             6# define degree(a) ((a)/180.0*3.141592653)
             7struct
             8{
             9    int s,e;
            10    double x,y;
            11    int turn;
            12}
            st[N];
            13int len[N];
            14inline void change(double &x,double &y,double turn)
            15{
            16    double tx=x,ty=y;
            17    x=cos(turn)*tx-sin(turn)*ty;
            18    y=sin(turn)*tx+cos(turn)*ty;
            19}

            20inline void update(int pos,int add)
            21{
            22    st[pos].turn=(st[pos].turn+add)%360;
            23    change(st[pos].x,st[pos].y,degree(add%360));
            24}

            25void init(int s,int e,int pos=1)
            26{
            27    st[pos].s=s;
            28    st[pos].e=e;
            29    st[pos].turn=0;
            30    if(e==s+1)
            31        st[pos].y=len[s],st[pos].x=0;
            32    else
            33    {
            34        init(s,(s+e)>>1,pos<<1);
            35        init((s+e)>>1,e,(pos<<1)+1);
            36        st[pos].y=st[pos<<1].y+st[(pos<<1)+1].y;
            37        st[pos].x=0;
            38    }

            39}

            40int get(int target,int pos=1)
            41{
            42    if(st[pos].e==st[pos].s+1return st[pos].turn;
            43    else if(target<((st[pos].s+st[pos].e)>>1)) return st[pos].turn+get(target,pos<<1);
            44    else return st[pos].turn+get(target,(pos<<1)+1);
            45}

            46
            47void insert(int s,int e,int add,int pos=1)
            48{
            49    if(s==st[pos].s&&e==st[pos].e)
            50        update(pos,add);
            51    else
            52    {
            53        if(st[pos].turn)
            54        {
            55            update(pos<<1,st[pos].turn);
            56            update((pos<<1)+1,st[pos].turn);
            57            st[pos].turn=0;
            58        }

            59        if(e<=(st[pos].s+st[pos].e)>>1)
            60            insert(s,e,add,pos<<1);
            61        else if(s>=(st[pos].s+st[pos].e)>>1)
            62            insert(s,e,add,(pos<<1)+1);
            63        else
            64        {
            65            insert(s,(st[pos].s+st[pos].e)>>1,add,pos<<1);
            66            insert((st[pos].s+st[pos].e)>>1,e,add,(pos<<1)+1);
            67        }

            68        st[pos].x=st[pos<<1].x+st[(pos<<1)+1].x;
            69        st[pos].y=st[pos<<1].y+st[(pos<<1)+1].y;
            70    }

            71}

            72int main()
            73{
            74    int n,c,pos,turn,d1,d2;
            75    while(scanf("%d%d",&n,&c)!=EOF)
            76    {
            77        for(int i=1;i<=n;i++)
            78            scanf("%d",len+i);
            79        init(1,n+1);
            80        while(c--)
            81        {
            82            scanf("%d%d",&pos,&turn);
            83            d1=get(pos++);
            84            d2=get(pos);
            85            insert(pos,n+1,turn-180-d2+d1);
            86            printf("%.2f %.2f\n",st[1].x+eps,st[1].y+eps);
            87        }

            88    }

            89    return 0;
            90}

            posted on 2010-11-03 00:03 yzhw 閱讀(255) 評論(0)  編輯 收藏 引用 所屬分類: data struct

            <2011年6月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            導航

            統計

            公告

            統計系統

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            欧美一区二区三区久久综| 蜜桃麻豆www久久| 亚洲精品成人网久久久久久| 久久性生大片免费观看性| 久久久亚洲AV波多野结衣| 麻豆亚洲AV永久无码精品久久| 狠狠色丁香久久综合婷婷| 久久久精品国产亚洲成人满18免费网站 | 色播久久人人爽人人爽人人片aV| 久久亚洲精品无码播放| 国产亚洲精品美女久久久| 久久中文精品无码中文字幕| 色天使久久综合网天天| 国产L精品国产亚洲区久久| 色天使久久综合网天天| 亚洲欧美精品伊人久久| 国产69精品久久久久久人妻精品 | 91久久精品国产免费直播| 久久久久国产精品人妻| 91久久精品视频| 精品久久一区二区三区| 亚洲伊人久久精品影院| 无码人妻少妇久久中文字幕| 久久99毛片免费观看不卡| 午夜精品久久久久久久| 亚洲伊人久久综合中文成人网| a级毛片无码兔费真人久久| AV无码久久久久不卡蜜桃 | 国产69精品久久久久99| 99国产欧美久久久精品蜜芽| 亚洲欧美成人综合久久久| 久久人妻少妇嫩草AV蜜桃| 亚洲国产成人久久精品动漫| 久久天天躁狠狠躁夜夜网站| 久久青青草原精品国产| 无码人妻久久一区二区三区| 中文字幕无码精品亚洲资源网久久| 亚洲国产视频久久| 综合久久给合久久狠狠狠97色| 欧美亚洲另类久久综合婷婷 | 香蕉久久夜色精品国产尤物|