有谁作了uva上的361,help me?

galois_godel 2003-05-25 08:23:27
我不是wrong answer ,就是 。。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
#define infinity 1e20
#define EP 1e-10
#define N 10000
//#define double int

struct TPoint{
double x,y;
};
TPoint bp;
struct TLineSeg{
TPoint a,b;
};
int same1(TLineSeg l,TPoint r,TPoint s)
{
double temp;
double dx,dy,dx1,dy1,dx2,dy2;
dx=l.b.x-l.a.x;
dy=l.b.y-l.a.y;
dx1=r.x-l.a.x;
dy1=r.y-l.a.y;
dx2=s.x-l.a.x;
dy2=s.y-l.a.y;
temp=(dx*dy1-dy*dx1)*(dx*dy2-dy*dx2);
return (temp>=0);
}


double max(double a,double b)
{
if(a>b)
return a;
else
return b;
}
double min(double a,double b)
{
if(a<b)
return a;
else
return b;
}
float distance(TPoint p1,TPoint p2)
{
return(sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)));
}


float multiply(TPoint p1,TPoint p2,TPoint p0)
{
return((p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y));
}


int intersect(TLineSeg u,TLineSeg v)
{
return( (max(u.a.x,u.b.x)>=min(v.a.x,v.b.x))&&
(max(v.a.x,v.b.x)>=min(u.a.x,u.b.x))&&
(max(u.a.y,u.b.y)>=min(v.a.y,v.b.y))&&
(max(v.a.y,v.b.y)>=min(u.a.y,u.b.y))&&
(multiply(v.a,u.b,u.a)*multiply(u.b,v.b,u.a)>=0)&&
(multiply(u.a,v.b,v.a)*multiply(v.b,u.b,v.a)>=0));
}

int online(TLineSeg l,TPoint p)
{
return( (multiply(l.b,p,l.a)==0)&&( ((p.x-l.a.x)*(p.x-l.b.x)<0 )||( (p.y-l.a.y)*(p.y-l.b.y)<0 )) );
}


int Euqal_Point(TPoint p1,TPoint p2)
{
return((fabs(p1.x-p2.x)<EP)&&(fabs(p1.y-p2.y)<EP));
}

int intersect_A(TLineSeg u,TLineSeg v)
{
return((intersect(u,v))&&
(!Euqal_Point(u.a,v.a))&&
(!Euqal_Point(u.a,v.b))&&
(!Euqal_Point(u.b,v.a))&&
(!Euqal_Point(u.b,v.b))&&
(!online(u,v.a))&&
(!online(u,v.b))&&
(!online(v,u.a))&&
(!online(v,u.b)));
}


