1709. [Usaco2007 Oct]Super Paintball超级弹珠

传送门

直接枚举显然是不行的,考虑减少枚举

显然第一头牛一定要被打到,所以合法位置一定在第一头牛的八个方向

因为牛多位置少,所以枚举能打到第一头牛的所有位置,在枚举那个位置能打到的牛的数量,如果全都可以打到就记入答案

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+(ch^48); ch=getchar(); }
    return x*f;
}
const int N=507,xx[8]={0,1,1,1,0,-1,-1,-1},yy[8]={1,1,0,-1,-1,-1,0,1};
int n,m,mp[N][N],ans;
inline void check(int x,int y)
{
    int cnt=mp[x][y];
    for(int k=0;k<8;k++)
        for(int i=1;i<=n;i++)
        {
            int tx=x+xx[k]*i,ty=y+yy[k]*i;
            if(tx<1||tx>n||ty<1||ty>n) continue;
            cnt+=mp[tx][ty];
        }
    if(cnt==m) ans++;
}
int main()
{
    n=read(),m=read();
    int a,b;
    for(int i=1;i<=m;i++)
        a=read(),b=read(),mp[a][b]++;
    check(a,b);
    for(int k=0;k<8;k++)
        for(int i=1;i<=n;i++)
        {
            int tx=a+xx[k]*i,ty=b+yy[k]*i;
            if(tx<1||tx>n||ty<1||ty>n) continue;
            check(tx,ty);
        }
    printf("%d\n",ans);
}

 

转载于:https://www.cnblogs.com/LLTYYC/p/11410990.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值