【SDOI2018】反回文串(【ARC064 F】Rotated Palindromes 加强版)

题意

  给你一个正整数 \(n\),求有多少字符集为 \(1\)\(k\) 之间整数的字符串,使得该字符串可以由一个长度为 \(n\) 的回文串循环移位得到。
  ARC原题 \(100\%\) 的数据是 \(n,k\le 10^9\)
  SDOI改编后,\(30\%\) 的数据是 \(n,k\le 10^{10}\)\(60\%\) 的数据是 \(n,k\le 10^{14}\)\(100\%\) 的数据是 \(n,k\le 10^{18}\)……

题解

\(n,k\le 10^{10}\)

  考虑一个回文串,设它的循环节长度为 \(x\),若 \(x\) 为奇数,则对答案贡献 \(x\);若为偶数,则对答案贡献 \(\frac{x}{2}\)
  我们按 \(x\) 把所有字符串分类,统计每一类的数量。
  设 \(f(i)\) 表示最小循环节长度为 \(i\) 的回文串数量,\(F(i)\) 表示循环节长度为 \(i\)(即 \(i\) 是最小循环节长度的正整数倍)能得到新回文串的回文串数量。
  则 \[F(i)=\sum\limits_{d|i} f(d)\] \[ans = \sum\limits_{d|n} f(d)\times \begin{cases} d(d为奇数) \\ \frac{d}{2}(d为偶数) \end{cases}\]
  显然有 \(F(i)=k^{\lceil \frac{i}{2}\rceil}\),我们可以解 \(f(d)\) 了。
  \(n\le 10^{10}\) 时,因数最多约有 \(6700\) 多个。所以我们要求出 \(6700\) 多个 \(f(d)\)

  移项得 \(f(i)=F(i)-\sum\limits_{d|i 且 d≠i} f(d)\)
  递推 \(f\) 即可。

  复杂度大约 \(O(6700^2)\)

#include<bits/stdc++.h>
#define ll long long
#define N 7000
#define mod 1000000007
using namespace std;
inline int read(){
    int x=0; bool f=1; char c=getchar();
    for(;!isdigit(c); c=getchar()) if(c=='-') f=0;
    for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
    if(f) return x;
    return 0-x;
}
int n,k,d[N],f[N],cnt,ans;
int Pow(int x, int y){
    int ret=1;
    while(y){
        if(y&1) ret=(ll)ret*x%mod;
        x=(ll)x*x%mod;
        y>>=1;
    }
    return ret;
}
int main(){
    n=read(), k=read();
    int nn=sqrt(n);
    for(int i=1; i<=nn; ++i)
        if(n%i==0){
            d[++cnt]=i, f[cnt]=Pow(k,(i+1)/2);
            for(int j=1; j<cnt; ++j)
                if(i%d[j]==0) f[cnt]=((f[cnt]-f[j])%mod+mod)%mod;
            ans=(ans+(ll)f[cnt]*((i&1)?i:i/2)%mod)%mod;
        }
    for(int i=nn; i>=1; --i)
        if(n%i==0){
            int ii=n/i;
            d[++cnt]=ii, f[cnt]=Pow(k,(ii+1)/2);
            for(int j=1; j<cnt; ++j)
                if(ii%d[j]==0) f[cnt]=((f[cnt]-f[j])%mod+mod)%mod;
            ans=(ans+(ll)f[cnt]*((ii&1)?ii:ii/2)%mod)%mod;
        }
    cout<<ans<<endl;
    return 0;
}
\(n,k\le 10^{14}\)

  \(F(i)=\sum\limits_{d|i} f(d)\) 不是莫比乌斯反演式子?
  根据公式转化成 \(f(i)=\sum\limits_{d|i} F(d)\mu(\frac{i}{d})\)
  我们最多只需要求约 \(17280\)\(\mu\),因此可以暴力 \(\text{dfs}\) 计算每个 \(\mu(i)\),然后就求出 \(f(i)\) 了。
  发现 \(\text{dfs}\) 的时候,\(n\) 的每个质因数只需要乘 \(0\)\(1\) 个,乘 \(2\) 个的话 \(\mu\) 值就变成了 \(0\) 了。
  于是复杂度变为 \(O(17280\times 2^{12})\),但约数数量通常不多,更不会卡满上界 \(17280\),所以卡卡常就能 \(60\) 分?

\(n,k\le 10^{18}\)

  看不懂,请移步 scb 的博客。

转载于:https://www.cnblogs.com/scx2015noip-as-php/p/11519710.html

### 实现旋转锚点生成器 对于目标检测和其他计算机视觉任务中的旋转锚点生成器,通常涉及创建一系列具有不同角度、比例和大小的矩形框。这些锚点框可以更好地适应倾斜的对象,从而提高模型性能。 #### 锚点生成原理 在标准的目标检测框架中,锚点通常是水平排列的边界框。然而,在处理如航空图像或文本识别等场景时,对象可能呈现任意方向。因此引入了带有角度参数的旋转锚点[^1]。 ```python import numpy as np def generate_rotated_anchors(base_size=16, ratios=[0.5, 1, 2], scales=2 ** np.arange(3, 6), angles=np.linspace(-np.pi / 4, np.pi / 4, 9)): """ Generate rotated anchors based on given parameters. :param base_size: Base size of the anchor box :param ratios: Aspect ratio list for generating different shapes :param scales: Scale factors applied to base sizes :param angles: Rotation angle range in radians :return: A set of generated rotated anchors with shape (N, 5) where N is number of total anchors, each row represents an anchor by its center coordinates(x,y), width(w), height(h) and rotation angle(a). """ # Calculate basic properties from input arguments num_ratios = len(ratios) num_scales = len(scales) num_angles = len(angles) # Initialize output array anchors = np.zeros((num_ratios * num_scales * num_angles, 5)) # Iterate over all combinations of scale,ratio & angle idx = 0 for i in range(num_ratios): w = base_size * np.sqrt(ratios[i]) h = base_size / np.sqrt(ratios[i]) for j in range(num_scales): sw = w * scales[j] sh = h * scales[j] for k in range(num_angles): cx = cy = 0 # Center point at origin initially; will be shifted later during sliding window process theta = angles[k] anchors[idx, :] = [cx, cy, sw, sh, theta] idx += 1 return anchors ``` 此函数`generate_rotated_anchors()`接受四个主要参数来控制生成过程: - `base_size`: 定义基础尺寸,默认设置为16像素。 - `ratios`: 控制宽高比的选择范围,默认提供三个选项 `[0.5, 1, 2]`. - `scales`: 调整缩放因子,默认覆盖多个尺度级别。 - `angles`: 设置旋转角度区间,默认从 `-π/4` 到 `+π/4`. 通过调整上述参数组合,可以根据具体应用场景灵活定制所需类型的旋转锚点集。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值