10355 Superman poao899 Accepted C++ 0.012 2010-02-16 09:54:03 .
嗯 兩個月沒coding了
為什麼第一個挑的題目就是計算幾何啦囧
是說不難 但是co得亂七八糟
#include<stdio.h>
#include<math.h>
#include<algorithm>
char name[20];
struct point{
double x,y,z;
void get(){
scanf("%lf%lf%lf\n",&x,&y,&z);
}
}st,ed,cen,p;
double t;
int r,n;
inline double pow2(double a){
return a*a;
}
inline double dist2(point a,point b){
return pow2(a.x-b.x)+pow2(a.y-b.y)+pow2(a.z-b.z);
}
struct node{
double x;
int flag;
bool operator<(const node &b)const{
return x<b.x || x==b.x&&flag>b.flag;
}
};
struct line{
node N[30];
int cnt;
void init(){
cnt=0;
}
void push(double a,double b){
if(a<0)a=0;
if(b>1)b=1;
N[cnt].x=a;
N[cnt++].flag=1;
N[cnt].x=b;
N[cnt++].flag=-1;
}
}L;
int main(){
while(~scanf("%s",name)){
puts(name);
L.init();
st.get();
ed.get();
scanf("%d",&n);
double xt,yt,zt,c,dis,dt;
xt=ed.x-st.x;
yt=ed.y-st.y;
zt=ed.z-st.z;
while(n--){
cen.get();
scanf("%d",&r);
c=xt*cen.x + yt*cen.y + zt*cen.z;
t = (c -xt*st.x -yt*st.y -zt*st.z)/(pow2(xt)+pow2(yt)+pow2(zt));
p.x=xt*t + st.x;
p.y=yt*t + st.y;
p.z=zt*t + st.z;
dis = pow2(double(r)) - dist2(cen,p);
if(dis<0)continue;
dt = sqrt((dis)/(pow2(xt)+pow2(yt)+pow2(zt)));
L.push(t-dt,t+dt);
}
int cnt=0;double pre=0,total=0;
std::sort(L.N,L.N+L.cnt);
for(int i=0;i<L.cnt;i++){
if(cnt>0){
total+=(L.N[i].x-pre);
}
cnt+=L.N[i].flag;
pre=L.N[i].x;
}
printf("%.2lf\n",total*100);
}
return 0;
}
沒有留言:
張貼留言