Codeforces 460e Roland and Rose (violent)

Source: Internet
Author: User

Link: codeforces 460e Roland and Rose

N Integer Points are selected in the local area where the origin is the center and the radius is R, so that the sum of squares of the distance between the two points is the largest.

Solution: The maximum R value is 30. In fact, there are only 12 Integer Points with the largest distance from the center of the circle, and the enumeration is directly violent.

#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 (violent)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.