I . Beer Coasters 最小编辑距离

该博客主要讨论了一项关于测量矩形杯垫在酒吧环境中受啤酒杯底部湿润影响的磨损率的研究。研究涉及计算啤酒杯底与杯垫接触的面积,输入包括啤酒杯和杯垫的坐标及半径,输出为精确到小数点后四位的接触面积。博主分享了一个用于计算这种接触面积的计算机程序设计问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I . Beer Coasters
Description
Often, in an average pub, the beer is served in a mug which is, quite obviously, wet from inside, but also wet from outside. The barkeeper typically has no capacity to dry freshly washed mugs. To protect the table and the (optional!) tablecloth, beer coasters are used in most pubs. Originally, the beer coasters were round, nowadays you can find a variety of different shapes. Despite being perceived as slightly unorthodox, square and even rectangular coasters are manufactured and used daily in many self-respecting restaurants, taverns, beer houses and drinkeries of high and low profiles.

A research related to the well-known satiric Ig Nobel Prize is being conducted in local pubs. The research aims to measure the rate of wear of the rectangular coasters. The rate of wear depends also on how much a coaster is getting wet from the contact with the wet bottom of beer mugs. That, in turn, depends on the exact area of contact between the mug and the coaster. The exact position of the coaster and the mug on the table is recorded each time the mug is put on the coaster.

Many sophisticated calculations in the research take as input the area of contact, which has to be calculated by a suitable computer program. You are to write such a program.

Input
The input contains 7 space-separated integers on a single line. The first three integers X,Y,R describe the coordinates of the beer mug bottom on the table. The center of the mug bottom is at (X,Y) and the radius of the mug bottom is R. The next four integers Ax,Ay,Bx,By describe the coordinates of two opposite corners, (Ax,Ay) and (Bx,By), of the coaster on the table. The coaster is a rectangle placed with its sides parallel to the coordinate axes. All coordinates are in the range from −1 000 to 1 000, the radius is in the range from 1 to 1 000. The radius and the coordinates are expressed in the same units of length.

Output
Output a single decimal number with precision of 4 digits after the decimal point, the area of contact between the coaster and the beer mug.

Samples
Input 复制
-1 0 2 -1 -2 3 2
Output
6.2832
Source
CTU Open Contest 2019
//最小编辑距离
状态转移方程;dp[i][j](它表示第一个字符串的长度为i的子串到第二个字符串的长度为j的子串的编辑距离)。
具体csdn博客

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#pragma GCC optiize(2)
#define maxn 0x3f3f3f3f
int ans=0;
void chage(string &s)
{
    for(int i=0;i<s.size();i++)
    {
        if(s[i]>='0'&&s[i]<='9')
        {
            ans++;
            int t=s[i]-'0';
            s.erase(i,1);
            for(int j=1;j<=t;j++)
            {
                s.insert(i,"*");
            }
            if(!t)i--;//特例两个数字挨着第一个为零
        }

    }
}
int dp[20001][2001];
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    chage(s1);
    //cout<<s1<<endl;;
    chage(s2);
    //cout<<s2;
    int l1=s1.size();
    int l2=s2.size();
    s1="*"+s1;
    s2="*"+s2;
    for(int i=1;i<=l1;i++)dp[i][0]=i;
    for(int i=1;i<=l2;i++)dp[0][i]=i;
    for(int i=1;i<=l1;i++)
    {
        for(int j=1;j<=l2;j++)
        {
            dp[i][j]=min(dp[i-1][j]+1,dp[i][j-1]+1);
            if(s1[i]==s2[j]||s1[i]=='*'||s2[j]=='*')
                dp[i][j]=min(dp[i-1][j-1],dp[i][j]);//
        }
    }
    cout<<dp[l1][l2]+ans;
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值