二分题整理

1 篇文章 0 订阅

题目链接

When repairing an electronic board, Basil discovered that the board had already been under repair, and one of the resistors on it was replaced with a strange design. The design consisted of k series of connected links, and each link in them — of two resistors connected in parallel.
在这里插入图片描述

Moreover, in each link, along with the typical resistor, with a clearly readable denomination, there was a resistor with a strange, non-standard marking. Having examined the non-standard resistors, Basil came to the conclusion that they were of the same type. However, he could not determine their value. The total resistance value of the entire circuit was equal to R ohms. Having written out the nominal value of the known resistor for each link in the circuit, Basil received a series of integers r1, r2, …, rk.
Help Basil — write a program that calculates the value of the mysterious resistors from the total resistance of the circuit R, and the known values r1, r2, …, rk.

Input:

The first line of the input data contains two integers k (1≤k≤1000) and R (1≤R≤100000), separated by a space.

The second line contains k integers separated by spaces: r1, r2,…, rk (1≤ri≤100000; 2R≤r1+r2+…+rk).

Output:

The program should output a single number — the estimated value of the mysterious resistors. The value must be outputed with an accuracy of 10−6.

#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int n,R,r[10005];

double cnt(double k)
{
    double sum=0;
    for(int i=1; i<=n; i++)
    {
        sum+=(r[i]*k)/(r[i]+k);
    }
    return sum;
}

double f(double l,double r)
{
    double mid=(l+r)/2;
    double ans=cnt(mid);
    if(abs(ans-R)<0.0000001)
    {
        return mid;
    }
    if(ans>R)
        return f(l,mid);
    else
        return f(mid,r);
}

int main()
{
    cin>>n>>R;
    for(int i=1; i<=n; i++)
        cin>>r[i];
    printf("%.8lf\n",f(0,100000));
    return 0;
}

—————————————————————————————————
题目链接

While analyzing a mathematical problem, a programmer, Basil by name, noticed an interesting fact: for the numbers 2 and 4 holds the equality 24=42. ‘This could be a great challenge for the participants of the programming championship,’ he thought. Unfortunately, Basil could not find other such pairs of numbers, the pair 2 and 4 was his only combination that he could think of. ‘Okay, then we’ll change the conditions, let there be three numbers,’ Basil decided. The written program of enumeration options confirmed that with three numbers the task made sense.

Your task: find the integer x by the given integers a and b such that falls in the range from 1 to 1018 (Basil’s program didn’t deal with greater numbers) such that ax=xb. If there are several such numbers, type the smaller of them. If such a number does not exist, type 0.

Input:

The input data consist of two integers a and b (2≤a,b≤10000; a≠b), separated by a blank space.

Output:

The integer x if there is a solution, or 0 (zero) if there is no solution.

#include <iostream>
#include <cmath>
#include <cstdio>
#define ll long long
using namespace std;
ll a,b;

ll f(ll l,ll r)
{
    if(l>r)
        return 0;
    ll mid=(l+r)/2;
    double x=(double)(log(mid)/log(a));
    if(abs(x*b-mid)<0.00000000001)
    {
        ll ans  = f(1,mid-1);
        if(ans)
            return ans;
        return mid;
    }
    if(x*b>mid)
        return f(mid+1,r);
    else
        return f(l,mid-1);
}

int main()
{
    cin>>a>>b;
    printf("%lld\n",f(1,1e18));
    return 0;
}

—————————————————————————————————
题目链接

在一个二维平面上,有一个顶点分别在 (x0,  y0), (x0 + a,  y0), (x0,  y0 + b) 三点上的三角形 A。
请给出一条平行于 y 轴的直线 L: x = c,使得三角形 A 被直线 L 分成面积相等的两半。
正式地讲,请给出一个实数 c,使得三角形 A 中,坐标小于或等于 c 的点所组成图形的面积 SLeft,与坐标大于 c 的点所组成图形的面积 SRight 相等。

Input:

