您的位置:首页 > 大数据 > 人工智能

SZU 2015 Winter Training Day#5

2015-01-21 22:40 113 查看

Problem(A28):ArcticNetwork

Judge Info

MemoryLimit: 32768KB

Case TimeLimit: 10000MS

Time Limit:10000MS

Judger:Number Only Judger

Description

TheDepartment of National Defense (DND) wishes to connect several northernoutposts by a wireless network. Two different communication technologies are tobe used in establishing the network: every outpost will have a radiotransceiver and some outposts will
in addition have a satellite channel.

Any twooutposts with a satellite channel can communicate via the satellite, regardlessof their location. Otherwise, two outposts can communicate by radio only if thedistance between them does not exceed D\,, which depends of the power of thetransceivers.
Higher power yields higher D\, but costs more. Due to purchasingand maintenance considerations, the transceivers at the outposts must beidentical; that is, the value of D\, is the same for every pair of outposts.

Your job isto determine the minimum D\, required for the transceivers. There must be atleast one communication path (direct or indirect) between every pair ofoutposts.

Input

The firstline of input contains T(1 \leq T \leq 100), the number of test cases. Thefirst line of each test case contains 1 \leq S \leq 100, the number ofsatellite channels, and P (S < P \leq 500), the number of outposts. P linesfollow, giving the (x,y) coordinates
of each outpost in km (coordinates areintegers between 0 and 10000).

Output

For eachcase, output should consist of a single line giving the minimum D\, required toconnect the network. Output should be specified to 2 decimal points.

Sample Input

2

2 4

0 100

0 300

0 600

150 750

2 4

0 100

0 300

0 600

150 750

SampleOutput

212.13

212.13

程序:
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const int MAXP=500;

struct locate
{
int x,y;
} point[MAXP+5];

struct dis
{
int num1,num2;
double len;
} edge[(MAXP+1)*MAXP+5];

int f[(MAXP+1)*MAXP+5];

bool cmp(dis,dis);
int find(int);

int main()
{
int t=(MAXP+1)*MAXP+5,s,i,j,x,y,p,q,o,d,k;
double temp;

scanf("%d",&d);
while (d--)
{
for (i=0;i<t;i++)
{
edge[i].len=0;
f[i]=i;
}

scanf("%d%d",&s,&o);

for (i=0;i<o;i++)
scanf("%d%d",&point[i].x,&point[i].y);

t=0;
for (i=0;i<o;i++)
for (j=i+1;j<o;j++)
{
x=point[i].x-point[j].x;
y=point[i].y-point[j].y;
temp=sqrt((double)(x*x+y*y));
edge[t].num1=i;
edge[t].num2=j;
edge[t++].len=temp;
}

sort(edge,edge+t,cmp);

k=0;
for (i=0;i<t;i++)
{
p=find(edge[i].num1);
q=find(edge[i].num2);
if (p!=q)
{
f[p]=q;
k++;
if (k==o-s)
{
printf("%.2lf\n",edge[i].len);
break;
}
}
}
}

return 0;
}

bool cmp(dis a,dis b)
{
return (a.len<b.len);
}

int find(int x)
{
if (f[x]==x) return x;
else
return f[x]=find(f[x]);
}
 


Problem(A53):Board

Judge Info

Memory Limit: 10240KB

Case Time Limit: 5000MS

Time Limit: 5000MS

Judger: Number Only Judger

Description

One day, i am on the way to my home. I findthere are a lots of boards on the road. Some of them are overlap, it makes theflat road become winding. I try to do something for it, remove some overlappedboards, (i can not move any boards on the road but make
it disappear, do notask me why, i won’t tell you). I want to keep the boards on the road as many aspossible(maximum the number of boards, may not have the longest length),without any overlap.

Task

Please help me to find out, the maximumnumber of boards can be leaved without any overlap.

Input

The first line of input contains T(1 \leq T\leq 100), the number of test cases. For each test case , the first line willhave an integer N(1 \leq N \leq 100) which means N boards on the road. N pairsof integer (l, r), (l < r) followed, all of them are \leq
1, 000, 000, 000which denote the left and right ends of boards.

Output

For each test case, output a line containsan integer, the maximum number of boards can be leaved without any overlap.

Sample Input

2

3

1 2

2 3

3 4

3

3 5

2 4

1 3

Sample Output

3

2

程序:
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN=100;

