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 ...
随机推荐
- 1.3(Mybatis学习笔记)动态SQL
一.<if> 使用<if>可以根据具体情况来拼接SQL语句,使其更加灵活更加适应我们的需求. <if>的标签体中是需要拼接的语句,满足条件才会将其进行拼接. < ...
- Problem O: 逆序输出——C语言初学者百题大战之二十
#include<stdio.h> int main() { int a,b,c,d,e,n; scanf("%d",&n); a=n/; b=n%/; c=n ...
- jvm-监控指令-jdump
格式: jmap [option] vmid 作用: 生成堆转储快照. 使用:(注意:需要使用工具打开,分析. 比如: EclipseMemoryAnalyzer)
- Android 架构 4.总结
以下是Keegan小钢大神原创博客: Android项目重构之路:架构篇Android项目重构之路:界面篇Android项目重构之路:实现篇 看了这几篇文章,以及下面的评论,总结一下,以便以后拓展: ...
- react使用echarts
1.安装echarts: npm install echarts --save 2.制作线性图组件,只引入echart必要的js内容 /** * Created by yongyuehuang on ...
- SpringMVC学习记录(七)--拦截器的使用
SpringMVC的请求如以下这样的图所看到的: 能够看出全部的请求都要通过Dispatherservlet来接收,然后通过Handlermapping来决定使用哪个控制器,再依据ViewResolv ...
- nagios监控mongodb
nagios本身不提供监控mongodb的服务,需要安装插件 已经有大神写好的插件nagios_plugin-mongodb 地址https://github.com/mzupan/nagios-pl ...
- 【java】为数组全部元素赋同样的值 以及 数组之间的复制
为数组全部元素赋同样的值 : boolean[] resArray=new boolean[100]; Arrays.fill(resArray, true); 数组之间的复制: System.arr ...
- LINUX 和WINDOWS下的自动登录小脚本
每天上班第一件事,就是连接公司LAB里面的机器,但首先要过一个防火墙,每次输用户名密码是很累人的事, 以下是两个脚本,可以放在启动项中,开机便自动登录 WINDOWS: @echo off ipcon ...
- git学习——打标签
打标签 就像某人发布某个软件版本(v1.0)后,一般会给一个标签. Git 使用的标签有两种类型:轻量级的(lightweight)和含附注的(annotated).轻量级标签就像是个不会变化的分支, ...