题目链接: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(暴力)的更多相关文章

  1. Codeforces 459E Roland and Rose

    本以为是个树形DP,按照树形DP的方法在那里dfs,结果WA到死,因为它存在有向环,不是树,凡是存在环的情况切记不要用树形的方法去做 题目的突破点在于将边排完序之后,用点表示以该点为边结尾的最大长度, ...

  2. 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 ...

  3. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

  4. Codeforces gym 100685 A. Ariel 暴力

    A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Desc ...

  5. Codeforces Gym 100637G G. #TheDress 暴力

    G. #TheDress Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100637/problem/G ...

  6. [ An Ac a Day ^_^ ] CodeForces 691F Couple Cover 花式暴力

    Couple Cover Time Limit: 3000MS   Memory Limit: 524288KB   64bit IO Format: %I64d & %I64u Descri ...

  7. Codeforces 626D Jerry's Protest(暴力枚举+概率)

    D. Jerry's Protest time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  8. HDU 5745 La Vie en rose 暴力

    La Vie en rose 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5745 Description Professor Zhang woul ...

  9. codeforces 650D D. Image Preview (暴力+二分+dp)

    题目链接: http://codeforces.com/contest/651/problem/D D. Image Preview time limit per test 1 second memo ...

随机推荐

  1. Intellij IDEA自动生成serialVersionUID

    [Setting]->[Inspections]->[Serialization issues]->[Serializable class without ’serialVersio ...

  2. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. lync项目总结

    概述 9月份,由于公司人事变动,摆在自己面前也有两条路可选择,一是选择lync,二是选择sharepoint,由于之前,部门老大已经让我看了大概一个月的有关lync方面的资料(文档,代码,项目实施等) ...

  4. github清理,记录一些有趣的项目

    1. rhino 一种java做的开源javascript引擎 https://github.com/mozilla/rhino 2. jeewx 国人写的公众号管理后台,集成度有些高,不好剥离.还是 ...

  5. iOS:实现邮件和短信发送的简单示例

    发送邮件1.导入库文件:MessageUI.framework2.引入头文件3.实现代理<MFMailComposeViewControllerDelegate> 和 <UINavi ...

  6. Objective-C:运行时runtime

    1.是否可以把比较耗时的操作放在通知中心中?   通知在哪一个线程发的,那么对通知事件的处理就在同一个线程中进行; 如果在异步线程发的通知,那么可以执行比较耗时的操作: 如果在主线程发的通知,那么就不 ...

  7. Solution of NumberOfDiscIntersections by Codility

    question:https://codility.com/programmers/lessons/4 this question is seem like line intersections qu ...

  8. 在Dell XPS 13安装WIN10和ubuntu双系统

    新入了Dell的XPS 13超级本,之所以买这个本子,就是看中它轻便且续航持久.这款本子也是为数不多的能够和苹果的13'' mac book air一较高下的本子.在重量上,占地面积和综合性价比上,还 ...

  9. 【android相关】【问题解决】R.java文件丢失

    在进行android开发过程中,有时候,我们会遇到gen文件中R.java丢失的现象.重新build,或者clean工程,close并重新打开Project,但有时也没解决. 这可能是由于不小心把xm ...

  10. php核心技术与最佳实践知识点(下)

    九.缓存 1.缓存三大要素:命中率, 缓存更新策略,缓存最大数据量 2.命中率(mysql为例):mysql提供了一系列的query cache的global status来提现数据库缓存的情况: s ...