struct node
{
int s,e;
} point[MAXN+5];

bool cmp(node,node);

int main()
{
int t,n,i,l,sum;

scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (i=0;i<n;i++)
scanf("%d%d",&point[i].s,&point[i].e);

sort(point,point+n,cmp);

l=0;
sum=0;
for (i=0;i<n;i++)
if (point[i].s>=l)
{
sum++;
l=point[i].e;
}

printf("%d\n",sum);
}

return 0;
}

bool cmp(node a,node b)
{
return a.e<b.e;
}
 


Problem(A60):Roads

Judge Info

Memory Limit: 32768KB

Case Time Limit: 10000MS

Time Limit: 10000MS

Judger: Number Only Judger

Description

Actually, Mr.K is a famous engineer. He gota big project resently.He is asked to build roads to connect several city. Atfirst, there is no roads between any pair of these city. He is given thedistances between any two cities . Mr.K wants to build roads as
less length asposible to make all city connected.

Input

The input will contains multiple test cases.The first line of the input is a single integer T (1 \leq T \leq 100) which isthe number of test cases. T test cases follow.

Each test case contains one positiveintegers n(1 \leq n \leq 1,000) --the number of the citis numbered 1 to n.Next,there are n rows, and which row contains n positive integer. The integerat ith row,jth column is the distance between city i and city j, and
it willnever bigger than 10,000;

Output

For each input test case, you are to outputa single integer - the smallest length of roads that make all cities connected.

Sample Input

2

3

0 1 1

1 0 2

1 2 0

3

0 1 1

1 0 2

1 2 0

Sample Output

2

2

程序:
#include <iostream>
#include <algorithm>
using namespace std;

const int MAXN=1000;

struct path
{
int c1,c2,len;
} point[MAXN*MAXN+5];

int f[MAXN*MAXN+5];

bool cmp(path,path);
int find(int);

int main()
{
int t,r,n,i,j=0,k=MAXN+5,temp,sum,a,b;

scanf("%d",&t);
while (t--)
{
for (i=j;i<k;i++)
point[i].len=0;

scanf("%d",&n);

r=0;
for (i=0;i<n;i++)
for (j=0;j<n;j++)
{
scanf("%d",&temp);
if (temp && j>i)
{
point[r].c1=i;
point[r].c2=j;
point[r++].len=temp;
}
}

j=(n+1)*n/2;
k=n*n;

for (i=0;i<k;i++)
f[i]=i;

sum=0;
sort(point,point+k,cmp);

for (i=j;i<k;i++)
{
a=find(point[i].c1);
b=find(point[i].c2);
if (a!=b)
{
f[a]=b;
n--;
if (n)
sum+=point[i].len;
}
}

printf("%d\n",sum);
}

return 0;
}

bool cmp(path a,path b)
{
return (a.len<b.len);
}

int find(int x)
{
if (f[x]==x) return x;
else
return f[x]=find(f[x]);
}
 

Problem(G26):Turtleand Rabbit

Judge Info

Memory Limit: 32768KB

Case Time Limit: 1000MS

Time Limit: 1000MS

Judger: Normal

Description

Rabbit invites Turtle to participate in arunning competition again. Surely, Turtle accepted. They will start at one endof the village and the destination will be another end. In the village, thereare some crossing points, which are connected by road and
river, and forest andbuildings. It is silly and dangerous to go into the forest or unknown building.Therefore, they won’t to do so. Both Turtle and Rabbit can cross the road, andof course Rabbit can cross the road faster than Turtle. Turtle can swim so thathe
can cross the river, although he can’t swim very fast, but Rabbit do noteven know how to swim. They both grow in the village hence they are familiarwith every road there. And of course, both want to win. So, despite anyaccidents, who will win?

第一次龟兔赛跑后,兔子不服,再次邀请乌龟进行比赛。乌龟欣然接受了兔子的挑战。它们将从村子的一头跑到村子的另一头。村子里面有许多由道路、河流、森林和建筑物连接形成的交叉路口。跑进森林或未知建筑里面是危险而愚蠢的行为,因此,兔子和乌龟都不会跑进去。兔子和乌龟都能在道路上跑,而且兔子跑步的速度显然比乌龟快。乌龟会游水因此尽管它游得不快,但它能游过河流,而兔子就根本不会游水了。它们都在村子里长大,对村里的道路非常熟悉,而且它们都非常想赢得比赛。那么,兔子这次不会在半路上睡着,也没有其它意外发生,这次比赛谁会胜出?

