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;
}