题目链接: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. iOS项目之企业证书打包和发布

    一.打包ipa 个人发布证书和企业发布证书打包 app 大同小异,只是打包时导出选项不同,企业证书打包选择 Save for Enterprise Deployment ,并最终导出 ipa 包.详细 ...

  2. binlog监听工具-canal

    官网 https://github.com/alibaba/canal/wiki

  3. JAVA EE 学习笔记

    http://www.cnblogs.com/kuangdaoyizhimei/category/701794.html http://www.cnblogs.com/liunanjava/p/445 ...

  4. 【java】子类可以通过调用父类的public方法调用父类的private方法,为什么?

    代码1: 打印结果: 代码2: 运行结果: 问题: 代码1中super是父类自己调用自己的add()方法,并在add()方法中调用了私有的del()方法,那为什么打印出来的this是子类? 代码2中t ...

  5. css:滑动门

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. oracle数据库修改编码

    (1)SYSTEM  用户登录SQLPLUS        SYS是sysdba用户,不能直接登录 (2)SYSDBA登录        CONN  / as sysdba; (3)查看数据库字符集 ...

  7. 集合—ArrayList

    ArrayList也叫作数组列表 public static void main(String[] args) { List list1 = new ArrayList<String>() ...

  8. Docker与PAAS

    Docker与PAAS 学习了:https://blog.csdn.net/raindaywhu/article/details/52057103 Docker基于内存的:

  9. [Functional Programming] Combine Multiple State ADT Instances with the Same Input (converge(liftA2(constant)))

    When combining multiple State ADT instances that depend on the same input, using chain can become qu ...

  10. pip安装mysql报错 ld: library not found for -lssl

    ld: library not found for -lssl clang: error: linker command failed with exit code (use -v to see in ...