Input

The input contains multiple test cases. Foreach test case: The first line will have three integers 'n', 'm1', 'm2'(0<=n<=200, 0<=m1,m2<=5,000). Integer 'n' is the number of crossingpoints, which are numbered from 1 to n. Integer 'm1' is the number of roads
and'm2' is the number of rivers. In the following 'm1' lines, each of themcontains three integers 'u', 'v', 'c' which means the length of the roadbetween crossing point 'u' and 'v' is 'c'. In the following 'm2' lines, each ofthem contains three integers 'u',
'v', 'c' which means the length of the riverbetween crossing point 'u' and 'v' is 'c'. In the following line contains twointegers 's' and 't', which represent the number of the starting crossing pointand the destination crossing point. Then last line contains
three integers'vr', 'vt1' and 'vt2', which represent the speed of Rabbit on the road, thespeed of Turtle on the road and the speed of Turtle in the river. The last testcase will start with n=0, m1=0, m2=0, and this test case should be ignored.Between any two
crossing points, there will be only one road or one river ifthere is one. All the roads and the rivers are bidirectional.

输入包含多个测试例子。

对每个测试例子:第1行有3个整数n,m1和m2(0<=n<=200, 0<=m1,m2<=5,000)。n是交叉路口的数目,从1开始编号到n。m1和m2分别是道路和河流的数目。

接下来的m1行,每一行包含3个整数u、v和c,表示在交叉路口u和v间的道路长度是c。

再接下来的m2行,同样每行都包含3个整数u、v和c,表示在交叉路口u和v间的河流长度是c。(特别注意,c可以是0)

再接下来的一行是整数s和t,分别表示比赛开始和结束的路口编号。

最后一行是3个整数vr、vt1和vt2,分别表示兔子在道路上的奔跑速度,乌龟在道路上的爬行速度和乌龟在水里的游动速度。

最后的结束标志由n=0,m1=0和m2=0表示,这个测试例子忽略,不予考虑。 在任意两个交叉路口间,最多只有1条道路或1条河流,所有的道路和河流都是双向的。(特别注意,双向通行)

Output

For each test case, output the answer in oneline. If Rabbit will win, output "rabbit win". Otherwise, output"turtle win". For every test case, both of them can reach thedestination.If they reach the destination at the same time,just output"turtle win".

对每个测试用例输出一行答案。如果兔子将赢得比赛,输出"rabbit win",否则,输出"turtle win"。对每个测试用例,兔子和乌龟都能到达终点。如果它们同时到达终点,输出"turtle win"。

Sample Input

4 3 2

1 2 100

2 4 300

1 3 200

3 4 50

1 4 150

1 4

4 2 1

4 3 2

1 2 100

2 4 300

1 3 200

3 4 50

1 4 150

1 4

4 2 2

0 0 0

Sample Output

rabbit win

turtle win

Problem(J16):Brightstars

Judge Info

Memory Limit: 65536KB

Case Time Limit: 10000MS

Time Limit: 10000MS

Judger: Float Numbers (1e-4) Judger

Description

坐在稔熟的星空下

一处最最随意的地方

我又一次举头

品尝无边的璀璨

这时我很想随意吟唱

一支祥和的歌子

可是夜色如水

封锢了众多安眠的耳朵

我诗歌的翅膀便在此时扬起

笼罩夜空

心事一缕缕细下来

使我无暇顾及

此重亦或彼轻

想起此时离我最近的星子

也迢遥若干光年

沮丧的心又一次领略

巨大的辽阔 和星斗们

遥遥相映的温柔

坐在星空下

小我渐渐远去

清凉的夜风

使我双唇紧闭

说不出多余的话

一种真正的祥和汹涌潮来

溶我于无极

而我却要归去

归去何方?或许只有忧伤的作者清楚.

是几万光年远处的彼岸?

是曾经走过的漫漫长路?

还是企盼着的神秘的未来?

过去与未来或许只是我们遥不可及的梦想之一

但我们从未放弃追求梦想。

所以,我们一直期盼到达过去与未来。

过去与未来不可能到达吗?

或许不是,现实理论中有这么一个东西,可以连接两个时空,它就是虫洞(后面有关于它的解释)。

