codeforces 559D Randomizer

本文介绍了一种计算凸多边形内部点期望数量的方法,利用皮克定理和贡献法,解决了精度和范围限制的问题,并给出了具体的实现代码。

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

题意简述:

在一个格点图中 给定一个凸$n$边形(每个定点均在格点上),随机选择其中一些点构成一个子多边形,

求子多边形的内部点个数的期望。

----------------------------------------------------------------------------------------------------------------------------------

首先这题是需要知道 皮克定理 这个结论的

我们用 $s$代表多边形面积 $ans$代表内部点数(即要求的答案)$node$代表边上的格点

公式即为 $ans=s-\frac{node}{2}+1$

----------------------------------------------------------------------------------------------------------------------------------

然后这题是求期望的 对于期望 我们知道它是满足分配率的 于是我们可以考虑分别求出$s$和$node$的期望

对于$s$的期望 可以这样考虑(算贡献)

每次选出一个子多边形后 剩余部分显然是可以用多个顶点连续的多边形补成的

我们可以用前缀和维护这个顶点连续的多边形的面积 然后来算贡献

公式为$\displaystyle \frac{2^{n-i} -1}{2^n-1-n-C_2^n}*$子多边形面积

 

直接求出所有是$O(n^2)$的 然而观察公式我们可以发现i取较大的数的时候对答案的影响是很小的

综合考虑题目要求的$10^{-9}$的相对误差以及$double$的精度 $i$的上界$lim$可以取$min(n,60)$

$node$的求法也是类似的 只要熟悉如何算贡献就比较容易了 想了很久还不懂的话可以留言

----------------------------------------------------------------------------------------------------------------------------------

这样我们就可以过掉样例了 然后我们会$ WA  10$

因为$double$不仅仅是精度限制 还有范围限制 大概范围就是 $(10^{300}~10^{-300})$

这个问题 初次遇见还是很纠结的 多想想后 我们发现可以把公式变形成这样(上下同时除$2^n$):

$\displaystyle\frac{2^{-i} -1}{1-2^{-n}*(1+n+C_n^2)}*$子多边形面积

----------------------------------------------------------------------------------------------------------------------------------

差不多就是这些了 第一次写$div1D$题 还有些小激动呢

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=1e5+10;
double polygon[N],p[N];
int x[N],y[N];
double s,ans,node,product;
int n,lim;
double cross(long long x1,long long y1,long long x2,long long y2)
{
    return x1*y2-x2*y1;
}
int main()
{
    scanf("%d",&n);
    lim=min(n,60);
    p[0]=1;
    for(int i=0;i<n;++i)
    {
        scanf("%d%d",&x[i],&y[i]);
        p[i+1]=p[i]*0.5;
    }
    for(int i=3;i<lim;++i)
    {
        product=(p[i]-p[n])/
            (1-p[n]*((long long)n*(n-1)/2+n+1));
        for(int j=0;j<n;++j)
        {
            polygon[j]+=cross(x[(j+i-2)%n]-x[j],y[(j+i-2)%n]-y[j],
                              x[(j+i-1)%n]-x[j],y[(j+i-1)%n]-y[j]);
            s-=product*polygon[j];
        }
    }
    for(int i=0;i<n-2;++i)
        s+=cross(x[i+1]-x[0],y[i+1]-y[0],
                 x[i+2]-x[0],y[i+2]-y[0]);
    s/=2;
    for(int i=2;i<=lim;++i)
    {
        product=(p[i]-p[n])/
            (1-p[n]*((long long)n*(n-1)/2+n+1));
        for(int j=0;j<n;++j)
            node+=product*__gcd(abs(x[(j+i-1)%n]-x[j]),
                                abs(y[(j+i-1)%n]-y[j]));
    }
    ans=s-node/2+1;
    printf("%.10f\n",ans);
    return 0;
}

 

转载于:https://www.cnblogs.com/sagitta/p/4851552.html

一、综合实战—使用极轴追踪方式绘制信号灯 实战目标:利用对象捕捉追踪和极轴追踪功能创建信号灯图形 技术要点:结合两种追踪方式实现精确绘图,适用于工程制图中需要精确定位的场景 1. 切换至AutoCAD 操作步骤: 启动AutoCAD 2016软件 打开随书光盘中的素材文件 确认工作空间为"草图与注释"模式 2. 绘图设置 1)草图设置对话框 打开方式:通过"工具→绘图设置"菜单命令 功能定位:该对话框包含捕捉、追踪等核心绘图辅助功能设置 2)对象捕捉设置 关键配置: 启用对象捕捉(F3快捷键) 启用对象捕捉追踪(F11快捷键) 勾选端点、中心、圆心、象限点等常用捕捉模式 追踪原理:命令执行时悬停光标可显示追踪矢量,再次悬停可停止追踪 3)极轴追踪设置 参数设置: 启用极轴追踪功能 设置角度增量为45度 确认后退出对话框 3. 绘制信号灯 1)绘制圆形 执行命令:"绘图→圆→圆心、半径"命令 绘制过程: 使用对象捕捉追踪定位矩形中心作为圆心 输入半径值30并按Enter确认 通过象限点捕捉确保圆形位置准确 2)绘制直线 操作要点: 选择"绘图→直线"命令 捕捉矩形上边中点作为起点 捕捉圆的上象限点作为终点 按Enter结束当前直线命令 重复技巧: 按Enter可重复最近使用的直线命令 通过圆心捕捉和极轴追踪绘制放射状直线 最终形成完整的信号灯指示图案 3)完成绘制 验证要点: 检查所有直线是否准确连接圆心和象限点 确认极轴追踪的45度增量是否体现 保存绘图文件(快捷键Ctrl+S)
### Codeforces 1487D Problem Solution The problem described involves determining the maximum amount of a product that can be created from given quantities of ingredients under an idealized production process. For this specific case on Codeforces with problem number 1487D, while direct details about this exact question are not provided here, similar problems often involve resource allocation or limiting reagent type calculations. For instance, when faced with such constraints-based questions where multiple resources contribute to producing one unit of output but at different ratios, finding the bottleneck becomes crucial. In another context related to crafting items using various materials, it was determined that the formula `min(a[0],a[1],a[2]/2,a[3]/7,a[4]/4)` could represent how these limits interact[^1]. However, applying this directly without knowing specifics like what each array element represents in relation to the actual requirements for creating "philosophical stones" as mentioned would require adjustments based upon the precise conditions outlined within 1487D itself. To solve or discuss solutions effectively regarding Codeforces' challenge numbered 1487D: - Carefully read through all aspects presented by the contest organizers. - Identify which ingredient or component acts as the primary constraint towards achieving full capacity utilization. - Implement logic reflecting those relationships accurately; typically involving loops, conditionals, and possibly dynamic programming depending on complexity level required beyond simple minimum value determination across adjusted inputs. ```cpp #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; vector<long long> a(n); for(int i=0;i<n;++i){ cin>>a[i]; } // Assuming indices correspond appropriately per problem statement's ratio requirement cout << min({a[0], a[1], a[2]/2LL, a[3]/7LL, a[4]/4LL}) << endl; } ``` --related questions-- 1. How does identifying bottlenecks help optimize algorithms solving constrained optimization problems? 2. What strategies should contestants adopt when translating mathematical formulas into code during competitive coding events? 3. Can you explain why understanding input-output relations is critical before implementing any algorithmic approach? 4. In what ways do prefix-suffix-middle frameworks enhance model training efficiency outside of just tokenization improvements? 5. Why might adjusting sample proportions specifically benefit models designed for tasks requiring both strong linguistic comprehension alongside logical reasoning skills?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值