cf 156 div.2 D. Mr. Bender and Square

这题就是先算总面积,再减去超出面积,再加上重叠面积。关键要注意细节。

 

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
#define INF 1E9
using namespace std;
int main()
{
    long long n,x,y,c;
    cin>>n>>y>>x>>c;
    long long now=0;
    long long i,xr,xl,yu,yd,d;
    x--;y--;
    for(i=1;now<c;i++)
    {
        now=i*i+(i-1)*(i-1);
        if(now<c)continue;
        i--;
        xr=x+i;
        xl=x-i;
        yu=y-i;
        yd=y+i;
        if(xl<0)now-=xl*xl;
        if(xr>n-1)now-=(xr-n+1)*(xr-n+1);
        if(yu<0)
        {
            now-=yu*yu;
            yu++;
            d=-yu;
            if(x+d>n-1)now+=(x+d-n+2)*(x+d-n+1)/2;
            if(x+yu<0)now+=(x-d)*(x-d-1)/2;
        }
        if(yd>n-1)
        {
            now-=(yd-n+1)*(yd-n+1);
            d=yd-n+1;
            d--;
            if(x+d>n-1)now+=(x+d-n+2)*(x+d-n+1)/2;
            if(x-d<0)now+=(x-d)*(x-d-1)/2;
        }
        i++;
    }
    cout<<i-2<<endl;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值