CodeForces333E Summer Earnings

本文解析了CodeForces上的一道题目E,任务是在平面上寻找三个点以绘制不相交的最大半径圆。文章提供了详细的算法思路,通过枚举点对并使用bitset进行快速查询来确定最佳组合。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接:http://codeforces.com/contest/333/problem/E

题面:

Many schoolchildren look for a job for the summer, and one day, when Gerald was still a schoolboy, he also decided to work in the summer. But as Gerald was quite an unusual schoolboy, he found quite unusual work. A certain Company agreed to pay him a certain sum of money if he draws them three identical circles on a plane. The circles must not interfere with each other (but they may touch each other). He can choose the centers of the circles only from the n options granted by the Company. He is free to choose the radius of the circles himself (all three radiuses must be equal), but please note that the larger the radius is, the more he gets paid.

Help Gerald earn as much as possible.

Input

The first line contains a single integer n — the number of centers (3 ≤ n ≤ 3000). The following n lines each contain two integers xi, yi ( - 104 ≤ xi, yi ≤ 104) — the coordinates of potential circle centers, provided by the Company.

All given points are distinct.

Output

Print a single real number — maximum possible radius of circles. The answer will be accepted if its relative or absolute error doesn't exceed 10 - 6.

Examples
Input
Copy
3
0 1
1 0
1 1
Output
0.50000000000000000000
Input
Copy
7
2 -3
-2 -3
3 0
-3 -1
1 -2
2 -2
-1 0
Output
1.58113883008418980000

题意:给出N个点,找到其中3个点,以任意半径画圆,但3个圆不能相交(可以相切,见样例1)。

题解:显然可以枚举C(N,3),然后构成三角形最短边的一半最大值就是答案。会TLE, 我们换种想法。

           首先O(N^2)算出所有线段,问题等价于找到AB, BC, AC三条线,求max{min{AB,BC,AC}}。我们得到线段之后从大到小排序,bitset<N>a[N],表示当前有某个点,那么当我们加入某条线段时,两个点有我A,B,如果a[A],a[B]可以由交集就说明存在C点,构成一个三角形,又因为我们是从大到小枚举的,找到第一个就是最优解。复杂度(N^3 / 32),可以通过。

#include <bits/stdc++.h>

using namespace std;
#define SZ(X) ((int)X.size())
#define mp make_pair
#define pb push_back
#define RALL(X) X.rbegin(),X.rend()
#define ALL(X) X.begin(),X.end()

using ll = long long ;
using ld = long double ;

const int N = 3010;

int sqr(int a) {return a*a;}

struct Point
{
    int x, y;
}p[N];
struct Seg
{
    int u, v, d;
    bool operator < (const Seg& s) const {
        return d > s.d;
    }
}seg[N*N];
bitset<N>a[N];


int main()
{
    int n;
    scanf("%d", &n);
    for(int i = 1;i <= n;i ++) scanf("%d%d",&p[i].x,&p[i].y);
    int m = 0;
    for(int i = 1;i <= n;i ++) {
        for(int j = i + 1;j <= n;j ++) {
            seg[++m] = {i, j, sqr((p[i].x-p[j].x)) + sqr((p[i].y-p[j].y))};
        }
    }
    sort(seg+1, seg+1+m);
    for(int i = 1;i <= m;i ++) {
        int t1 = seg[i].u;
        int t2 = seg[i].v;
        if((a[t1]&a[t2]).count()) {
            return !printf("%.12f\n",sqrt(seg[i].d) / 2.0);
        }
        a[t1].set(t2);
        a[t2].set(t1);
    }
    return 0;
}



### Codeforces 887E Problem Solution and Discussion The problem **887E - The Great Game** on Codeforces involves a strategic game between two players who take turns to perform operations under specific rules. To tackle this challenge effectively, understanding both dynamic programming (DP) techniques and bitwise manipulation is crucial. #### Dynamic Programming Approach One effective method to approach this problem utilizes DP with memoization. By defining `dp[i][j]` as the optimal result when starting from state `(i,j)` where `i` represents current position and `j` indicates some status flag related to previous moves: ```cpp #include <bits/stdc++.h> using namespace std; const int MAXN = ...; // Define based on constraints int dp[MAXN][2]; // Function to calculate minimum steps using top-down DP int minSteps(int pos, bool prevMoveType) { if (pos >= N) return 0; if (dp[pos][prevMoveType] != -1) return dp[pos][prevMoveType]; int res = INT_MAX; // Try all possible next positions and update 'res' for (...) { /* Logic here */ } dp[pos][prevMoveType] = res; return res; } ``` This code snippet outlines how one might structure a solution involving recursive calls combined with caching results through an array named `dp`. #### Bitwise Operations Insight Another critical aspect lies within efficiently handling large integers via bitwise operators instead of arithmetic ones whenever applicable. This optimization can significantly reduce computation time especially given tight limits often found in competitive coding challenges like those hosted by platforms such as Codeforces[^1]. For detailed discussions about similar problems or more insights into solving strategies specifically tailored towards contest preparation, visiting forums dedicated to algorithmic contests would be beneficial. Websites associated directly with Codeforces offer rich resources including editorials written after each round which provide comprehensive explanations alongside alternative approaches taken by successful contestants during live events. --related questions-- 1. What are common pitfalls encountered while implementing dynamic programming solutions? 2. How does bit manipulation improve performance in algorithms dealing with integer values? 3. Can you recommend any online communities focused on discussing competitive programming tactics? 4. Are there particular patterns that frequently appear across different levels of difficulty within Codeforces contests?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值