http://acm.hdu.edu.cn/showproblem.php?pid=6639
题意:给n个点,求在二维矩阵区域{[0,0],[m,m]}中满足[xe,ye]的个数。
思路:用n个点把二维区域划分成(n+2)^2块区域,对于每一个区域,枚举xe模60(2,3,4,5的公倍数)后的数,xe模60后的数,判断是否合理,最后统计该区域该条件下的点个数。复杂度(n^3*60*60)。
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define FI first
#define SE second
#define MP make_pair
#define PII pair<int,int>
const LL mod = 1e9+7;
const int MX = 1e6+5;
int x[20],y[20],k[20],t[20];
vector<int>vx,vy;
LL cal(LL x,LL y){
if(x>y)return 0;
return (y-x)/60+1;
}
int main(){
int T;cin>>T;while(T--){
int n,m;cin>>n>>m;vx.clear(),vy.clear();
for(int i=1;i<=n;i++){
cin>>x[i]>>y[i]>>k[i]>>t[i];
vx.push_back(x[i]);
vy.push_back(y[i]);
}
vx.push_back(0),vx.push_back(m+1);
vy.push_back(0),vy.push_back(m+1);
sort(vx.begin(),vx.end());
sort(vy.begin(),vy.end());
vx.erase(unique(vx.begin(),vx.end()),vx.end());
vy.erase(unique(vy.begin(),vy.end()),vy.end());
int sx=vx.size(),sy=vy.size();
LL ans=0;
for(int i=0;i<=sx-2;i++){
for(int j=0;j<=sy-2;j++){
for(int u=0;u<60;u++){
for(int v=0;v<60;v++){
int tag=1;int X=vx[i]+u,Y=vy[j]+v;
for(int z=1;z<=n;z++){
if((abs(x[z]-X)+abs(y[z]-Y))%k[z]!=t[z]){tag=0;break;}
}
if(tag) ans=ans+cal(X,vx[i+1]-1)*cal(Y,vy[j+1]-1);
}
}
}
}
cout<<ans<<'\n';
}
return 0;
}