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 ...
随机推荐
- Hive SQL 编译过程
转自:http://www.open-open.com/lib/view/open1400644430159.html Hive跟Impala貌似都是公司或者研究所常用的系统,前者更稳定点,实现方式是 ...
- influxdb简单使用
之前对influxdb有一个简单的了解和入门的使用,近期由于想使用influxdb做一点东西玩玩,又要捡起influxdb.本篇就针对influxdb的数据库.表的概念,增删改查操作.RESTful操 ...
- 在android手机上通过Html5Plus调用java类。
关于html5plus的资料参考http://www.html5plus.org/ 最近通过html5做手机app,其中涉及到网络通过,必须采用原生的socket,websocket无法满足要求,ht ...
- Nginx 服务器性能Bug和性能优化方案(真实经历)
一.遇到的问题 1.问题:本应该是3个ffmpeg ,但是怎么会有5个ffmpeg出现? 2.Lua脚本问题,一直写入日志,导致有大量的日志,这里的错误日志是直接写进nginx的error.log 日 ...
- springmvc常用注解标签详解-推荐
1.@Controller 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理层处理之后封装成一个Model ...
- Python 入门基础8 --函数基础1 定义、分类与嵌套使用
目录 零.了解函数 一.函数的组成 二.函数的定义 三.函数的使用 四.函数的分类 五.函数的嵌套使用 零.了解函数 1.什么是函数 在程序中函数就是具备某一功能的工具 2.为何用函数 为了解决以下问 ...
- CSS marging相关
一.margin可以为负值 在盒模型中,内容区的width/height.padding.border都不能为负值,但是margin例外,它可以为负值. margin负值的本质,在于它改变了元素在普通 ...
- nginx_upstream_check_module监控后端服务器http
nginx_upstream_check_module 是专门提供负载均衡器内节点的健康检查的外部模块,由淘宝的姚伟斌大神开发,通过它可以用来检测后端 realserver 的健康状态.如果后端 re ...
- C#使用redis学习笔记
1.官网:http://redis.io/(英) http://www.redis.cn/(中) 2.下载:https://github.com/dmajkic/redis/downloads(Wi ...
- css1-puchong1
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. 一:HTML DOM 树 ...