BZOJ4115 : [Wf2015]Tile Cutting
设一种方案里三角形上三个点的坐标分别为$(0,0),(-a,b),(c,d)$,则得到的平行四边形的面积为$ac+bd$。
设$d(n)$为$n$的约数个数,$D$为$d$的生成函数,则答案的生成函数$=D^2$。
先用线性筛$O(n)$求出$d$,再用FFT在$O(n\log n)$的时间内预处理出所有答案即可。
#include<cstdio>
#include<cmath>
#include<algorithm>
#define N 1048576
using namespace std;
typedef long long ll;
int n=500000,d[N],g[N],i,j,p[N],tot,T,l,r,ans;bool v[N>>1];ll f[N];
struct comp{
double r,i;comp(double _r=0,double _i=0){r=_r;i=_i;}
comp operator+(const comp x){return comp(r+x.r,i+x.i);}
comp operator-(const comp x){return comp(r-x.r,i-x.i);}
comp operator*(const comp x){return comp(r*x.r-i*x.i,r*x.i+i*x.r);}
}a[N];
const double pi=acos(-1.0);
void FFT(comp a[],int n,int t){
for(int i=1,j=0;i<n-1;i++){
for(int s=n;j^=s>>=1,~j&s;);
if(i<j)swap(a[i],a[j]);
}
for(int d=0;(1<<d)<n;d++){
int m=1<<d,m2=m<<1;
double o=pi/m*t;comp _w(cos(o),sin(o));
for(int i=0;i<n;i+=m2){
comp w(1,0);
for(int j=0;j<m;j++){
comp &A=a[i+j+m],&B=a[i+j],t=w*A;
A=B-t;B=B+t;w=w*_w;
}
}
}
if(t==-1)for(int i=0;i<n;i++)a[i].r/=n;
}
int main(){
for(d[1]=1,i=2;i<=n;i++){
if(!v[i])p[tot++]=i,d[i]=2,g[i]=1;
for(j=0;i*p[j]<=n&&j<tot;j++){
v[i*p[j]]=1;
if(i%p[j]){
d[i*p[j]]=d[i]*2;
g[i*p[j]]=1;
}else{
d[i*p[j]]=d[i]/(g[i]+1)*(g[i]+2);
g[i*p[j]]=g[i]+1;
break;
}
}
}
for(i=1;i<=n;i++)a[i].r=d[i];
FFT(a,N,1);
for(i=0;i<N;i++)a[i]=a[i]*a[i];
FFT(a,N,-1);
for(i=1;i<=n;i++)f[i]=(ll)(a[i].r+0.5);
for(scanf("%d",&T);T--;printf("%d %lld\n",ans,f[ans])){
scanf("%d%d",&l,&r);
for(ans=l;l<=r;l++)if(f[l]>f[ans])ans=l;
}
return 0;
}
BZOJ4115 : [Wf2015]Tile Cutting的更多相关文章
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- bzoj4109: [Wf2015]Cutting Cheese
Description 给定一个100*100*100(单位:毫米)的奶酪方块,这个奶酪含有n个球形小孔.现在要求将这个奶酪切成s片使得每片质量相等. Input 第一行包含两个整数n,s,表示奶酪有 ...
- Vector Tile
Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...
- OpenGL Insights 阅读有感 - Tile Based架构下的性能调校 翻译
Performance Tunning for Tile-Based Architecture Tile-Based架构下的性能调校 by Bruce Merry GameKnife译 译序 在大概1 ...
- geotrellis使用(十八)导入多波段Tiff、读取多波段Tile
Geotrellis系列文章链接地址http://www.cnblogs.com/shoufengwei/p/5619419.html 目录 前言 多波段数据导入 读取多波段瓦片 提取单波段 总结 一 ...
- [Python学习] python 科学计算库NumPy—tile函数
在学习knn分类算法的过程中用到了tile函数,有诸多的不理解,记录下来此函数的用法. 函数原型:numpy.tile(A,reps) #简单理解是此函数将A进行重复输出 其中A和reps都是ar ...
- Python-Numpy函数-tile函数
tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...
- 百度地图TILE算法
Creating primary keyvar LLBAND2 = [75, 60, 45, 30, 15, 0]; var LL2MC2 = [[-.0015702102444, 111320.70 ...
- How to tile small texture image onto page as its background
You don’t need to set a big size image as the background of pages if the image is texture or uniform ...
随机推荐
- css radial-gradient()函数用法
radial:半径的:放射状的:射线:光线:径向 gradient:梯度,坡度:渐变 radial-gradient:径向渐变 radial-gradient()函数:用径向渐变创建函数.径向渐变由中 ...
- Codeforces #55D-Beautiful numbers (数位dp)
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- bzoj千题计划286:bzoj1226: [SDOI2009]学校食堂Dining
http://www.lydsy.com/JudgeOnline/problem.php?id=1226 关键点:一个人只能忍受 ‘紧跟’ 在他 后面的b个人比他先打到饭 dp[i][j][k] 前i ...
- bzoj千题计划183:bzoj1197: [HNOI2006]花仙子的魔法
http://www.lydsy.com/JudgeOnline/problem.php?id=1197 题意转化:在n维空间中放m个n维球,问最多将空间分成几部分 f[i][j] 表示在i维空间中放 ...
- c#的事件用法——实现下载时发生的事件
//下载时发出的事件 using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- Spring 学习01
一.Spring概念 1 spring是开源的轻量级框架 2 spring核心主要两部分: (1)aop:面向切面编程,扩展功能不是修改源代码实现 (2)ioc:控制反转, - 比如有一个类,在类里面 ...
- Asp.Net中索引器的用法
索引器定义类似于属性,但其功能与属性并不相同.索引器提供一种特殊的方法编写get和set访问器.属性可以像访问字段一样访问对象的数据,索引器可以使用户像访问数组一样访问类成员. 一.索引器特性 1.g ...
- BZOJ4818 序列计数
4818: [Sdoi2017]序列计数 Time Limit: 30 Sec Memory Limit: 128 MB Description Alice想要得到一个长度为n的序列,序列中的数都是 ...
- Linux - sed 常用操作
sed 文本常用操作方式 sed 10q # 显示文件中的前10行 (模拟"head") sed -n '$=' # 计算行数(模拟 "wc -l") sed ...
- 扩展欧几里得(E - The Balance POJ - 2142 )
题目链接:https://cn.vjudge.net/contest/276376#problem/E 题目大意:给你n,m,k,n,m代表当前由于无限个质量为n,m的砝码.然后当前有一个秤,你可以通 ...