在梦想之中,我们利用一个虫洞,连接任两个恒星(包括同一时间维度),通过这个虫洞,我们可以瞬间从1个星球到达另外一个星球,而虫洞的距离,就是这两个恒星的时空距离。

通过虫洞,我们可以构造一整个星际旅行的网络,例如在银河系中,我们可以

在空间上探索海王星的秘密。

在空间上探索河外星系的飘渺虚无。

在空间上探索宇宙深处的未知秘密。

在时间上,与曾经一统整个亚欧大陆的一代天骄成吉思汗一起弯弓射大雕。

在时间上,阻止乾隆实行闭关锁国的政策,从而使如今我们有一个繁华昌盛的国度。

在时间上,挽回我们犯下的种种过错,重拾我们在堕落中度过的大学时光。

问题来了:怎样才能在以最少虫洞的情况下,并且虫洞的长度总和最小,使一个时空星系中所有星球连接在一起?

关于虫洞:

由阿尔伯特•爱因斯坦提出该理论。简单地说,“虫洞”就是连接宇宙遥远区域间的时空细管。暗物质维持着虫洞出口的敞开。虫洞可以把平行宇宙和婴儿宇宙连接起来,并提供时间旅行的可能性。虫洞也可能是连接黑洞和白洞的时空隧道,所以也叫"灰道"。

是不是很深奥?没关系,这里再说明一下,虫洞,我们可以再将其抽象成一条路,这条路的两端,正是连接着两个不同时空的两个星球.

Input

有许多组测试数据,每组测试数据中,第一行一个n(2<=n<=2000),表示某星系恒星的数量.

接下来n行,每行4个整型数据x,y,z,t(0<=x,y,z,t<=1000).表示恒星在宇宙中的空间坐标点以及时间的维度t(忽略计算恒星的体积大小)。

Output

输出1行,包含三个数字(用一个空格区分,注意最后一个数字后面没空格).

第一个是需要虫洞的数量,第二个是所有虫洞总长度之和(输出后4位小数).第三个是最长的虫洞的长度(输出后4位小数).

Sample Input

4

0 0 0 0

0 1 1 0

1 1 1 0

0 0 0 1

Sample Output

3 3.4142 1.4142

Hint

我们知道,1维 空间 上的距离d=x

我们知道,2维 空间 上的距离 d = \sqrt{x^2+y^2}

我们知道,3维 空间 上的距离 d = \sqrt{x^2+y^2+z^2}

类似地, 4维 时空 上的距离 d = \sqrt{x^2+y^2+z^2+t^2}

Sample中 0 0 0 0,我们可以想象为是地球,而0 1 1 0是木星,1 1 1 0是金星,0 0 0 1是未来1个世纪后的地球。

还有的是,注意星球的数量有点多,大家注意处理。

程序:
#include <iostream>
#include <cmath>
using namespace std;

const int MAXN=2000;

struct pos
{
int c[4];
} point[MAXN+5];

double len[MAXN+5][MAXN+5],lowcost[MAXN+5];
double cal(pos,pos);

int main()
{
int n,i,j,k,sum;
int closet[MAXN+5];
double mincost,min,max;

while (scanf("%d",&n)!=EOF)
{
sum=0;
max=0;

for (i=0;i<n;i++)
for (j=0;j<4;j++)
scanf("%d",&point[i].c[j]);

for (i=0;i<n;i++)
for (j=i+1;j<n;j++)
len[i][j]=len[j][i]=cal(point[i],point[j]);

for (i=0;i<n;i++)
{
lowcost[i]=len[1][i];
closet[i]=1;
}

mincost=0;

for (i=0;i<n-1;i++)
{
min=INT_MAX;
for (j=0;j<n;j++)
if (lowcost[j]>0 && lowcost[j]<min)
{
min=lowcost[j];
k=j;
}

if (len[closet[k]][k]>max) max=len[closet[k]][k];
mincost+=len[closet[k]][k];
sum++;
lowcost[k]=0;

for (j=0;j<n;j++)
if (len[k][j]<lowcost[j])
{
lowcost[j]=len[k][j];
closet[j]=k;
}
}

printf("%d %.4lf %.4lf\n",sum,mincost,max);

}

return 0;
}

double cal(pos a,pos b)
{
int i;
double sum=0;

for (i=0;i<4;i++)
sum+=(a.c[i]-b.c[i])*(a.c[i]-b.c[i]);

return sqrt(sum);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: