2021牛客多校8K Yet Another Problem About Pi

Posted 布图

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021牛客多校8K Yet Another Problem About Pi相关的知识,希望对你有一定的参考价值。

题目

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

时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

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 π\\piπ km driving. Thus, the route has a maximum total length of π\\piπ 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 www km, draw a line of points with some equal longitude, named meridian. Similarly, every ddd 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.

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 TTT (1≤T≤1051 \\le T \\le 10^51≤T≤105).

In the following TTT lines, each line contains two real numbers w,dw,dw,d (0<w,d≤50 < w,d \\le 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

输入

[复制](javascript:void(0)😉

2
5 5
1.5 1.5

输出

[复制](javascript:void(0)😉

4
8

解释与代码

你可以走PI米的长度(PI指圆周率3.141592…),给你w和d,把一个无限大的平面分成长为w宽为d的无限多的格子,问最多能经过多少格子

比赛的时候就想的差不多了,但是就是wa,后来发现雀食差一点点

看题解写的暴力

两个方向,斜着和横着(宽度最小的那一个方向),假设经过横竖线交错的那个点,那么可以算接触了四个区域

横着和斜着,横着一次增加2个区域,斜着一次增加三次区域,所以其实我们遍历一遍就可以知道,最多多少了

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <limits.h>
#include <assert.h>
#include <functional>
#include <numeric>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb          push_back
#define ppb         pop_back
#define lbnd        lower_bound
#define ubnd        upper_bound
#define endl        '\\n'
#define mll         map<ll,ll>
#define msl         map<string,ll>
#define mls         map<ll, string>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x)  for(auto& a : x)
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define vll         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define DEBUG       cerr<<"/n>>>I'm Here<<</n"<<endl;
#define display(x)  trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ini(a)      memset(a,0,sizeof(a))
#define ini2(a,b)   memset(a,b,sizeof(a))
#define rep(i,a,b)  for(int i=a;i<=b;i++)
#define case        ll T;cin>>T;for(ll Q=1;Q<=T;Q++)
#define lowbit(x)   x&(-x)
#define pr          printf
#define sc          scanf
#define _           0
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DBG(x) \\
    (void)(cout << "L" << __LINE__ \\
    << ": " << #x << " = " << (x) << '\\n')
#define TIE \\
    cin.tie(0);cout.tie(0);\\
    ios::sync_with_stdio(false);
//#define long long int

//using namespace __gnu_pbds;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI    = acos(-1.0);
const double eps   = 1e-6;
const int    INF   = 0x3f3f3f3f;
const ll     LLINF = 0x3f3f3f3f3f3f3f3f;
const int    maxn  = 1e5+10;
const ll     N     = 5;

typedef struct LNode{
    int coef,index;
    struct LNode *next;
}LNode,*LinkList;

struct SegmentTree{
	int l, r;
	int dat;
}t[N*4];

bool cmp(int a,int b){
	return a>b;
}

void solve(){
	double w, d, p;
	cin>>w>>d;
	if (w>d) {
		p = w;
		w = d;
		d = p;
	}
	p = sqrt(w*w + d*d);
	int ans = 4, q;

    for (int i=0; i<=2000; i++) {
    	if (i*w>PI) break;
    	q = (PI - i*w)/p;
    	ans = max(ans, i*2 + q*3 + 4);
	}
	
	for (int i=0; i<=2000; i++) {
    	if (i*p>PI) break;
    	q = (PI - i*p)/w;
    	ans = max(ans, i*3 + q*2 + 4);
	}
    
    cout<<ans<<endl;
    
}

int main()
{
	TIE;
//    #ifndef ONLINE_JUDGE
//    freopen ("input.txt","r",stdin);
//    #else
//    #endif
//	solve();
    case{solve();}
//    case{cout<<"Case "<<Q<<":"<<endl;solve();}
	return ~~(0^_^0);
}

参考:https://blog.csdn.net/MasterSummeer/article/details/119544864?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162886093216780271515971%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=162886093216780271515971&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2blogfirst_rank_v2~times_rank-1-119544864.pc_v2_rank_blog_default&utm_term=%E7%89%9B%E5%AE%A2%E5%A4%9A%E6%A0%A1%E7%AC%AC8+Yet+Another+Problem+About+Pi&spm=1018.2226.3001.4450

以上是关于2021牛客多校8K Yet Another Problem About Pi的主要内容,如果未能解决你的问题,请参考以下文章

2021牛客多校8 D.OR(位运算)

2021牛客多校9 E.Eyjafjalla(dfs序+主席树)

2021牛客多校5 B Boxes

2021牛客多校1 B Ball Dropping

2021牛客多校8 D OR

2021牛客多校5 H Holding Two