ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

2021牛客暑期多校训练营8 K. Yet Another Problem About Pi(几何)

2021-08-09 22:00:41  阅读:266  来源: 互联网

标签:Toilet About 多校 long 牛客 Ares ans line pi


链接:https://ac.nowcoder.com/acm/contest/11259/K
来源:牛客网

题目描述

On a distant planet of dreams, Toilet-Ares is packing up the things and memories, ready to commerce a new adventurous road trip. With outstanding driving skills, the driving route may be a segment, a curve, a polyline, and it can be closed (end-to-end), even self-intersect, as long as the route is continuous. The fuel capacity, oddly enough, can support ππ km driving. Thus, the route has a maximum total length of ππ km.

The planet's surface is expansive and flat enough to regard as a plane. A Cartesian coordinate system, formed with longitude and latitude, is used to describe each geographical position on the planet. Every ww km, draw a line of points with some equal longitude, named meridian. Similarly, every dd km, draw a line of points with some equal latitude, named parallel. Notice that innumerous meridians are perpendicular to innumerous parallels, constructing a grid called graticule, dividing the plane into infinite cells. Inhabitants there are used to defining those cells as regions, and to avoid conflict, positions on meridians or parallels belong to no region.

There are so many different kinds of landscapes to see, to admire, to experience. Toilet-Ares starts the drive at an arbitrary position on the planet. Whenever passing a region for the first time, Toilet-Ares will remember its visual feature (which is always distinguishable from any other region). So, it will be easy for Toilet-Ares to count up the number of regions visited as the road trip ends.

For example, in both situations shown below, four different regions are visited along the route.

img

Just as the saying goes, "Where there is a will, there is a way." Toilet-Ares always attempts to figure out how many different regions at most can visit in the whole road trip. And you, as a friend, are here to answer this question.

输入描述:

The input contains multiple test cases. The first line of input contains one integer TT (1≤T≤1051≤T≤105).

In the following TT lines, each line contains two real numbers w,dw,d (0<w,d≤50<w,d≤5), describing one test case. Any of them may be an integer or contains at most 8 decimal digits. It is guaranteed that there is no trailing zero in decimal place.

输出描述:

For each test case, output the corresponding answer with an integer in one line.

示例1

输入

复制

2
5 5
1.5 1.5

输出

复制

4
8

注意到$\pi \(是实数,而w和d都是有理数,在网格线交点画一个半径为无穷小量的圆则可以占据四个区域,这也是最少的情况。如果想要占据的区域尽可能多,则路线要么贴着网格走(在交点画一个无穷小圆),要么沿着斜线走(也是在交点画一个无穷小圆)。而一段斜线\)\sqrt{w2+d2}$的贡献为3,一段水平/垂直线的贡献为2,令 \(a=min\{w,d\},b=\sqrt{w^2+d^2}\),则算法是对 \(ax+by\leq \pi\) 的非负解求 \(2x+3y\) 的最大值,然后再加上起点的贡献4。同时,x<3 与 y<2 至少有一成立(因为改变操作的情况只有在边界时才会发生),因此直接枚举即可(当然也可以01背包)。注意开long long以免溢出。

#include <bits/stdc++.h>
#define int long long
#define pi acos(-1)
using namespace std;
signed main() {
	int t;
	cin >> t;
	while(t--) {
		double w, d;
		cin >> w >> d;
		double a = min(w, d);
		double b = sqrt(w * w + d * d);
		long long ans = 0;
		//ax + by <= pi
		for(int i = 0; i < 3; i++) {
			if(pi - 1.0 * i * a >= 0) ans = max(ans, (long long) floor((pi - 1.0 * i * a) / b) * 3 + i * 2ll + 4);
			if(pi - 1.0 * i * b >= 0) ans = max(ans, (long long) floor((pi - 1.0 * i * b) / a) * 2 + i * 3ll + 4);
		}
		cout << ans << endl;
	}
}



标签:Toilet,About,多校,long,牛客,Ares,ans,line,pi
来源: https://www.cnblogs.com/lipoicyclic/p/15120867.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有