int InsidePolygon(int vcount,TPoint Polygon[],TPoint q)
{
int c=0,i,n;
TLineSeg l1,l2;

l1.a=q;
l1.b=q;
l1.b.x=infinity;
n=vcount;
for (i=0;i<vcount;i++)
{
l2.a=Polygon[i];
l2.b=Polygon[(i+1)%n];
// cout<<i<<" "<<online(l1,Polygon[(i+1)%n])<<" "<<intersect_A(l1,l2)<<endl;
if( Euqal_Point(q,l2.a) ||Euqal_Point(q,l2.b))
return 1;
if(online(l2,q))
return 1;
if((intersect_A(l1,l2))||
(
(online(l1,Polygon[(i+1)%n]))&&
(
(!online(l1,Polygon[(i+2)%n]))&&
(!same1(l1,Polygon[i],Polygon[(i+2)%n]))
||
(online(l1,Polygon[(i+2)%n]))&&
(!same1(l1,Polygon[i],Polygon[(i+3)%n]))
)
)
) c++;

// cout<<c<<endl;
}
//cout<<c<<endl;
return(c%2!=0);
}
void swap(TPoint *a,TPoint *b)
{
TPoint temp=*a;
*a=*b;
*b=temp;
}
/*
int cmp(const void *a,const void *b)
{
TPoint *pa=(TPoint *)a;
TPoint *pb=(TPoint *)b;
double ra=sqrt((pa->x-bx)*(pa->x-bx)+(pa->y-by)*(pa->y-by));
double rb=sqrt((pb->x-bx)*(pb->x-bx)+(pb->y-by)*(pb->y-by));
if(ra<EP)
return 1;
if(rb<EP)
return -1;
double ka=acos((pa->x-bx)/ra);
double kb=acos((pb->x-bx)/rb);
if(fabs(ka-kb)<1e-6)
if(ra>rb)
return 1;
else if(ra<rb)
return -1;
else
return 0;
else if(ka>kb)
return 1;
else
return -1;
//return anglea-angleb;
}*/
int cmp(const void *a,const void *b)
{
double ka,kb;
double da,db;
double ax=((TPoint *)a)->x-bp.x;
double ay=((TPoint *)a)->y-bp.y;
// cout<<" int cmp: "<<bx<<" "<<by<<endl;
double bx=((TPoint *)b)->x-bp.x;
double by=((TPoint *)b)->y-bp.y;

da=sqrt(ax*ax+ay*ay);
db=sqrt(bx*bx+by*by);
ka=acos(ax/da);
kb=acos(bx/db);
if(fabs(ka-kb)<EP)
if(da>db)
return 1;
else if(da<db)
return -1;
else
return 0;
else if(ka>kb)
return 1;
else
return -1;

}
void output(TPoint p[],int len)
{
cout<<"DEBUG IN OUTPUT"<<endl;
int i;
for(i=0;i<len;i++)
{
cout<<p[i].x<<" "<<p[i].y<<endl;
}
cout<<"END OF DEBUG IN OUPUT"<<endl;
}
int convexhull(TPoint p[],int len)
{
int mini=0;
TPoint pp[N];
int pplen;
int i,j;
for(i=1;i<len;i++)
{
if((p[mini].y)>(p[i].y) || ( fabs(p[mini].y-p[i].y)<EP && p[mini].x>p[i].x ))
mini=i;
}
if(mini)
swap(&p[mini],&p[0]);
bp=p[0];
if(len>1)
qsort((void *)(p+1),len-1,sizeof(p[0]),cmp);
//output(p,len);

pp[0]=p[0];
pp[1]=p[1];
pp[2]=p[2];
pplen=3;
j=3;
while(fabs(multiply(pp[0],pp[1],pp[2]))<EP )
{
pp[1]=pp[2];
if(j<len)
pp[2]=p[j++];
else
{
pplen--;
break;
}

}


for(;j<len;j++)
{
// pp[pplen++]=p[j];
// cout<<" for "<<j<<" "<<p[j].x<<" "<<p[j].y<<endl;
while(multiply(p[j],pp[pplen-1],pp[pplen-2])>0 && pplen>2 )
{
// cout<<" multiply(p[j],p[pplen-1],p[pplen-2])="<<multiply(p[j],p[pplen-1],p[pplen-2])<<endl;
pplen--;
// cout<<j<<endl;
}
// cout<<"outwhile multiply(p[j],p[pplen-1],p[pplen-2])="<<multiply(p[j],p[pplen-1],p[pplen-2])<<endl;
pp[pplen++]=p[j];

}
for(i=0;i<pplen;i++)
p[i]=pp[i];
return pplen;
}

TPoint cop[N];
TPoint rob[N];
int c,r,o;
void input()
{
int i;
for(i=0;i<c;i++)
cin>>cop[i].x>>cop[i].y;
if(c>2)
c=convexhull(cop,c);
//cout<<c<<endl;
/// output(cop,c);
for(i=0;i<r;i++)
cin>>rob[i].x>>rob[i].y;
if(r>2)
r=convexhull(rob,r);
}
void slv()
{
int i;
TPoint citizen;
for(i=0;i<o;i++)
{
cin>>citizen.x>>citizen.y;
if(InsidePolygon(c,cop,citizen) )
cout<<" Citizen at ("<<citizen.x<<","<<citizen.y<<") is "<<"safe."<<endl;
else if(InsidePolygon(r,rob,citizen) )
cout<<" Citizen at ("<<citizen.x<<","<<citizen.y<<") is "<<"robbed."<<endl;
else
cout<<" Citizen at ("<<citizen.x<<","<<citizen.y<<") is "<<"neither."<<endl;
}
cout<<endl;
}

