[UVA 12633] Super Rooks on Chessboard FFT+计数
如果只有行和列的覆盖,那么可以直接做,但现在有左上到右下的覆盖.
考虑对行和列的覆盖情况做一个卷积,然后就有了x+y的非覆盖格子数.
然后用骑士的左上到右下的覆盖特判掉那些x+y的格子就可以了.
注意题意,Row是从上到下来的,被坑得好惨.
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<string>
#include<iomanip>
#include<algorithm>
#include<map>
using namespace std;
#define LL long long
#define FILE "dealing"
#define up(i,j,n) for(LL i=j;i<=n;++i)
#define db double
#define ull unsigned long long
#define eps 1e-10
#define pii pair<LL,LL>
LL read(){
LL x=0,f=1,ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return f*x;
}
const LL maxn=402000,maxm=20000,mod=(LL)(1e9+7+0.1),limit=(LL)(1e6+1),inf=(LL)(1e9);
bool cmax(LL& a,LL b){return a<b?a=b,true:false;}
bool cmin(LL& a,LL b){return a>b?a=b,true:false;}
namespace FFT{
db pi=acos(-1.0);
struct cp{
db x,y;
cp(db x=0,db y=0):x(x),y(y){}
cp operator+(const cp& b){return cp(x+b.x,y+b.y);}
cp operator-(const cp& b){return cp(x-b.x,y-b.y);}
cp operator*(const cp& b){return cp(x*b.x-y*b.y,x*b.y+y*b.x);}
}w[maxn],a[maxn],b[maxn];
LL R[maxn],H,L;
void FFT(cp* a,LL f){
up(i,0,L-1)if(i<R[i])swap(a[i],a[R[i]]);
for(LL len=2;len<=L;len<<=1){
LL l=len>>1;
cp wn(cos(pi/l),f*sin(pi/l));
up(i,1,l-1)w[i]=w[i-1]*wn;
for(LL st=0;st<L;st+=len)
for(LL k=0;k<l;k++){
cp x=a[st+k],y=w[k]*a[st+k+l];
a[st+k]=x+y;a[st+k+l]=x-y;
}
}
if(f==-1)up(i,0,L-1)a[i].x/=L;
}
void solve(LL* c,LL* d,LL n,LL m,LL* ch){
n++,m++;
up(i,0,n-1)a[i].x=c[i],a[i].y=0;
up(i,0,m-1)b[i].x=d[i],b[i].y=0;
for(H=0,L=1;L<n+m-1;H++)L<<=1;
up(i,n,L)a[i].x=a[i].y=0;
up(i,m,L)b[i].x=b[i].y=0;
up(i,1,L)R[i]=(R[i>>1]>>1)|((i&1)<<(H-1));
w[0].x=1;
FFT(a,1);FFT(b,1);
up(i,0,L-1)a[i]=a[i]*b[i];
FFT(a,-1);
up(i,1,n+m-1)ch[i]=(LL)(a[i].x+0.5);
}
};
LL n,m,K;
LL a[maxn],b[maxn],c[maxn],d[maxn];
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
LL T=read();
up(j,1,T){
n=read(),m=read(),K=read();
up(i,1,n)a[i]=1;
up(i,1,m)b[i]=1;
up(i,1,n+m)d[i]=0;
up(i,1,K){
LL x=n-read()+1,y=read();
a[x]=0,b[y]=0;
d[x+y]=1;
}
FFT::solve(a,b,n,m,c);
LL ans=0;
up(i,1,n+m)if(c[i]&&!d[i])ans+=c[i];
printf("Case %lld: %lld\n",j,ans);
}
return 0;
}
[UVA 12633] Super Rooks on Chessboard FFT+计数的更多相关文章
- UVA 12633 Super Rooks on Chessboard [fft 生成函数]
Super Rooks on Chessboard UVA - 12633 题意: 超级车可以攻击行.列.主对角线3 个方向. R * C 的棋盘上有N 个超级车,问不被攻击的格子总数. 行列好好做啊 ...
- UVA 12633 Super Rooks on Chessboard(FFT)
题意: 给你一个R*C的棋盘,棋盘上的棋子会攻击,一个棋子会覆盖它所在的行,它所在的列,和它所在的从左上到右下的对角线,那么问这个棋盘上没有被覆盖的棋盘格子数.数据范围R,C,N<=50000 ...
- UVA 12633 Super Rooks on Chessboard ——FFT
发现对角线上的和是一个定值. 然后就不考虑斜着,可以处理出那些行和列是可以放置的. 然后FFT,统计出每一个可行的项的系数和就可以了. #include <map> #include &l ...
- UVA 12633 Super Rooks on Chessboard (生成函数+FFT)
题面传送门 题目大意:给你一张网格,上面有很多骑士,每个骑士能横着竖着斜着攻击一条直线上的格子,求没被攻击的格子的数量总和 好神奇的卷积 假设骑士不能斜着攻击 那么答案就是没被攻击的 行数*列数 接下 ...
- UVa12633 Super Rooks on Chessboard(容斥 + FFT)
题目 Source http://acm.hust.edu.cn/vjudge/problem/42145 Description Let’s assume there is a new chess ...
- UVA12633 Super Rooks on Chessboard
题目描述 题解: 第一眼满眼骚操作,然后全部否掉. 然后屈服于题解,才发现这题这么执掌. 首先,如果这个东西是普通的车,那我们可以记录一下$x,y$的覆盖情况,然后减一下; 但是这个可以斜着走. 所以 ...
- UVA - 12298 Super Poker II NTT
UVA - 12298 Super Poker II NTT 链接 Vjudge 思路 暴力开个桶,然后统计,不过会T,用ntt或者fft,ntt用个大模数就行了,百度搜索"NTT大模数&q ...
- UVA - 11134 Fabled Rooks[贪心 问题分解]
UVA - 11134 Fabled Rooks We would like to place n rooks, 1 ≤ n ≤ 5000, on a n × n board subject to t ...
- uva 11134 - Fabled Rooks(问题转换+优先队列)
题目链接:uva 11134 - Fabled Rooks 题目大意:给出n,表示要在n*n的矩阵上放置n个车,并且保证第i辆车在第i个区间上,每个区间给出左上角和右小角的坐标.另要求任意两个车之间不 ...
随机推荐
- linux系统中毒排查学习记录
linux有许多的版本,主要关注redhat(centos)和ubuntu这两个主流版本 以下命令基本都需要root权限,执行命令前记得加sudo 第一步 top,ps命令查看系统资源和负载情况,查看 ...
- Js删除Table中的一行
<html> <head> <title></title> <script type="text/javascript"> ...
- su、sudo、sudo su、sudo -i的用法和区别
sudo : 暂时切换到超级用户模式以执行超级用户权限,提示输入密码时该密码为当前用户的密码,而不是超级账户的密码.不过有时间限制,Ubuntu默认为一次时长15分钟.su : 切换到某某用户模式,提 ...
- 2016.3.23 集成新版activiti-modeler(5.17+)到项目中
书:<activiti实战> 博客: http://www.kafeitu.me/activiti/2013/03/10/integrate-activiti-modeler.html h ...
- 怎样备份Github博客至GitCafe
原文链接:http://stackvoid.com/how-to-transfer-github-pages-to-gitcafe/ 开通博客半年多了,一直将博客托管到 Github 上,使用 Git ...
- merge-sorted-array——合并两个有序数组
Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume th ...
- nginx for windows 配置多域名反向代理
调试了很久...哦耶 共享出来吧 其实 nginx反向代理同一ip多个域名,给header加上host就可以了 upstream test.test.cn { server 119. ...
- python coding style guide 的高速落地实践
python coding style guide 的高速落地实践 机器和人各有所长,如coding style检查这样的可自己主动化的工作理应交给机器去完毕,故发此文帮助你在几分钟内实现coding ...
- A和B是好友,他们经常在空闲时间聊天,A的空闲时间为[a1 ,b1 ],[a2 ,b2 ]..[ap ,bp ]。B的空闲时间是[c1 +t,d1 +t]..[cq +t,dq +t],这里t为B的起床时间。这些时间包括了边界点。B的起床时间为[l,r]的一个时刻。若一个起床时间能使两人在任意时刻聊天,那么这个时间就是合适的,问有多少个合适的起床时间?
// ConsoleApplication5.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<vector> ...
- 现在有一个城市销售经理,需要从公司出发,去拜访市内的商家,已知他的位置以及商家的位置,但是由于城市道路交通的原因,他只能在左右中选择一个方向,在上下中选择一个方向,现在问他有多少种方案到达商家地址。给定一个地图map及它的长宽n和m,其中1代表经理位置,2代表商家位置,-1代表不能经过的地区,0代表可以经过的地区,请返回方案数,保证一定存在合法路径。保证矩阵的长宽都小于等于10。
include "stdafx.h" #include<iostream> #include<vector> #include<algorithm&g ...