| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
纠结,两个不同的结果居然都能AC,代码如下~~~第一个:
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<memory>
using namespace std;
const double PI = 3.141592657;
struct Node
{
double x,y;
}map[100];
int main()
{
int testcase,i;
double sum = 0.0,rad;
scanf("%d%lf",&testcase,&rad);
sum = 2*PI*rad;
scanf("%lf%lf",&map[0].x,&map[0].y);
for(i = 1;i < testcase;i++)
{
scanf("%lf%lf",&map[i].x,&map[i].y);
//cout<<"****";
}
for( i = 1;i < testcase;i++)
{
sum += sqrt((map[i].x - map[i-1].x)*(map[i].x - map[i-1].x)+(map[i].y - map[i-1].y)*(map[i].y - map[i-1].y));
}
sum += sqrt((map[i-1].x-map[0].x)*(map[i-1].x-map[0].x) + (map[i-1].y - map[0].y)*(map[i-1].y - map[0].y));
//cout<<sum<<endl;
printf("%.2lf\n",sum);
//system("pause");
return 0;
}
第二个:
#include<iostream>
#include<math.h>
#define PI (3.141592657)
using namespace std;
typedef struct Point{
double x,y;
}Point;
double LengthOfTwoPoints(Point x,Point y){
double dx=x.x-y.x,dy=x.y-y.y;
return sqrt(dx*dx+dy*dy);
}
double CaculateAngle(Point a,Point b,Point c){
double la = LengthOfTwoPoints(b,c);
double lb = LengthOfTwoPoints(a,c);
double lc = LengthOfTwoPoints(a,b);
return acos((lb*lb+lc*lc-la*la)/(2*lb*lc));
}
double LengthOfArc(double angle,double radius){
return angle*radius;
}
double LengthOfRope(Point nails[],int N,double radius){
double totalLength=0;
int prePos=0,nextPos=0;
if(N==1) return 2*PI*radius;
for(int i=0;i<N;i++){
prePos=i-1,nextPos=i+1;
if(prePos<0) prePos=N-1;
if(nextPos>=N) nextPos=0;
totalLength+=LengthOfTwoPoints(nails[i],nails[nextPos])
+LengthOfArc(PI-CaculateAngle(nails[i],nails[prePos],nails[nextPos]),radius);
}
return totalLength;
}
/*double LengthOfRope(Point nails[],int N,double radius){
double totalLength=2*PI*radius;
int nextPos=0;
if(N==1)
return totalLength;
for(int i=0;i<N;i++){
nextPos=i+1;
if(nextPos>=N) nextPos=0;
totalLength+=LengthOfTwoPoints(nails[i],nails[nextPos]);
}
return totalLength;
}*/
int main(){
Point nails[100];
int N=0;
double radius=0;
scanf("%d%lf",&N,&radius);
for(int i=0;i<N;i++)
scanf("%lf%lf",&nails[i].x,&nails[i].y);
printf("%.2lf",LengthOfRope(nails,N,radius));
return 0;
}
测试数据:
5 1
0 0
1 2
3 2
5 4
3 -1
两个结果不一样啊,都AC了,搞不懂~~~
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator