B - Light Bulb

Compared to wildleopard's wealthiness, his brother mildleopard is rather poor. His house is narrow and he has only one light bulb in his house. Every night, he is wandering in his incommodious house, thinking of how to earn more money. One day, he found that the length of his shadow was changing from time to time while walking between the light bulb and the wall of his house. A sudden thought ran through his mind and he wanted to know the maximum length of his shadow.

Input

The first line of the input contains an integer T (T <= 100), indicating the number of cases.

Each test case contains three real numbers H, h and D in one line.H is the height of the light bulb while h is the height of mildleopard.D is distance between the light bulb and the wall. All numbers are in range from 10-2 to 103, both inclusive, andH - h >= 10-2.

<b< dd="">

Output

For each test case, output the maximum length of mildleopard's shadow in one line, accurate up to three decimal places..

<b< dd="">

Sample Input

3
2 1 0.5
2 0.5 3
4 3 4

<b< dd="">

Sample Output

1.000
0.750
4.000 
火柴人从灯泡下向D前进,影子开始会慢慢变长,而当影子的落点到达D时,如果继续向D前进,影子也许会继续变长,也许会变短,所以火柴人前进的距离与影子的长度的函数是个开口向下的凸函数(当有凹凸时可以试试三分),因此比较适合三分法
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{

    int T;
    //freopen("1.txt","r",stdin);
    scanf("%d",&T);
    while (T--)
    {
        double H,h,D,t1,t2,l,r,mid,midd;
        scanf("%lf%lf%lf",&H,&h,&D);
        l=(H - h) * D / H,r=D;
        while(r-l>=1e-8)
        {
            mid=(r+l)/2,midd=(mid+r)/2;
            t1=D - mid + H - (H - h) * D / mid;
            t2=D - midd + H - (H - h) * D / midd;

            if(t1<t2)l=mid;
            else r=midd;
        }
        printf("%.3lf\n",t2);
    }
    return 0;
}

