#include<cstdio>
#include<cmath>
using namespace std
double fun(int a,int b,int c,int d)
{
long double x,y
x = abs(a - c)
y = abs(b - d)
return sqrt(x * x + y * y) / 10000
}
int main()
{
// freopen("a.txt","r",stdin)
int x, y while(cin >>x >>y) { int i, n, x1, y1, x2, y2 double sum = 0 cin >>n for(i = 1i <= ni ++) { cin >>x1 >>y1 >>x2 >>y2 sum += fun(x1,y1,x2,y2) } int T = sum - 1 double t = sum - T int te =floor(t * 60 + 0.5) if(te >= 60) { T ++ te -= 60 } cout <<T <<":" if(te <10) cout <<"0" cout <<te <<endl } return 0
}
#include <stdio.h>#define max 100
typedef struct anode
{
int adjvex//边的终点位置
struct anode *nextarc
}arcnode
typedef struct node
{
int data
arcnode *firstout
}vnode
typedef struct
{
vnode adjlist[max]
int n
int e
}Agraph
static int visit[max]
//深度遍历
void DFS(Agraph &G,int v) //v为初始顶点编号
{
int k
arcnode *p
for(k=0k<G.nk++)
visit[k]=0
printf("%d ",v)
p=G.adjlist[v].firstout
while(p)
{
if(!visit[p->adjvex])
DFS(G,p->adjvex)
p=p->nextarc
}
}
void BFS(Agraph &G,int v)
{
arcnode *p
int q[max]
int front=0
int rear=0
int w,i
for(i=0i<G.ni++)
visit[i]=0
printf("%d ",v)
visit[v]=1
rear=(rear+1)%max
q[rear]=v
while(front!=rear)
{
front=(front+1)%max
w=q[front]
p=G.adjlist[w].firstout
while(p)
{
if(!visit[p->adjvex])
{
printf("%d ",p->adjvex)
visit[p->adjvex]=1
rear=(rear+1)%max
q[rear]=p->adjvex
}
p=p->nextarc
}
printf("\n")
}
}
//层序遍历二叉树
struct btnode
{
int data
btnode *lchild,*rchild
}
void level(struct btnode *bt)
{
if(!bt)
return
btnode *q[max]
int front,rear
front=0
rear=0
printf("%d ",bt->data)
rear=(rear+1)%max
q[rear]=bt
while(front!=rear)
{
front=(front+1)%max
bt=q[front]
if(bt->lchild)
{
printf("%d ",bt->lchild->data)
rear=(rear+1)%max
q[rear]=bt->lchild
}
if(bt->rchild)
{
printf("%d ",bt->rchild->data)
rear=(rear+1)%max
q[rear]=bt->rchild
}
}
}
void DFS1(Agraph &G,int v)
{
arcnode *p
printf("%d ",v)
visit[v]=1
p=G.adjlist[v].firstout
while(p)
{
if(!visit[p->adjvex])
{
DFS1(G,p->adjvex)
}
p=p->nextarc
}
}
void level1(struct btnode *bt)
{
if(!bt)
return
printf("%d ",bt->data)
struct btnode *q[max]
int front=0
int rear=0
rear=(rear+1)%max
q[rear]=bt
while(front!=rear)
{
front=(front+1)%max
bt=q[front]
if(bt->lchild)
{
printf("%d ",bt->lchild->data)
rear=(rear+1)%max
q[rear]=bt->lchild
}
if(bt->rchild)
{
printf("%d ",bt->rchild->data)
rear=(rear+1)%max
q[rear]=bt->rchild
}
}
}
void BFS1(Agraph &G,int v)
{
int q[max]
int front=0
int rear=0
int i
for(i=0i<G.ni++)
visit[i]=0
printf("%d ",v)
visit[v]=1
rear=(rear+1)%max
q[rear]=v
arcnode *p
while(front!=rear)
{
front=(front+1)%max
i=q[front]
p=G.adjlist[i].firstout
while(p)
{
if(!visit[p->adjvex])
{
printf("%d ",p->adjvex)
visit[p->adjvex]=1
rear=(rear+1)%max
q[rear]=p->adjvex
}
p=p->nextarc
}
}
}
这...算法和语言关系不是很大了...楼主可以看一下算法导论之类的书
如果要学算法什么的话,我才不说pascal什么最严谨了...
c++有STL vector之类的写起来可能会方便一些
不过LZ如果要学习算法的话还是认真写吧。
先学建图,再遍历,再最短路,再强连通,然后欧拉路哈密顿什么的选着看一些吧 tyvj图论分类下的题一抓一大把
以及 可以去NOIP吧转转 那边有各种大牛热心为你解答
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)