Codeforces 460E Roland and Rose(暴力)
来源:互联网 发布:java微信扫一扫 编辑:程序博客网 时间:2024/04/30 14:22
题目链接: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;}
1 0
- Codeforces 460E Roland and Rose(暴力)
- [Codeforces 460E][SCOI 2015集训]Roland and Rose(暴力乱搞)
- 【Codeforces Round 262 (Div 2)E】【爆搜 估价函数剪枝 搜索步长剪枝】Roland and Rose 整格放点 点对欧几里得距离平方和尽可能大
- Codeforces 463E Caisa and Tree(暴力)
- Codeforces 400E Inna and Binary Logic(位运算+暴力)
- Codeforces 366E Dima and Magic Guitar 暴力
- codeforces 525E Anya and Cubes (暴力+中途相遇法)
- codeforces 552E Vanya and Brackets(暴力)
- codeforces 324# E. Anton and Ira (暴力枚举+贪心)
- Codeforces 677E Vanya and Balloons(暴力+转换) category:
- Codeforces 272E Dima and Horses【玄学暴力】
- codeforces 446E E. Divisors(数论+暴力)
- Codeforces Round #264 (Div. 2) E. Caisa and Tree 树上操作暴力
- codeforces 525E Anya and Cubes(暴力,meet-in-the-middle)
- Codeforces 617E XOR and Favorite Number (区间异或和 莫队算法 分块暴力)
- Codeforces 677E Vanya and Balloons【断点前缀和+暴力维护+数学技巧】
- Codeforces 451E Devu and Flowers 容斥原理暴力+Lucas定理
- CodeForces 600E Lomsat gelral 暴力
- Linux下rz/sz安装及使用方法
- 【嵌入式Linux+ARM】存储控制器(操作SDRAM)
- Android成长之路-LayoutInflater和inflate的用法
- determine if a string has all unique characters
- BZOJ 1057: [ZJOI2007]棋盘制作
- Codeforces 460E Roland and Rose(暴力)
- ubuntu 12.04 登录界面黑屏
- Android 工程源文件结构
- CBCentralManager 的background mode问题
- 花生壳域名ping不通解决方法
- Mapreduce学习指导及疑难解惑汇总
- 发布一个长尾词生成的小软件工具
- PAAS平台构建7×24小时高可用应用的方案设计
- 程序员学英语—In August the English learning summary