2021牛客暑期多校训练营8 - K - Yet Another Problem About Pi( 思维 + 暴力枚举 )

题目链接:点击进入
题目

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

题意

一条长度为 π \pi π 的线,可以任意弯曲,平面上都是长 w 宽 d 的网格,问线最多能经过多少网格。

思路

线可以任意弯曲,那对于一个交点 ( 被四个网格包围 ) ,这个线如果把他圈起来,也就是围着这个点形成一个圆,那就可以经过 4 个网格,那么这个圆可以无限小,小到周长忽略不计,那么就可以看作经过一个交点,就相当于经过了它周围的格子。那么问题就转换成立,怎样经过格点可以经过尽可能多的格子。
一直按照一个方向走,走的格点越多,经过的格子越多。那么现在问题变成了,是顺着边走,还是走对角线。
顺着边走,那么我们肯定走 min ( w , d ) 的那一边,每到达一个新的格点增加 2 个格子;
走对角线,每到达一个新的格点增加 3 格;
想一下,最优的多半是 多数对角线 + 少数边 ,或者 多数边 + 少数对角线 ( 这样浪费的线长度相对较小 )。这个少数不会很大 ( 实际 <= 2 , 但我。。。不会证/(ㄒoㄒ)/~~,所以我就取 500 暴力[]( ̄▽ ̄)* ),所以我们直接枚举这两种情况的少数,最后取最大值即可;

代码
// Problem: Yet Another Problem About Pi
// Contest: NowCoder
// URL: https://ac.nowcoder.com/acm/contest/11259/K
// Memory Limit: 524288 MB
// Time Limit: 4000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

//#pragma GCC optimize(3)//O3
//#pragma GCC optimize(2)//O2
#include<iostream>
#include<string>
#include<map>
#include<set>
//#include<unordered_map>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<fstream>
#define X first
#define Y second
#define best 131 
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define lowbit(x) x & -x
#define inf 0x3f3f3f3f
// #define int long long
// #define double long double
//#define rep(i,x,y) for(register int i = x; i <= y;++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// const double pai=acos(-1.0);
const int maxn=1e6+10;
const int mod=998244353;
const double eps=1e-9;
const int N=5e3+10;
/*--------------------------------------------*/
inline int read()
{
    int k = 0, f = 1 ;
    char c = getchar() ;
    while(!isdigit(c)){if(c == '-') f = -1 ;c = getchar() ;}
    while(isdigit(c)) k = (k << 1) + (k << 3) + c - 48 ,c = getchar() ;
    return k * f ;
}
/*--------------------------------------------*/

double pai=acos(-1.0);
int t;
double w,d;

signed main() 
{
//	ios::sync_with_stdio(false);
//	cin.tie(0);cout.tie(0);
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lf%lf",&w,&d);
		double m=min(w,d);
		double l=sqrt(w*w+d*d);
		ll ans=0;
		for(int i=0;i<=500;i++)//多数对角线+少数边
		{
			double rest=pai-i*m;
			if(rest<0) break;
			ll tmp=4+i*2+((ll)(rest/l))*3;
			ans=max(ans,tmp);
		}
		for(int i=0;i<=500;i++)//多数边+少数对角线
		{
			double rest=pai-i*l;
			if(rest<0) break;
			ll tmp=4+i*3+((ll)(rest/m))*2;
			ans=max(ans,tmp);
		}
		printf("%lld\n",ans);
	}
    return 0;
} 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值