Problem E: 数量的类模板

Problem E: 数量的类模板

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 2047   Solved: 1444
[ Submit][ Status][ Web Board]

Description

定义一个类模板Data,用于包装C++中的基本数据类型int和double。它包括:

1. 数据成员value为该对象所包装的值。

2. 无参构造函数(初始化value为0)和带参构造函数。

3. 重载的运算符:>、<、+以及<<。其中"+"返回和,不改变两个操作数的值。

4. 成员函数setValue用于设置value的值。

定义另一个类模板GetResult,它只有3个静态成员函数(以下“T"为类型参数):

1. static Data<T> getSum(Data<T> *arr, int num):求存储在arr中的num个Data对象的和,并返回由这个和构成的一个Data对象。

2. static Data<T> getMax(Data<T> *arr, int num):求存储在arr中的num个Data对象的最大值,并返回这个最大值对应的对象。

3.  static Data<T> getMin(Data<T> *arr, int num):求存储在arr中的num个Data对象的最小值,并返回这个最小值对应的对象。

Input

输入分多行。

第一行M>0表示有M个测试用例。

只有的M行,每行开始有一个字母i或d,第二个是正整数N>0。如果第一个字母是i,则表示本行包括N个int类型的数据;如果第一个字母为d,则表示本行有N个double类型的数据。

Output

除前6行输出外,其他输出的行数等于M。其中每一行输出3个数据:对应测试用例的最大值、最小值以及和。实数输出定点小数,且只输出2位小数。

Sample Input

3i 3 1 2 3d 3 1.1 2.2 3.3i 1 10

Sample Output

a + b = 30max(a, b) = 20min(a, b) = 10c + d = -0.96max(c, d) = 3.14min(c, d) = -4.103 1 63.30 1.10 6.6010 10 10

HINT

Append Code

[ Submit][ Status][ Web Board]
#include <bits/stdc++.h>
using namespace std;
template < typename T>
class Data {
private :
     T value;
public :
     Data() : value(0) {}
     Data(T t) : value(t) {}
     bool operator > ( const Data<T> d) {
         return value > d.value;
     }
     bool operator < ( const Data<T> d) {
         return value < d.value;
     }
     T operator + ( const Data<T> d) {
         return value + d.value;
     }
     friend ostream& operator<<(ostream &output, const Data<T> d) {
         output << setprecision(2) << setiosflags(ios::fixed) << d.value;
         return output;
     }
     void setValue(T t) {
         value = t;
     }
     T getValue() { return value; }
};
 
template < typename T>
class GetResult {
public :
     static Data<T> getSum(Data<T> *arr, int num) {
         Data<T> d(0);
         for ( int i = 0; i < num; i++) {
             d.setValue(d.getValue() + arr[i].getValue());
         }
 
         return d;
     }
     static Data<T> getMax(Data<T> *arr, int num) {
         T t = arr[0].getValue();
         for ( int i = 0; i < num; i++) {
             t = max(t, arr[i].getValue());
         }
         Data<T> d(t);
         return d;
     }
     static Data<T> getMin(Data<T> *arr, int num) {
         T t = arr[0].getValue();
         for ( int i = 0; i < num; i++) {
             t = min(t, arr[i].getValue());
         }
         Data<T> d(t);
         return d;
     }
};
int main()
{
     Data< int > iData[1001];
     Data< double > dData[1001];
     int cases, num;
     char ch;
     int u;
     double v;
     Data< int > a(10), b(20);
     Data< double > c(3.14), d(-4.1);
     cout<< "a + b = " <<(a + b)<<endl;
     cout<< "max(a, b) = " <<(a > b ? a : b)<<endl;
     cout<< "min(a, b) = " <<(a < b ? a : b)<<endl;
     cout<< "c + d = " <<(c + d)<<endl;
     cout<< "max(c, d) = " <<(c > d ? c : d)<<endl;
     cout<< "min(c, d) = " <<(c < d ? c : d)<<endl;
     cin>>cases;
     for ( int i = 0; i < cases; i++)
     {
         cin>>ch;
         cin>>num;
         for ( int j = 0; j < num; j++)
         {
             if (ch == 'i' )
             {
                 cin>>u;
                 iData[j].setValue(u);
             }
             else if (ch == 'd' )
             {
                 cin>>v;
                 dData[j].setValue(v);
             }
         }
         if (ch == 'i' )
         {
             cout<<GetResult< int >::getMax(iData, num);
             cout<< " " <<GetResult< int >::getMin(iData, num);
             cout<< " " <<GetResult< int >::getSum(iData, num)<<endl;
         }
         else if (ch == 'd' )
         {
             cout<<GetResult< double >::getMax(dData, num);
             cout<< " " <<GetResult< double >::getMin(dData, num);
             cout<< " " <<GetResult< double >::getSum(dData, num)<<endl;
         }
     }
     return 0;
}
Abstract: Lane detection is an important foundation in the development of intelligent vehicles. To address problems such as low detection accuracy of traditional methods and poor real-time performance of deep learning-based methodologies, a lane detection algorithm for intelligent vehicles in complex road conditions and dynamic environments was proposed. Firstly, converting the distorted image and using the superposition threshold algorithm for edge detection, an aerial view of the lane was obtained via region of interest extraction and inverse perspective transformation. Secondly, the random sample consensus algorithm was adopted to fit the curves of lane lines based on the third-order B-spline curve model, and fitting evaluation and curvature radius calculation were then carried out on the curve. Lastly, by using the road driving video under complex road conditions and the Tusimple dataset, simulation test experiments for lane detection algorithm were performed. The experimental results show that the average detection accuracy based on road driving video reached 98.49%, and the average processing time reached 21.5 ms. The average detection accuracy based on the Tusimple dataset reached 98.42%, and the average processing time reached 22.2 ms. Compared with traditional methods and deep learning-based methodologies, this lane detection algorithm had excellent accuracy and real-time performance, a high detection efficiency and a strong anti-interference ability. The accurate recognition rate and average processing time were significantly improved. The proposed algorithm is crucial in promoting the technological level of intelligent vehicle driving assistance and conducive to the further improvement of the driving safety of intelligent vehicles.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值