• <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>

            Why so serious? --[NKU]schindlerlee

            2009年11月30日星期一.sgu110

            2009年11月30日星期一.sgu110

            sgu110:完全被這題玩了。。。
            題意很簡單:
            一堆球,一條光線,光線反射符合反射定律,輸出所有反射經過的球的序號
            的確沒有光線的起點在球中。

            tricks:
            1. test case 3 是無交點的。。。。我被這個玩了
            2. 直線要表示成參數方程
            P = P0 + s*v; 注意是射線,所以只有 "s >= 0" 時是成立的,注意 >= 0,自己想下為什么有等于0
            還要特判一下不能連著交同一個圓

            貌似沒有別的問題了

            反射直線有兩個推法

            1.
            lt表示直線的參數方程
            lt.p 為p0,lt.v為v

            point_t v = normal(tmp - circles[idx]);
            double d = -(tmp.x * v.x + tmp.y * v.y + tmp.z * v.z); //平面方程ax + by + cz + d = 0中的d
            double dis = fabs(p2p(lt.p, v.x, v.y, v.z, d));  // p2p為點到平面的距離
            v = tmp - lt.p + scale(v, dis * 2);
            lt.p = tmp, lt.v = normal(v);
            下圖表示了上面求解的過程
            \  |  /   
             \ | /    
              \|/     
            ---------
                \     
                 \    
                  \   
            還可以跟據,

            2.
            求出中點,mid = (s1 + s2)/2;
            然后求出s2即可

            \  *  /
             \   /
              \ /
            ==============================華麗麗的分割線==============================
            貼代碼
              1 /*
              2  * SOUR:sgu110
              3  * ALGO:3D computational geometry
              4  * DATE: 2009年 11月 29日 星期日 17:21:22 CST
              5  * COMM:4
              6  * */
              7 #include<iostream>
              8 #include<cstdio>
              9 #include<cstdlib>
             10 #include<cstring>
             11 #include<algorithm>
             12 #include<cmath>
             13 using namespace std;
             14 typedef long long LL;
             15 const int maxint = 0x7fffffff;
             16 const long long max64 = 0x7fffffffffffffffll;
             17 const int N = 128;
             18 int n;
             19 struct point_t {
             20     double x,y,z,r;
             21     point_t(){}
             22     point_t(double a,double b,double c){x = a,y = b,z = c;}
             23 }circle[N],s,e;
             24 point_t operator + (point_t a,point_t b) { return point_t(a.x + b.x ,a.y + b.y,a.z + b.z);}
             25 point_t operator - (point_t a,point_t b) { return point_t(a.x - b.x ,a.y - b.y,a.z - b.z);}
             26 point_t scale(point_t a,double fac) { return point_t(a.x * fac,a.y * fac,a.z * fac);}
             27 double dist(point_t a) { return sqrt(a.x * a.x + a.y * a.y + a.z * a.z);}
             28 point_t normal(point_t a) {
             29     double len = dist(a);
             30     return point_t(a.x / len,a.y/len,a.z/len);
             31 }
             32 point_t setLen(point_t a,double fac) {
             33     a = normal(a);
             34     return point_t(a.x*fac,a.y*fac,a.z*fac);
             35 }
             36 int out[N*N],top;
             37 
             38 double p2p(point_t p,double a,double b,double c,double d)
             39 {
             40     return (a * p.x + b * p.y + c * p.z + d)/sqrt(a * a + b * b + c* c);
             41 }
             42 
             43 const double inf = 1e10;
             44 const double eps = 1e-12;
             45 double dot_mul(point_t a,point_t b) {
             46     return a.x * b.x + a.y * b.y + a.z * b.z;
             47 }
             48 void solve()
             49 {
             50     int i,j,k,pre = -1;
             51     top = 0;
             52     for(k = 0;k < 12;k++) {
             53         int idx = 0;
             54         double mink = inf;
             55         for(i = 1;i <= n;i++) {
             56             if(pre != i) {
             57                 double a = (e.x * e.x + e.y * e.y + e.z * e.z);
             58                 point_t t = s - circle[i];
             59                 double b = 2 * dot_mul(e,t);
             60                 double c = t.x * t.x + t.y * t.y + t.z * t.z - circle[i].r * circle[i].r;
             61                 if(b * b >= 4 * a * c)  {
             62                     double s1 = (-- sqrt(b*- 4 * a*c))/(2*a);
             63                     double s2 = (-+ sqrt(b*- 4 * a*c))/(2*a);
             64                     if(s1 >= 0) {
             65                         if(s1 < mink) {
             66                             mink = s1;
             67                             idx = i;
             68                         }
             69                     }else if(s2 >= 0){
             70                         if(s2 < mink) {
             71                             mink = s1;
             72                             idx = i;
             73                         }
             74                     }
             75                 }
             76             }
             77         }
             78         if(idx > 0) {
             79             point_t p = s + scale(e,mink);
             80             //p is the point which intersects with the circles
             81             point_t v = normal(p - circle[idx]); // normal vector
             82             double d = -dot_mul(p,v);
             83             //double dis = fabs(p2p(s,v.x,v.y,v.z,d));
             84             double dis = fabs(dot_mul(v,s)+d);
             85 
             86             point_t mid = p + scale(v,dis);
             87             point_t p1 = scale(mid,2- s;
             88 
             89             s = p,e =p1-p;
             90             out[top++= idx;
             91             pre = idx;
             92         }else {
             93             break;
             94         }
             95     }
             96     if(top > 0//哥死在這句話上了。。。
             97         printf("%d",out[0]);
             98     for(i = 1;i < 10 && i < top;i++) {
             99         printf(" %d",out[i]);
            100     }
            101     if(top > 10) {
            102         printf(" etc.");
            103     }
            104     putchar(10);
            105 }
            106 
            107 int main()
            108 {
            109     int i,j,k;
            110     while(scanf("%d",&n) == 1) {
            111         top = 0;
            112         for(i = 1;i <= n;i++) {
            113             scanf("%lf%lf%lf%lf",&circle[i].x,&circle[i].y,&circle[i].z,&circle[i].r);
            114         }
            115         scanf("%lf%lf%lf%lf%lf%lf",&s.x,&s.y,&s.z,&e.x,&e.y,&e.z);
            116         e = e - s;
            117         solve();
            118     }
            119     return 0;
            120 }
            121 


            posted on 2009-11-30 14:45 schindlerlee 閱讀(1262) 評論(0)  編輯 收藏 引用 所屬分類: 解題報告

            伊人久久大香线蕉精品| 99久久人妻无码精品系列蜜桃| 久久久久亚洲av综合波多野结衣 | 激情综合色综合久久综合| 国产福利电影一区二区三区久久老子无码午夜伦不| 漂亮人妻被黑人久久精品| 精品精品国产自在久久高清| 国内精品久久久久久中文字幕| 无码人妻久久一区二区三区蜜桃| 无码人妻久久久一区二区三区| 久久久精品波多野结衣| 久久亚洲日韩精品一区二区三区| 亚洲国产精品久久久久| 人妻精品久久久久中文字幕69 | 久久精品中文字幕久久| 欧美性大战久久久久久| 久久99精品久久久久久动态图| 久久精品国产一区二区三区| 久久99国产综合精品免费| 久久久高清免费视频| 国产精品内射久久久久欢欢| 中文字幕人妻色偷偷久久| 久久亚洲电影| 精品久久久久中文字| 麻豆精品久久久一区二区| 久久久久人妻精品一区 | 亚洲AV日韩AV永久无码久久| 国内精品久久久久久久久电影网| 999久久久无码国产精品| 亚洲日韩中文无码久久| 思思久久精品在热线热| 性高朝久久久久久久久久| 精品国产青草久久久久福利| 成人国内精品久久久久影院| 久久香蕉国产线看观看精品yw| 亚洲精品无码久久千人斩| 精品一二三区久久aaa片| 久久国产免费直播| 久久亚洲春色中文字幕久久久| 久久综合国产乱子伦精品免费| 久久综合给合久久狠狠狠97色|