C. Three displays

codeforces地址:http://codeforces.com/contest/987/problem/C

从中间暴力

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 3005;
const int inf = 0x3f3f3f3f;
LL a[N];
LL b[N];
LL c[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n;++i)
        scanf("%lld",&a[i]);
    for(int i = 0;i < n;++i)
        scanf("%lld",&b[i]);
    for(int i = 0;i < n;++i)
    {
        LL Min = inf;
        for(int j = 0;j < i;++j)
        {
            if(a[j] < a[i])
                Min = min(Min,b[i] + b[j]);
        }
        c[i] = Min;
    }
    LL ans = inf;
    for(int i = 0;i < n;++i)
    {
        LL Min = inf;
        for(int j = i + 1;j < n;++j)
        {
            if(a[i] < a[j]){
                Min = min(Min,c[i] + b[j]);
            }
        }
        ans = min(ans,Min);
    }
    if(ans == inf){
        printf("-1\n");
    }
    else{
        printf("%lld\n",ans);
    }
    return 0;
}
1、Experiment purpose (1)Write the txt file. (2)Class definition. (3)Function application. (4)Selections. (5)Loops 2、Experiment task Project 1: Define the Rectangle2D class that contains: Two double data fields named x and y that specify the center of the rectangle with constant get functions and set functions. (Assume that the rectangle sides are parallel to x- or y-axes.) The double data fields width and height with constant get functions and set functions. A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height. A constructor that creates a rectangle with the specified x, y, width, and height. A constant function getArea() that returns the area of the rectangle. A constant function getPerimeter() that returns the perimeter of the rectangle. A constant function contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle. See Figure a. A constant function contains(const Rectangle2D &r) that returns true if the specified rectangle is inside this rectangle. See Figure b. A constant function overlaps(const Rectangle2D &r) that returns true if the specified rectangle overlaps with this rectangle. See Figure c. Draw the UML for the class. Implement the class. Write a test program that creates three Rectangle2D objects r1(2, 2, 5.5, 4.9), r2(4, 5, 10.5, 3.2)), and r3(3, 5, 2.3, 5.4), and displays r1’s area and perimeter, and displays the result of r1.contains(3, 3), r1.contains(r2), and r1.overlaps(r3). And save all these results in the txt file that is called Result.txt.写一段c++代码
06-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值