Codeforces Round #262 (Div. 2) E. Roland and Rose violence

Source: Internet
Author: User

E. Roland and Rose

Time limit:1 Sec Memory limit:256 MB

Topic Connection Http://codeforces.com/problemset/problem/460/E
Description

Roland loves growing flowers. He had recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The Rose is so beautiful, that Roland was 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 the -most R from the rose. Besides, Roland assumes that the towers should is built at points with integer coordinates and the sum of squares of Dista NCEs between all pairs of towers must is as large as possible. Note, that's Roland may build several towers at the same point, also he may build some of them on point (0, 0).

Help Roland builds the towers at the integer points so, the sum of squares of distances between all towers is maximum P Ossible. Note that the distance-problem is defined as the Euclidian distance between points.



Inputthe first line contains and integers, n and R (2≤ n ≤ 8;  1≤ R ≤30). 1000000000.
Output

The first line print an integer-the maximum possible sum of squared distances. in the I-th of the following n lines Print II integers, xi, YI -the coordinates of the I-th Tower. Each tower must is inside or on the border of the circle with radius r. Note that there is several towers located at the same point of the plane, also some towers can is located at point (0, 0).

If There is multiple valid optimal arrangements, choose any of them.


Sample Input4 1Sample Output 16
0 1
0 1
0-1
0-1 HINT

Test instructions

At the center of the origin point, the radius of R is selected in the local area of n integer points, so that n points in the square and maximum 22 distance.

Exercises

R Max is 30, then the maximum distance from the center of the whole point is only 12, the most direct violent enumeration.

Code:

//Qscqesze#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<sstream>#include<queue>#include<typeinfo>#include<fstream>#include<map>#include<stack>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 200001#defineMoD 10007#defineEPS 1e-9//const int INF=0X7FFFFFFF; //infinitely LargeConst intinf=0x3f3f3f3f;/*int buf[10];inline void write (int i) {int p = 0;if (i = = 0) p++;  else while (i) {buf[p++] = i% 10;i/= 10;}  for (int j = p-1; J >=0; j--) Putchar (' 0 ' + buf[j]); printf ("\ n");}*///**************************************************************************************inline ll read () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; ch=GetChar ();} returnx*F;}Const intK = About, N =9;intX[k], y[k], z[k], ax[n], ay[n], tx[n], ty[n], N, M, R, I, J, K, R1, R2, S;voidGointTintp) {    if(p = =N) {intU =0;  for(inti =0; I < n; i++)             for(intj = i +1; J < N; J + +) U+ = (Tx[i]-tx[j]) * (Tx[i]-tx[j]) + (Ty[i]-ty[j]) * (Ty[i]-Ty[j]); if(U >s) {s=u;  for(inti =0; I < n; i++) Ax[i]= Tx[i], ay[i] =Ty[i]; }    }    Else    {         for(inti = t; I < K; i++) {Tx[p]= X[i], ty[p] =Y[i]; Go (i, P+1); }    }}intMain () {scanf ("%d%d", &n, &R); R1= (R-1) * (R-1); R2= R *R;  for(i =-R; I <= R; i++)         for(j =-R; J <= R; J + +)        {            intt = i * i + j *J; if(t <= R2 && T >R1) X[k]= i, y[k] = j, z[k++] =T; }     for(i =0; I < K; i++)         for(j = i +1; J < K; J + +)            if(Z[j] >Z[i]) {                intZZ; ZZ= X[j], x[j] = X[i], x[i] =ZZ; ZZ= Y[j], y[j] = Y[i], y[i] =ZZ; ZZ= Z[j], z[j] = Z[i], z[i] =ZZ; } k= -; Go (0,0); printf ("%d\n", s);  for(i =0; I < n; i++) printf ("%d%d\n", Ax[i], ay[i]); return 0;}

Codeforces Round #262 (Div. 2) E. Roland and Rose violence

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.