302392: CF460E. Roland and Rose
Memory Limit:256 MB
Time Limit:3 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Roland and Rose
题意翻译
- ## 题目描述 R先生对种花这一门手艺可谓是心醉神迷。他最近正在种植一株美丽迷人的玫瑰。我们可以用丰富的联想能力把R先生的花园看作一个笛卡尔坐标系,那么我们令这株玫瑰在原点,也就是(0,0)上。因为这株玫瑰实在太美丽了,抱歉我的言辞匮乏无法形容,我不能如实地把我脑中的映像描绘出来,像是玛丽恩巴德的挽歌中天使的明净,又胜过小王子里那需人呵护的独一无二的玫瑰。这也是为什么R先生倾尽心力想要保护她,不让那些恶毒的力量窃走她。 为了保护她的玫瑰,R先生想要建造n座看守塔。让我们假定每一座看守塔是这个平面上的一个点,并且距离玫瑰不能超过r个单位长度。除此之外,R先生觉得,这些塔只有建在**整数格点**上,并且两两之间距离的平方和要最大,才能最好的抵御邪恶势力。值得注意的是,R先生是一个会魔法的建筑师,他可以在同一个点建造数个看守塔,也可以在玫瑰所在的(0,0)建造。 怎么样才能最好地保护他心爱的玫瑰呢?这个问题使R先生犯难了。他想要在尽可能快的时间内得到一个符合条件的解法,这样他便可以争分夺秒地修建防御设施,保护他心爱地玫瑰。(R先生只知道欧几里得距离) - ## 输入格式 第一行有两个整数,分别代表看守塔的个数n和最大距离r。 - ## 输出格式 在第一行输出一个整数,最大的距离平方和 接下来n行每行输出一个坐标,即满足条件的塔的坐标。每座塔必须在以r为半径的圆中。再次提醒,有些塔可能在同一个点上,有些塔可能在(0,0)。 如果有多个有效的最优方案,输出任何一个就行了。题目描述
Roland loves growing flowers. He has recently grown a beautiful rose at point $ (0,0) $ of the Cartesian coordinate system. The rose is so beautiful that Roland is afraid that the evil forces can try and steal it. To protect the rose, Roland wants to build $ n $ watch towers. Let's assume that a tower is a point on the plane at the distance of at most $ r $ from the rose. Besides, Roland assumes that the towers should be built at points with integer coordinates and the sum of squares of distances between all pairs of towers must be as large as possible. Note, that Roland may build several towers at the same point, also he may build some of them at point $ (0,0) $ . Help Roland build the towers at the integer points so that the sum of squares of distances between all towers is maximum possible. Note that the distance in this problem is defined as the Euclidian distance between points.输入输出格式
输入格式
The first line contains two integers, $ n $ and $ r $ $ (2<=n<=8; 1<=r<=30) $ .
输出格式
In the first line print an integer — the maximum possible sum of squared distances. In the $ i $ -th of the following $ n $ lines print two integers, $ x_{i},y_{i} $ — the coordinates of the $ i $ -th tower. Each tower must be inside or on the border of the circle with radius $ r $ . Note that there may be several towers located at the same point of the plane, also some towers can be located at point $ (0,0) $ . If there are multiple valid optimal arrangements, choose any of them.
输入输出样例
输入样例 #1
4 1
输出样例 #1
16
0 1
0 1
0 -1
0 -1
输入样例 #2
3 6
输出样例 #2
312
0 6
5 -3
-5 -3