Codeforces 460E Roland and Rose(暴力)
题目链接:Codeforces 460E Roland and Rose
题目大意:在以原点为圆心,半径为R的局域内选择N个整数点,使得N个点中两两距离的平方和最大。
解题思路:R最大为30。那么事实上距离圆心距离最大的整数点只是12个最多,直接暴力枚举。
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
struct point {
int x, y;
point (int x = 0, int y = 0) {
this->x = x;
this->y = y;
}
};
int N, R, M, ans, pos[10], rec[10];
vector<point> vec;
inline int dis (int x, int y) {
return x * x + y * y;
}
inline bool cmp (const point& a, const point& b) {
return dis(a.x, a.y) > dis(b.x, b.y);
}
void init () {
scanf("%d%d", &N, &R);
for (int i = -R; i <= R; i++) {
for (int j = -R; j <= R; j++) {
if (i * i + j * j <= R * R)
vec.push_back(point(i, j));
}
}
ans = 0;
M = min((int)vec.size(), 18);
sort(vec.begin(), vec.end(), cmp);
}
void dfs (int d, int f, int s) {
if (d == N) {
if (s > ans) {
ans = s;
memcpy(rec, pos, sizeof(pos));
}
return;
}
for (int i = f; i < M; i++) {
int add = 0;
for (int j = 0; j < d; j++)
add += dis(vec[pos[j]].x - vec[i].x, vec[pos[j]].y - vec[i].y);
pos[d] = i;
dfs(d + 1, i, s + add);
}
}
int main () {
init();
dfs(0, 0, 0);
printf("%d\n", ans);
for (int i = 0; i < N; i++)
printf("%d %d\n", vec[rec[i]].x, vec[rec[i]].y);
return 0;
}
Codeforces 460E Roland and Rose(暴力)的更多相关文章
- Codeforces 459E Roland and Rose
本以为是个树形DP,按照树形DP的方法在那里dfs,结果WA到死,因为它存在有向环,不是树,凡是存在环的情况切记不要用树形的方法去做 题目的突破点在于将边排完序之后,用点表示以该点为边结尾的最大长度, ...
- Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力
E. Roland and Rose Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/pro ...
- Codeforces Gym 100015H Hidden Code 暴力
Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...
- Codeforces gym 100685 A. Ariel 暴力
A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...
- Codeforces Gym 100637G G. #TheDress 暴力
G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...
- [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力
Couple Cover Time Limit: 3000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u Descri ...
- Codeforces 626D Jerry's Protest(暴力枚举+概率)
D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- HDU 5745 La Vie en rose 暴力
La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...
- codeforces 650D D. Image Preview (暴力+二分+dp)
题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...
随机推荐
- Jquery的Split二次分割
<script type="text/javascript">var str="Q1#k1:Q2#k2"var str2=str.split(':' ...
- SpringBoot拦截器中service或者redis注入为空的问题
原文:https://my.oschina.net/u/1790105/blog/1490098 这两天遇到SpringBoot拦截器中Bean无法注入问题.下面介绍我的思考过程和解决过程: 1.由于 ...
- redis秒杀系统数据同步(保证不多卖)
东西不多卖 秒杀系统需要保证东西不多卖,关键是在多个客户端对库存进行减操作时,必须加锁.Redis中的Watch刚好可以实现一点.首先我们需要获取当前库存,只有库存中的食物小于购物车的数目才能对库存进 ...
- 【SQL】查询数据库中某个字段有重复值出现的信息
select name,mobile from [GeneShop].[dbo].[xx_member] where mobile in ( SELECT mobile FROM [GeneShop] ...
- 十个Chatbot框架介绍
十个Chatbot框架介绍 原创 2016年12月13日 16:01:23 4616 Chatbot列表 1. Artificial Intelligence Markup Language ...
- jstack来分析。当linux出现cpu被java程序消耗过高时
我们使用jdk自带的jstack来分析.当linux出现cpu被java程序消耗过高时,以下过程说不定可以帮上你的忙: 1.top查找出哪个进程消耗的cpu高 21125 co_ad2 18 ...
- idea 配置Spring MVC
一.idea 生成的Spring MVC 项目将<url-pattern>.form<url-pattern>改成<url-pattern>.do<url-p ...
- LeakCanary 的使用遇到的弯路
基本上来源是: http://www.liaohuqiu.net/cn/posts/leak-canary-read-me/ 1. demon 中自带的android_v7兼容包有问题的,建议自己使 ...
- PHPer 应聘见闻
关于我自己 我,很普通的一个开发,88年出生在皖南山区.从小学到高中毕业都没想过自己会从事软件开发,高考的误打误撞,被某普通二本院校收编.大学浑浑噩噩,对软件开发也没多大的兴趣,11年毕业后来杭,面试 ...
- S3C6410+FPGA+2*RTL8211 驱动 iperf測试
驱动也写的差点儿相同了,所以有必要測试下性能怎样?本次採用了iperf进行測试.而且对照了下s3c6410+ks8851的測试结果 1.iperf怎样交叉编译? https://iperf.fr/ 官 ...