SSL-ZYC 2432 面积最大

题目大意:
这里写图片描述


思路:
将半径r转一圈,就得到了
这里写图片描述
A B C = 90 °
∴△ A B C 为直角三角形
A B = ( 2 r ) 2 a 2
S A B C = A B × C B = ( 2 r ) 2 a 2 × a
S A B C D = 2 × S A B C = 2 × ( 2 r ) 2 a 2 × a
同理可得 S E F G H = 2 × ( 2 r ) 2 b 2 × b
阴影面积 = S A B C D + S E F G H a × b = 2 × ( 2 r ) 2 a 2 × a + 2 × ( 2 r ) 2 b 2 × b a × b

我知道你们看不懂
那么由于r的值是确定的,而a,b又必须是正整数,那么我们枚举a和b,就可以求出最终答案啦!

感谢 XXY 同学帮助修改markdown!


代码:

#include <cstdio>
#include <cmath>
#include <iostream>
using namespace std;

double maxn,r,d;
int s1,s2;

int main()
{
    cin>>r;
    for (double i=1;i<2.0*r;i++)
    {
        double a=(double)sqrt(2.0*r*2.0*r-i*i);  //求AB长度
        for (double j=1;j<2.0*r;j++)
        {
            double b=(double)sqrt(2.0*r*2.0*r-j*j);  //求EF长度
            if (a*i+b*j-i*j>maxn)  //求最大值
            {
                maxn=a*i+b*j-i*j;
                s1=(int)i;
                s2=(int)j;  //记录答案
            }
        }
    }
    cout<<s1<<endl<<s2;
    return 0;
}

猜你喜欢

转载自blog.csdn.net/SSL_ZYC/article/details/80374390
今日推荐