The ICPC world finals will be held in a luxurious hotel with a big ballroom. A buffet meal will be served in this ballroom, and organizers decided to decorate its walls with pictures of past champion teams. In order to avoid criticism about favouring some of those teams over others, the organizing commitee wants to make sure that all pictures are appropiately illuminated. The only direct way they’ve found for doing this is ensuring each picture has at least one lightbulb that directly illuminates it. In this way, the perimeter of the ballroom wall can be divided into illuminated parts (in which pictures may be placed) and dark parts (which are not suitable for placing the pictures). The ballroom has the shape of a box and contains several lightbulbs. Each lightbulb emits light in all directions, but this light can be blocked by columns. All columns in the ballroom have cylindrical shape and go from the floor to the ceiling, so light cannot pass over or above them. Columns are of course placed so that its circular section is parallel to the ballroom floor. Any given point p on the perimeter wall is said to be illuminated if there exists a line segment (a light ray) which starts on a lightbulb, ends in p and does not touch or pass through any column. Your task as a helper of the ICPC organization is to examine the blueprints of the ballroom and determine the total length of illuminated sections of the perimeter wall. The blueprint consist of a rectangle indicating a top view of the ballroom, with the lightbulbs and columns marked in it. 输入 Each test case will consist on several lines. The first line will contain four integers: L, the number of lightbulbs, C, the number of columns, X, the size of the ballroom on the x coordinate and Y , the size of the ballroom on the y coordinate. The lower-left corner of the ballroom is at (0, 0) while the upper-right corner is at (X, Y ). The next L lines will contain two integers each representing the x and y coordinate of each lightbulb. The last C lines of the test case will contain three integers each, representing the x and y coordinates of the center of a column and its radius, in that order. You can assume that 1 <= L,C <= 103 and 4 <= X, Y <= 106. Also, for all pairs of coordinates (x,y), 0 < x < X and 0 < y < Y , both for lightbulbs and column center locations. All radii of the columns will be positive. Finally, no two columns will overlap, although they may touch, and no column will touch or intersect with the border of the ballroom. No lightbulb will be inside a column or in its boundary and no two lightbulbs will be in the same place. Input is terminated with L = C = X = Y = 0. 输出 For each test case, output a single line with the total length of the illuminated parts of the perimeter wall. The result must be printed as a real number with exactly four decimal figures, with the lowest-order decimal figure rounded up. 样例输入 2 1 8 8 6 6 2 6 4 4 2 1 4 7 7 3 3 2 4 1 4 2 1 2 2 1 4 4 1 2 2 9 7 1 2 5 5 3 3 2 7 5 1 0 0 0 0 ⧉ 样例输出 28.0000 0.0000 25.8214 ⧉ 题目来源 用巧思
11-01
<template> <view class="home-page"> <!-- 顶部导航栏 --> <view class="header"> <view class="header-content"> <view class="header-left"> <text class="header-title">智家控制中心</text> <text class="header-subtitle">8台设备在线</text> </view> <view class="header-right"> <button class="icon-btn"> <text class="fa fa-search"></text> </button> <button class="icon-btn"> <text class="fa fa-bell"></text> </button> <image src="https://picsum.photos/seed/user/40/40" class="avatar"></image> </view> </view> </view> <!-- 主内容区 --> <view class="main-content"> <!-- 房间切换 --> <div class="NeiRong1"> <!-- 使用v-for循环生成房间选择按钮(实际代码中使用了静态写法) --> <button :class="{active: activeRoom === '全部房间'}" @click="activeRoom = '全部房间'" >全部房间</button> <button :class="{active: activeRoom === '客厅'}" @click="activeRoom = '客厅'">客厅</button> <button :class="{active: activeRoom === '主卧'}" @click="activeRoom = '主卧'">主卧</button> <button :class="{active: activeRoom === '次卧'}" @click="activeRoom = '次卧'">次卧</button> <button :class="{active: activeRoom === '厨房'}" @click="activeRoom = '厨房'">厨房</button> <button :class="{active: activeRoom === '卫生间'}" @click="activeRoom = '卫生间'">卫生间</button> <button :class="{active: activeRoom === '阳台'}" @click="activeRoom = '阳台'">阳台</button> </div> <!-- 常用设备 --> <view class="section"> <view class="section-header"> <text class="section-title">常用设备</text> <text class="section-more" @click="navigateTo('/pages/devices/devices')">查看全部</text> </view> <view class="devices-grid"> <!-- 灯光 --> <view class="device-card"> <view class="card-header"> <view class="device-icon light"> <text class="fa fa-lightbulb-o"></text> </view> <switch :checked="devices.light" @change="toggleDevice('light')" color="#007AFF"/> </view> <text class="device-name">客厅主灯</text> <text class="device-status">亮度 {{devices.lightBrightness}}%</text> <slider :value="devices.lightBrightness" min="0" max="100" @change="changeLightBrightness" activeColor="#007AFF"/> </view> <!-- 空调 --> <view class="device-card"> <view class="card-header"> <view class="device-icon ac"> <text class="fa fa-snowflake-o"></text> </view> <switch :checked="devices.ac" @change="toggleDevice('ac')" color="#007AFF"/> </view> <text class="device-name">客厅空调</text> <text class="device-status">制冷 · {{devices.acTemp}}°C</text> <view class="temp-control"> <button class="temp-btn" @click="changeTemp(-1)">-</button> <text class="temp-value">{{devices.acTemp}}°</text> <button class="temp-btn" @click="changeTemp(1)">+</button> </view> </view> </view> </view> <!-- 场景模式 --> <view class="section"> <view class="section-header"> <text class="section-title">场景模式</text> <text class="section-more" @click="navigateTo('/pages/scenes/scenes')">编辑场景</text> </view> <view class="scenes-grid"> <view class="scene-btn home" @click="activateScene('home')"> <view class="scene-icon"> <text class="fa fa-home"></text> </view> <text class="scene-name">回家模式</text> </view> <view class="scene-btn cinema" @click="activateScene('cinema')"> <view class="scene-icon"> <text class="fa fa-film"></text> </view> <text class="scene-name">影院模式</text> </view> </view> </view> </view> </view> </template> <script> export default { data() { return { devices: { light: true, lightBrightness: 70, ac: true, acTemp: 24 }, activeRoom: '全部房间' // 默认激活的房间 } }, methods: { navigateTo(url) { uni.navigateTo({ url }) }, toggleDevice(device) { this.devices[device] = !this.devices[device] uni.showToast({ title: `${device === 'light' ? '灯光' : '空调'}已${this.devices[device] ? '打开' : '关闭'}`, icon: 'none' }) }, changeLightBrightness(e) { this.devices.lightBrightness = e.detail.value }, changeTemp(delta) { const newTemp = this.devices.acTemp + delta if (newTemp >= 16 && newTemp <= 30) { this.devices.acTemp = newTemp } }, activateScene(scene) { const sceneNames = { 'home': '回家模式', 'cinema': '影院模式' } uni.showToast({ title: `${sceneNames[scene]}已激活`, icon: 'success' }) } } } </script> <style scoped> .home-page { background-color: #f8fafc; min-height: 100vh; } /* 头部样式 */ .header { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.1); position: fixed; top: 0; left: 0; right: 0; z-index: 100; } .header-content { padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; } .header-left { display: flex; flex-direction: column; } .header-title { font-size: 18px; font-weight: bold; color: #1e293b; } .header-subtitle { font-size: 12px; color: #6b7280; } .header-right { display: flex; align-items: center; gap: 12px; } .icon-btn { width: 34px; height: 34px; border-radius: 50%; background: #f3f4f6; display: flex; align-items: center; justify-content: center; border: none; } .icon-btn text { color: #6b7280; font-size: 14px; } .avatar { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #007AFF; } /* 主内容区 */ .main-content { padding-top: 80px; padding-bottom: 100px; } /* 房间标签 */ .NeiRong1 { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; overflow-x: auto; padding: 10px 20px; background-color: #f5f5f5; } .NeiRong1::-webkit-scrollbar { display: none; /* Chrome, Safari and Opera */ } .NeiRong1 { -ms-overflow-style: none; /* IE and Edge */ scrollbar-width: none; /* Firefox */ } .NeiRong1 button { flex-shrink: 0; min-width: 80px; height: 30px; padding: 0 12px; font-size: 12px; border: none; border-radius: 30px; cursor: pointer; background-color: #007BFF; color: white; transition: background-color 0.3s ease; } .NeiRong1 button:hover { background-color: #0056b3; } .NeiRong1 button.active { background-color: #0056b3; box-shadow: 0 0 0 2px white, 0 0 0 4px #0056b3; } /* 分区样式 */ .section { padding: 0 16px; margin-bottom: 24px; } .section-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; } .section-title { font-size: 18px; font-weight: bold; color: #1e293b; } .section-more { font-size: 14px; color: #007AFF; } /* 设备网格 */ .devices-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .device-card { background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 2px 8px rgba(0,0,0,0.1); } .card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; } .device-icon { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; } .device-icon.light { background: #dbeafe; } .device-icon.light text { color: #007AFF; } .device-icon.ac { background: #dcfce7; } .device-icon.ac text { color: #34C759; } .device-name { font-size: 16px; font-weight: 500; color: #1e293b; display: block; } .device-status { font-size: 12px; color: #6b7280; display: block; margin-bottom: 8px; } .temp-control { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; } .temp-btn { width: 28px; height: 28px; border-radius: 50%; background: #f3f4f6; display: flex; align-items: center; justify-content: center; border: none; font-size: 12px; } .temp-value { font-size: 16px; font-weight: 500; } /* 场景网格 */ .scenes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .scene-btn { background: #fff; border-radius: 12px; padding: 20px 12px; display: flex; flex-direction: column; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.1); } .scene-btn.home { background: linear-gradient(135deg, #eff6ff, #dbeafe); } .scene-btn.cinema { background: linear-gradient(135deg, #faf5ff, #f3e8ff); } .scene-icon { width: 48px; height: 48px; border-radius: 50%; background: rgba(255,255,255,0.7); display: flex; align-items: center; justify-content: center; margin-bottom: 8px; } .scene-btn.home .scene-icon text { color: #007AFF; } .scene-btn.cinema .scene-icon text { color: #8b5cf6; } .scene-name { font-size: 14px; font-weight: 500; color: #1e293b; } </style> 我希望只有点击全部房间按钮的时候,下方常用设备和场景模式内容才会显示
最新发布
11-25
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值