E. Roland and Rose

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

http://codeforces.com/problemset/problem/460/E

Description

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.

Input

The first line contains two integers, n and r (2 ≤ n ≤ 8; 1 ≤ r ≤ 30).

1000000000.

Output

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, xi, yi — 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.

Sample Input

4 1

Sample Output

16
0 1
0 1
0 -1
0 -1

HINT

题意

在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大。

题解:

R最大为30,那么其实距离圆心距离最大的整数点不过12个最多,直接暴力枚举。

代码:

//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>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff; //无限大
const int inf=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()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
const int K = , N = ; int x[K], y[K], z[K], ax[N], ay[N], tx[N], ty[N], n, m, r, i, j, k, r1, r2, s; void go(int t, int p)
{
if (p == n)
{
int u = ;
for (int i = ; i < n; i++)
for (int j = i + ; 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 (int i = ; i < n; i++)
ax[i] = tx[i], ay[i] = ty[i];
}
}
else
{
for (int i = t; i < k; i++)
{
tx[p] = x[i], ty[p] = y[i];
go(i, p + );
}
}
} int main()
{
scanf("%d%d", &n, &r); r1 = (r - ) * (r - );
r2 = r * r; for (i = -r; i <= r; i++)
for (j = -r; j <= r; j++)
{
int t = i * i + j * j;
if (t <= r2 && t > r1)
x[k] = i, y[k] = j, z[k++] = t;
} for (i = ; i < k; i++)
for (j = i + ; j < k; j++)
if (z[j] > z[i])
{
int zz;
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(, ); printf("%d\n", s);
for (i = ; i < n; i++)
printf("%d %d\n", ax[i], ay[i]); return ;
}

Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力的更多相关文章

  1. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  2. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  3. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  4. Codeforces Round #262 (Div. 2) 460C. Present(二分)

    题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory ...

  5. codeforces水题100道 第十五题 Codeforces Round #262 (Div. 2) A. Vasya and Socks (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/460/A题意:Vasya每天用掉一双袜子,她妈妈每m天给他送一双袜子,Vasya一开始有n双袜子, ...

  6. Codeforces Round #262 (Div. 2)解题报告

    详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http ...

  7. Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

    题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second mem ...

  8. Codeforces Round #262 (Div. 2)

    A #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> ...

  9. Codeforces Round #262 (Div. 2) A B C

    题目链接 A. Vasya and Socks time limit per test:2 secondsmemory limit per test:256 megabytesinput:standa ...

随机推荐

  1. 深入理解Spring系列之十一:SpringMVC-@RequestBody接收json数据报415

    转载 https://mp.weixin.qq.com/s/beRttZyxM3IBJJSXsLzh5g 问题原因 报错原因可能有两种情况: 请求头中没有设置Content-Type参数,或Conte ...

  2. linux——vi和vim的区别

    vi 和vim 的区别   它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅兼容vi的所有指令,而且还有一些新的特性在里面. vim的这些优势主要体现在以下几个方面:1.多级撤消我们知道 ...

  3. flask插件系列之Flask-WTF表单

    flask_wtf是flask框架的表单验证模块,可以很方便生成表单,也可以当做json数据交互的验证工具,支持热插拔. 安装 pip install Flask-WTF Flask-WTF其实是对w ...

  4. 服务器部署之nginx的配置

    nginx可作为Web和 反向代理 服务器,在高连接并发的情况下,Nginx是Apache服务器不错的替代品.下面记录一下自己对nginx的配置和使用. nginx的安装 环境:oracle-linu ...

  5. C++ 内联函数inline

    http://blog.csdn.net/u011327981/article/details/50601800 1.  内联函数 在C++中我们通常定义以下函数来求两个整数的最大值: 复制代码 代码 ...

  6. rocketmq 记

    Rocketmq选型 Rocket是一个专业的队列服务,性能优于Rabbitmq,优势是性能和并发,源于Kafka的扩展版,增强了数据的可靠性. Rocketmq的队列类型 普通队列,广播队列.顺序队 ...

  7. ftp,nfs和samba的区别

    先从名字上进行理解: 1. FTP(文件传输协议) 2. NFS(网络文件系统) 3. samba 即smb(服务信息块)协议 1 其中FTP 是TCP/IP协议栈所提供的一种子协议,该子协议具体可以 ...

  8. 关于angular导入第三方库的问题

    angular-cli使用webpack来将模块打包,在这里配置的scripts和styles会被打包成script.bundle.js和styles.bundle.js文件加载到前台页面. 这样就可 ...

  9. 8.Python3标准库--数据持久存储与交换

    ''' 持久存储数据以便长期使用包括两个方面:在对象的内存中表示和存储格式之间来回转换数据,以及处理转换后数据的存储区. 标准库包含很多模块可以处理不同情况下的这两个方面 有两个模块可以将对象转换为一 ...

  10. PHP任意文件上传漏洞CVE-2015-2348浅析

    昨晚安全新闻爆出一个“PHP任意文件上传漏洞”,CVE编号为:CVE-2015-2348. 当时楼主正准备收拾东西回家,看到这个新闻心里一惊:失传江湖多年的0字符截断上传漏洞又重现了?而且还影响这么多 ...