zoukankan      html  css  js  c++  java
  • bzoj1709[Usaco2007 Oct]Super Paintball超级弹珠*

    bzoj1709[Usaco2007 Oct]Super Paintball超级弹珠

    题意:

    n*n的网格中有k头牛。在一个格子里发射子弹可以射中本格子,同行,同列,左斜线,右斜线(就是一个米字形)的牛,问能射中所有牛的格子有几个。n≤100。

    题解:

    枚举所有格子,从当前格子出发按题目里的方向走累计被射中的牛即可。

    代码:

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define inc(i,j,k) for(int i=j;i<=k;i++)
     5 #define maxn 110
     6 using namespace std;
     7 
     8 inline int read(){
     9     char ch=getchar(); int f=1,x=0;
    10     while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
    11     while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    12     return f*x;
    13 }
    14 int a[maxn][maxn],n,k,ans;
    15 int main(){
    16     n=read(); k=read(); inc(i,1,k){int x=read(),y=read(); a[x][y]++;}
    17     inc(i,1,n)inc(j,1,n){
    18         int tot=0; inc(l,1,n)tot+=a[i][l]+a[l][j];
    19         int kx=i,ky=j; while(kx>=1&&ky>=1)tot+=a[kx][ky],kx--,ky--;
    20         kx=i; ky=j; while(kx<=n&&ky<=n)tot+=a[kx][ky],kx++,ky++;
    21         kx=i; ky=j; while(kx>=1&&ky<=n)tot+=a[kx][ky],kx--,ky++;
    22         kx=i; ky=j; while(kx<=n&&ky>=1)tot+=a[kx][ky],kx++,ky--;
    23         tot-=5*a[i][j]; if(tot==k)ans++;
    24     }
    25     printf("%d",ans); return 0;
    26 }

    20160812

  • 相关阅读:
    webpack之模块(七)
    webpack之配置(六)
    webpack之插件(五)
    webpack之loader(四)
    webpack之模式(三)
    webpack之输出(二)
    webpack之入口起点(一)
    Dynamics CRM Tips
    Step by Step 开发dynamics CRM
    Loading Ring 使用文档
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5774504.html
Copyright © 2011-2022 走看看