首页 > 其他 > 详细

Blocked Points CodeForces - 392A

时间:2021-09-24 02:23:10      阅读:35      评论:0      收藏:0      [点我收藏+]

原题链接
考察:枚举
思路:
??求出边界点的坐标,然后按公式计算.
??主要就是如何求边界点的坐标,如果两个坐标点嵌套\(for\)循环枚举,\(100\%\)超时.这里考虑是一个坐标从小枚举,另一个坐标从大开始枚举.

Code

#include <iostream> 
#include <cstring>
#include <cmath>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
int n;
LL ans;
LL cal(int i,int j)
{
	return (LL)i*i+(LL)j*j;
}
int main()
{
	scanf("%d",&n);
	if(!n)
	{
		printf("1\n");
		return 0;
	}
	if(n==1)
	{
		printf("4\n");
		return 0;
	}
	int y,minv = n+10,x = 0;
	for(int i=0,j=n;i<=j;i++)
	{
		while(cal(i,j)>(LL)n*n) j--;
		if(i>j) break;
		if(j-i<minv) minv = j-i,x = i,y = j;
	}
	if(x==y) ans = (x-1)*8+8;
	else ans = min(x,y)*8+4;
	printf("%lld\n",ans);
	return 0;
}

Blocked Points CodeForces - 392A

原文:https://www.cnblogs.com/newblg/p/15310857.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!