int main()
{

int cas=0;
while(cin>>c>>r>>o)
{
if(c==0 && r==0 && o==0)
break;
cout<<"Data set "<<++cas<<":"<<endl;
input();
slv();
}

return 0;
}
...全文
113 7 打赏 收藏 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
danger1900 2003-07-02
  • 打赏
  • 举报
回复
告诉我怎么做
mmmcd 2003-06-20
  • 打赏
  • 举报
回复
想结帖,点击次页上方的“管理”...
galois_godel 2003-06-14
  • 打赏
  • 举报
回复
不必回答了。我已过了。这道题目好象有点问题,题目上说数值范围在(-500,500),我照这做,死也不过,后来我把数值改大之后,立即就过了。ft。
浪费了我30多次submission

怎么结帖啊
dawnhorizon 2003-06-07
  • 打赏
  • 举报
回复
翻译一下,应该就会有了:)
galois_godel 2003-06-06
  • 打赏
  • 举报
回复
没人知道吗
galois_godel 2003-05-28
  • 打赏
  • 举报
回复
题目如下:
Cops and Robbers

You are to simulate a game of Cops and Robbers. In this game, cops, robbers, and other citizens are represented as points in a two-dimensional plane. A citizen is said to be safe if it is within a triangle formed by three cops. A citizen is said to be robbed if it is not safe and is within a triangle formed by three robbers. A citizen is neither safe nor robbed if it satisfies neither of the above conditions. For purposes of this problem, a triangle consists of three non-collinear points, and a point is within a triangle if it is inside or on the boundary of the triangle.


In the following diagram, filled circles represent cops, filled squares represent robbers, and filled triangles represent citizens. Dashed lines indicate triangles formeby cops or robbers



In this example, citizens A and B are safe, citizen C is robbed, and citizen D is neither.


Given a set of cops and robbers and several citizen queries, efficiently determine whether each citizen is safe, robbed, or neither.


Input
The input consists of several data sets. The first line of each data set contains three non-negative integers c, r, and o: the number of cops, robbers, and other citizens, respectively. c, r, and o will each be at most 200. The next c lines contain the (x, y) coordinates of each cop, one per line. The next r lines contain the (x, y) coordinates of each robber, one per line. The next o linescontain the (x, y) coordinates of each other citizen, one per line. All coordinates are integers between -500 and 500 inclusive.


Your program must stop processing input when it encounters adata set in which c, r, and o are all zero.


Output
Output for each data set begins with a line identifying the data set. For each other citizen in the data set, output the line



Citizen at (x,y) is status.



where (x,y) is the location of the citizen from the input and status is one of safe, robbed or neither. Follow the format given in the Sample Output. Leave a blank line after the output from each data set.


Sample Input

3 3 2
0 0
10 0
0 10
20 20
20 0
0 20
5 5
15 15
3 3 1
0 0
10 0
0 10
20 20
20 0
0 20
40 40
0 0 0

Sample Output

Data set 1:
Citizen at (5,5) is safe.
Citizen at (15,15) is robbed.

Data set 2:
Citizen at (40,40) is neither.
LeeMaRS 2003-05-25
  • 打赏
  • 举报
