HDU multi-school sixth 1006 Faraway - mathematics division space +

Topic links: point I ah ╭ (╯ ^ ╰) ╮

Subject to the effect:

    There are two dimensions n n points, are satisfied, and
     ( x i x e + Y i Y e ) (| X_i-x_e | + | y_i-y_e |) m O d mod k i = t i k_i=t_i
    begging ( x e , Y e ) (X_e, y_e) Number

Problem-solving ideas:Here Insert Picture Description

    enumerate n 2 n^2 Shi regions
    for each region, only enumerate 60 60 60*60 size can
    then calculate the number of points within the region legitimate

Core: enumeration area, mathematical thinking

#include<bits/stdc++.h>
#define rint register int
#define deb(x) cerr<<#x<<" = "<<(x)<<'\n';
using namespace std;
typedef long long ll;
int T, n, m, tx[15], ty[15];
struct node{
	int x, y, k, t;
} a[15];

bool check(int x, int y){
	for(int i=1; i<=n; i++)
		if((abs(a[i].x-x) + abs(a[i].y-y)) % a[i].k != a[i].t)
			return false;
	return true;
}

ll cal(int l, int r){
	ll cnt = r - l - 1;
	if(cnt < 0) return 0;
	return cnt / 60 + 1;
}

int main() {
	scanf("%d", &T);
	while(T--){
		scanf("%d%d", &n, &m);
		for(int i=1; i<=n; i++){
			scanf("%d%d%d%d", &a[i].x, &a[i].y, &a[i].k, &a[i].t);
			tx[i] = a[i].x, ty[i] = a[i].y;
		}
		tx[n+1] = ty[n+1] = m + 1;
		sort(tx+1, tx+2+n);
		sort(ty+1, ty+2+n);
		int cnt1 = unique(tx+1, tx+2+n) - tx - 1;
		int cnt2 = unique(ty+1, ty+2+n) - ty - 1;
		
		ll ans = 0;
		for(int nx=0; nx<cnt1; nx++)
			for(int ny=0; ny<cnt2; ny++)
				for(int i=0; i<60; i++)
					for(int j=0; j<60; j++)
						if(check(tx[nx]+i, ty[ny]+j))
							ans += cal(tx[nx]+i, tx[nx+1]) * cal(ty[ny]+j, ty[ny+1]);
		printf("%lld\n", ans);
	}
}
Published 221 original articles · won praise 220 · views 20000 +

Guess you like

Origin blog.csdn.net/Scar_Halo/article/details/103037194