• <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 線段樹的好題

            簡述題意:
            一堆豎直依次排列,端點(diǎn)處連接起來。現(xiàn)在給出這樣一種操作,將第i個(gè)桿子和第i+1個(gè)桿子直接的角度調(diào)整為180+degree,當(dāng)然,i+1個(gè)桿子以后的桿子連著它一起轉(zhuǎn)動(dòng)。求最后一個(gè)桿子的坐標(biāo)
            可以這樣設(shè)置線段樹的域
            1 struct
            2 {
            3     int s,e;
            4     double x,y;
            5     int turn;
            6 }st[N];
            turn代表當(dāng)前線段整體旋轉(zhuǎn)過的角度
            維護(hù)策略可以這樣寫:用到了坐標(biāo)的旋轉(zhuǎn)變換矩陣:
            |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 }
            其他標(biāo)記下移什么的和普通線段樹一樣,就不贅述了,貼代碼
             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) 評(píng)論(0)  編輯 收藏 引用 所屬分類: data struct

            <2011年1月>
            2627282930311
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            導(dǎo)航

            統(tǒng)計(jì)

            公告

            統(tǒng)計(jì)系統(tǒng)

            留言簿(1)

            隨筆分類(227)

            文章分類(2)

            OJ

            最新隨筆

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            中文字幕久久精品无码| 成人妇女免费播放久久久| 精品一久久香蕉国产线看播放| 亚洲欧美日韩精品久久| 久久久久久久免费视频| 人妻无码久久一区二区三区免费 | 国产午夜久久影院| 香蕉久久夜色精品国产小说| 四虎影视久久久免费| 伊人久久大香线蕉亚洲五月天| 久久国产精品久久国产精品| 香蕉久久AⅤ一区二区三区| 久久亚洲精品中文字幕| 亚洲?V乱码久久精品蜜桃| 久久精品人人做人人妻人人玩| 久久精品亚洲福利| 99久久人妻无码精品系列蜜桃 | 日本强好片久久久久久AAA| 秋霞久久国产精品电影院| 久久精品国产久精国产果冻传媒 | 久久综合伊人77777| 国产日产久久高清欧美一区| 久久精品日日躁夜夜躁欧美| 久久99国产一区二区三区| 国产精品99久久精品| 久久WWW免费人成一看片| 日韩久久久久中文字幕人妻 | 久久中文字幕一区二区| 久久亚洲中文字幕精品有坂深雪 | 久久精品国产亚洲Aⅴ香蕉| 国产国产成人精品久久| 久久精品无码专区免费青青| 亚洲乱码中文字幕久久孕妇黑人| 色婷婷噜噜久久国产精品12p| 日本免费久久久久久久网站| 久久精品www人人爽人人| 亚洲香蕉网久久综合影视| 久久久久亚洲AV无码观看| 久久精品人人做人人爽电影| 久久久久亚洲av综合波多野结衣| 久久久久久综合网天天|