一行,四个整数 x0, y0, a, b ( - 1, 000 ≤ x0, y0 ≤ 1, 000, 1 ≤ a, b ≤ 1, 000)。
表示三角形 A 三个顶点 (x0,  y0), (x0 + a,  y0), (x0,  y0 + b) 所对应的参数。

Output:

一个实数 c,需满足 x0 ≤ c ≤ x0 + a,表示一条直线 L: x = c,可将三角形 A 分成面积相等的两半。
但你不需要给出该实数的精确表示,只需要输出一个浮点数,使得它与标准答案的绝对误差或对标准答案的相对误差,不超过 10 - 4,即认为你给出的答案正确。
正式地讲,记你给出的浮点数答案是 c,标准答案为 d,当 ,则认为你给出的答案正确。

#include <iostream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define ll long long
using namespace std;
const int maxn = 1e5+10;
double x,y,a,b;
double area;

double find(double l,double r)
{
    double mid = (l+r)*1.0/2;
    double h = ((x+a-mid)*b)/a;
    double S = (h*(x+a-mid))/2;
    if(abs(S-area)<0.00000000001)
    {
        return mid;
    }
    if(S>area)
        return find(mid,r);
    else
        return find(l,mid);
}

int main()
{
    scanf("%lf%lf%lf%lf",&x,&y,&a,&b);
    area = a*b/2;
    area/=2;
    double ans = find(x,x+a);
    // double l=x,r=x+a;
    // while (r-l>0.000000001)
    // {
    //     double mid = (l+r)/2;
    //     double h = b*(a+x-mid)/a;
    //     double right = (x+a-mid)*h/2;
    //     if(right>=area)
    //         l=mid;
    //     else 
    //         r=mid;
    // }
    // printf("%.10lf\n",l);
    printf("%.10lf\n",ans);
    return 0;
}

—————————————————————————————————
奇怪的奇数

在这里插入图片描述

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#define ll long long
#define lowbit(x) ((~x+1)&x)
using namespace std;

ll n;
int main() {
    cin>>n;
    ll l=1,r=1e9+10;
    ll ans;
    while(l<=r) {
        ll mid = (l+r)>>1;
        if(mid*log10(mid)+1>=n) {
            ans = mid;
            r=mid-1;
        }
        else l=mid+1;
    }
    cout<<ans<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
目标检测(Object Detection)是计算机视觉领域的一个核心问,其主要任务是找出图像所有感兴趣的目标(物体),并确定它们的类别和位置。以下是对目标检测的详细阐述: 一、基本概念 目标检测的任务是解决“在哪里?是什么?”的问,即定位出图像目标的位置并识别出目标的类别。由于各类物体具有不同的外观、形状和姿态,加上成像时光照、遮挡等因素的干扰,目标检测一直是计算机视觉领域最具挑战性的任务之一。 二、核心问 目标检测涉及以下几个核心问: 分类问:判断图像的目标属于哪个类别。 定位问:确定目标在图像的具体位置。 大小问:目标可能具有不同的大小。 形状问:目标可能具有不同的形状。 三、算法分类 基于深度学习的目标检测算法主要分为两大类: Two-stage算法:先进行区域生成(Region Proposal),生成有可能包含待检物体的预选框(Region Proposal),再通过卷积神经网络进行样本分类。常见的Two-stage算法包括R-CNN、Fast R-CNN、Faster R-CNN等。 One-stage算法:不用生成区域提议,直接在网络提取特征来预测物体分类和位置。常见的One-stage算法包括YOLO系列(YOLOv1、YOLOv2、YOLOv3、YOLOv4、YOLOv5等)、SSD和RetinaNet等。 四、算法原理 以YOLO系列为例,YOLO将目标检测视为回归问,将输入图像一次性划分为多个区域,直接在输出层预测边界框和类别概率。YOLO采用卷积网络来提取特征,使用全连接层来得到预测值。其网络结构通常包含多个卷积层和全连接层,通过卷积层提取图像特征,通过全连接层输出预测结果。 五、应用领域 目标检测技术已经广泛应用于各个领域,为人们的生活带来了极大的便利。以下是一些主要的应用领域: 安全监控:在商场、银行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值