[乱搞] BZOJ 4434 [Cerc2015]Ice Igloos

这里写图片描述

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

double r[505][505];
double A,B,C;
double K,L;

int Count(int x,int y1,int y2){
  int ret=0;
  for (int y=y1;y<=y2;y++)
    ret+=r[x][y]>0.0 && fabs(A*x+B*y+C)<=r[x][y];
  return ret;
}

int main(){
  freopen("t.in","r",stdin);
  freopen("t.out","w",stdout);
  int n,Q,x,y; double _r;
  scanf("%d",&n);
  for (int i=1;i<=n;i++)
    scanf("%d%d%lf",&x,&y,&_r),r[x][y]=_r;
  scanf("%d",&Q);
  while (Q--){
    int x1,x2,y1,y2;
    scanf("%d%d%d%d",&x1,&y1,&x2,&y2); 
    if (x1>x2 || (x1==x2 && y1>y2))
      swap(x1,x2),swap(y1,y2);
    int ret=0;
    if (x1==x2){
      for (int y=y1;y<=y2;y++)
        ret+=r[x1][y]>0.0;
    }else if (y1==y2){
      for (int x=x1;x<=x2;x++)
        ret+=r[x][y1]>0.0;
    }else{
      A=(y2-y1)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
      B=(x1-x2)/sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
      C=-(A*x1+B*y1);
      K=(double)(y2-y1)/(x2-x1);
      L=y1-K*x1;
      int l,r,t;
      if (y2>y1) {
        l=y1,r=ceil(K*(x1+1)+L-1e-6);
        ret+=Count(x1,l,r);
        for (int x=x1+1;x<x2;x++) {
          t=r,r=ceil(K*(x+1)+L-1e-6);
          ret+=Count(x,l,r);
          l=t-1;
        }
        ret+=Count(x2,l,r);
      }else{
        r=y1,l=floor(K*(x1+1)+L+1e-6);
        ret+=Count(x1,l,r);
        for (int x=x1+1;x<x2;x++){
          t=l,l=floor(K*(x+1)+L+1e-6);
          ret+=Count(x,l,r);
          r=t+1;
        }
        ret+=Count(x2,l,r);
      }
    }
    printf("%d\n",ret);
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值