問題蟲洞:Faraway
黑洞內窺:
給出n個形如 (|xi−xe|+|yi−ye|) % ki=ti.
以及xi,xe, yi, ye 的最大範圍m
( 1<= ki <=5, 0<= ti <=4)
求有多少對(xe, ye)符合這n個式子
思維光年:
我的思路: 枚舉m,以60爲單位,but,,這只是一個x,,,你還要枚舉y。。
理性的求解:
ACcode:
//#include<bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include<algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <cstring>
#include <string.h>
#include <string>
#include <math.h>
#include <sstream>
using namespace std;
typedef long long int ll;
const ll MAXN = 100005;
#define INF 0x3f3f3f3f//將近ll類型最大數的一半,而且乘2不會爆ll
const ll mod = 2100000007;
const double eps = 0.00000001;
const double pi = acos(-1);
int b[20], c[20], x[20], y[20], xe[20], ye[20];
int t, n, m;
int is(int x, int y)
{
for(int i=1; i<=n; ++i)
{
if((abs(x-xe[i]) + abs(y-ye[i]))%b[i] != c[i])
return 0;
}
return 1;
}
ll qv(int l, int r)
{
r-=l;
if(r < 0) return 0;
else return r/60+1;
}
int main()
{
cin >> t;
while(t--)
{
scanf("%d %d", &n, &m);
ll ans = 0;
for(int i=1; i<=n; ++i)
scanf("%d %d %d %d", &xe[i], &ye[i], &b[i], &c[i]);
x[0] = 0, y[0] = 0; //一個正方形邊界
x[n+1] = m+1, y[n+1] = m+1;
for(int i=1; i<=n; ++i)
x[i] = xe[i], y[i] = ye[i];
sort(x, x+n+2);
sort(y, y+n+2);
for(int i=0; i<=n; ++i)//枚舉(n+1)^2個區域
for(int j=0; j<=n; ++j)
for(int k=0; k<60; ++k)//枚舉xe和ye
for(int h=0; h<60; ++h)
{
int xx = x[i]+k, yy = y[j]+h;
if(is(xx, yy))//計算區域的點
ans+=qv(xx, x[i+1]-1)*qv(yy, y[j+1]-1);
}
cout << ans << '\n';
}
return 0;
}