【ACM】HDU 6639 Faraway 2019杭电多校第六场1006(枚举)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6639

Faraway

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 268    Accepted Submission(s): 137


 

Problem Description

n soldiers are dispatched to somewhere in Byteland. These soldiers are going to set off now, but the target location is not so clear.

Assume the target location is at (xe,ye), it is clear that xe,ye are both non-negative integers within [0,m]. For the i-th soldier, the only thing he knows is that (|xi−xe|+|yi−ye|)modki=ti.

To find the correct target location, these soldiers are working on the information they have now. Please write a program to figure out the number of possible target locations.

 

 

Input

The first line of the input contains an integer T(1≤T≤10), denoting the number of test cases.

In each test case, there are two integers n,m(1≤n≤10,1≤m≤109) in the first line, denoting the number of soldiers and the upper bound of xe,ye.

For the next n lines, each line contains four integers xi,yi,ki,ti(0≤xi,yi≤m,2≤ki≤5,0≤ti

 

 

Output

For each test case, print a single line containing an integer, denoting the number of possible target locations.

 

 

Sample Input

 

2

2 5

1 2 4 2

3 1 2 1

2 5

1 2 4 2

1 2 4 3

 

 

Sample Output

 

10

0

题目大意:

有n个形如 |x-a|+|y-b| mod k =t 的等式,给出a,b,k,t,求同时满足所有的等式的x,y有多少种

思路:

【ACM】HDU 6639 Faraway 2019杭电多校第六场1006(枚举)_第1张图片

代码:

#include 
using namespace std;
int a[15],b[15],x[15],y[15],xe[15],ye[15];
int check(int xx,int yy,int n)
{
    for(int i=1;i<=n;i++)
    {
        if((abs(xx-xe[i])+abs(yy-ye[i]))%a[i]!=b[i])
            return 0;
    }
    return 1;
}
int cal(int l,int r)
{
    r-=l;
    if(r<0)
        return 0;
    else
        return r/60+1;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int t,n,m;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        long long ans=0;
        for(int i=1;i<=n;i++)
            scanf("%d%d%d%d",&xe[i],&ye[i],&a[i],&b[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+1;i++)
//            printf("%d\n",x[i]);
        for(int i=0;i<=n;i++)
        {
            for(int j=0;j<=n;j++)
            {
                for(int k=0;k<60;k++)
                {
                    for(int h=0;h<60;h++)
                    {
                        int xx=x[i]+k,yy=y[j]+h;
                        if(check(xx,yy,n))
                            ans+=(long long)cal(xx,x[i+1]-1)*cal(yy,y[j+1]-1);
                    }
                }
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

你可能感兴趣的:(【ACM】HDU 6639 Faraway 2019杭电多校第六场1006(枚举))