今天开了新的专题,上午做了三道二分的题目。有两道数学题,还有一道精度问题。
两道数学题就不贴代码了。
贴一道题吧。在这道题里我学会了控制π的精度。用三角函数。
题目如下:

My friends are very annoying and if one of them gets a bigger piece than the others, they start complaining. Therefore all of them should get equally sized (but not necessarily equally shaped) pieces, even if this leads to some pie getting spoiled (which is better than spoiling the party). Of course, I want a piece of pie for myself too, and that piece should also be of the same size.
What is the largest possible piece size all of us can get? All the pies are cylindrical in shape and they all have the same height 1, but the radii of the pies can be different.
3 3 3 4 3 3 1 24 5 10 5 1 4 2 3 4 5 6 5 4 2
25.1327 3.1416 50.2655
源代码如下:
//1、Pie
/*
给N个pie分给F+1个人;
每个人分到的只能是一个pie的一部分或者是整个,不能是不同的pie拼起来的。
求能分到的最大值。
二分法,在0和最大的体积之间二分,直到找到可以分且最大的值结束。
注意精度的控制……好像很严格……
*//*
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stdio.h>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
const double pi = atan(1.0)*4;
int F,N,n,r,i;
int sum;
double V[10005];
scanf("%d",&n);
while (n--)
{
double ans = 0;
double max1 = 0;
memset(V,0,sizeof(V));
scanf("%d %d",&N,&F);
for (i = 1; i <= N; i++)
{
scanf("%d",&r);
V[i] = pi * r * r;
if (V[i] > max1)
max1 = V[i];
}
double l = 0.0;
double r = max1;
double mid;
while (r - l > 0.00001)
{
mid = (l + r) / 2;
sum = 0;
for (i = 1; i <= N; i++)
{
sum += (int)(V[i]/mid);
}
if (sum >= F+1)
{
l = mid;
ans = mid;
}
else
r = mid;
}
cout << setiosflags(ios::fixed) << setprecision(4) << ans << endl;
}
return 0;
}
这个题没什么说的,二分就出来了。也算是复习了一下二分。
下午做了一场练习赛。居然有三角形的dp。题目比较简单A了四道但是大佬们都五六道……差距还是很明显的……
这些题就不贴代码了、
然后晚上又看了看单调队列。感觉并没有之前想的那么简单……还是不是很理解。
好像明白了单调队列的思想,但是还是不太明白代码是怎么实现的。
把单调队列想的太简单了……
明天继续看单调队列。争取能够深入理解一下。
然后刷题……