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

  • 相关阅读:
    基本STRUTS标签-学习笔记-Logic标签
    Static的使用
    模板template
    iostream与iostream.h的区别
    数据库连接池
    canvas基础
    javascript面试题集
    ES6新特性学习
    原型和原型链
    css为tbody或者li奇数偶数行样式
  • 原文地址:https://www.cnblogs.com/YuanZiming/p/5774504.html
Copyright © 2011-2022 走看看