回复
...你帖个题目过来, 会有更多的人帮你看..
内容概要:本文围绕基于物理场的动态模式分解(piDMD)展开研究,重点探讨其在流体力学、热传导及多物理耦合系统中的建模与应用。通过Matlab代码实现,将传统的动态模式分解(DMD)方法与物理场控制方程相结合,引入物理约束以增强数据驱动模型的物理一致性,从而提升对复杂非线性系统的模态提取精度与长期预测能力。文章系统阐述了piDMD的理论基础、数学推导过程与算法实现步骤,并结合典型物理场仿真案例(如Navier-Stokes方程驱动的流场演化)进行验证,展示了其在降阶建模、主导模态识别和时空动态可视化方面的优越性能,适用于高维、强耦合、非平稳系统的分析与优化。; 适合人群:具备一定数值计算、流体力学、控制理论或数据驱动建模背景,熟悉Matlab编程与线性代数运算,从事科学研究、工程仿真或系统辨识工作的研究生、科研人员及工程师。; 使用场景及目标:①实现对流场、温度场等物理场的高效降阶建模与动态行为预测;②提取符合物理规律的关键模态,用于系统稳定性分析与控制设计;③支撑复杂系统的状态估计、异常检测与优化调控等下游任务。; 阅读建议:建议读者结合提供的Matlab代码逐行调试与运行,深入理解piDMD算法中物理约束的嵌入方式及其对模态质量的影响,同时可尝试将其迁移至其他偏微分方程描述的物理系统中进行拓展验证与应用。
内容概要:本文研究了在峰谷分时电价引导下,基于多目标优化遗传算法NSGA-II的电动汽车充电负荷优化问题。通过构建以电网负荷波动最小化和用户充电成本最低为核心的多目标优化模型,利用NSGA-II算法求解获得帕累托最优解集,实现对大规模电动汽车充电行为的有序引导。文中系统阐述了峰谷电价激励机制的设计原理、电动汽车充电负荷的数学建模方法、多目标优化问题的形式化表达以及NSGA-II算法的具体实现流程,并借助Matlab平台进行仿真验证,结果表明该策略能有效平抑电网负荷峰谷差、降低用户充电支出并提升电力系统的运行效率与稳定性。; 适合人群:具备一定电力系统基础知识和Matlab编程能力,从事智能电网、电动汽车调度、需求侧管理等相关领域的研究生或科研人员。; 使用场景及目标:①研究峰谷电价政策对电动汽车充电行为的影响机制;②掌握NSGA-II算法在电力系统多目标优化中的具体应用;③实现电动汽车集群的有序充电调度以改善电网负荷曲线; 阅读建议:此资源结合了电力经济学与智能优化算法,建议读者在学习过程中重点关注模型构建与算法实现的衔接部分,动手复现仿真代码以深入理解参数设置与结果分析过程。
详情可查看下方数据集可视化效果。 【数据集概况】 · 检测类别(中文):[电梯(elevator)] · 训练集:1468 张 · 验证集:157 张 · 测试集:158 张 · 总计:1783 张 该数据集聚焦于各类建筑内部及外部环境中的电梯目标检测任务,涵盖住宅楼、办公楼、商场、酒店等多种典型场景下的电梯结构。图像采集覆盖不同光照条件、材质类型与安装位置,充分体现了实际应用中电梯的多样性与复杂性,为智能楼宇管理、安防监控及无障碍设施识别等方向提供了高质量的视觉基础支持。... 【训练曲线与评估图】 【模型训练配置】 参数 | 值 模型 | yolo26n 训练轮数 | 100 epochs 输入尺寸 | 640x640 批次大小 | 24 优化器 | auto 初始学习率 | 0.01 训练设备 【关键指标汇总】 训练了 72 个 epoch,最终轮指标: 指标 | 数值 mAP50 | **0.9446** mAP50-95 | 0.6531 Precision | 0.9305 Recall | 0.8777 train/box_loss | 0.5807 train/cls_loss | 0.3505 val/box_loss | 1.0020 val/cls_loss | 0.6208 【训练过程分析】 72 轮训练后 mAP50 达到 0.9446,模型收敛良好。Loss 曲线前段快速下降,后段趋于平稳,val_loss 无反弹,没有明显过拟合。但 mAP50-95 为 0.6531,和 mAP50 差距 0.29,定位精度仍有优化空间。 【模型性能评估】 Precision 0.9305、Recall 0.8777,精度高于召回,存在一定漏检。 【预测效果展示】 验证集预测效果较好,检测框基本准确覆盖电梯,置信度整体偏高。 【改进建议】 1. 丰富场景...

33,025

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