1001. Estate

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

//your code will be here
class Land

{

public:

Land() : price_(0) {}

explicit Land(int price);

// calculate how much Feng Gor can earn from the land

virtual double CalMoney() = 0;

protected:

// price of unit area

int price_;

};

class Square : public Land

{

public:

Square(double len, int price);

double CalMoney();

private:

//length of side of a square

double len_;

};

class Circle : public Land

{

public:

Circle(double radius, int price);

double CalMoney();

private:

//length of radius of a circle

double radius_;

};

Circle::Circle(double radius, int price){
 radius_ = radius;
 price_ = price;
}
double Circle::CalMoney(){
 return acos(-1)*price_ * radius_ * radius_;
}
 
Square::Square(double len, int price){
 len_ = len;
 price_ = price;
}
 
double Square::CalMoney(){
 return len_ * len_ * price_;
}
 
 void  Accountant::DevelopEstate(Land* land){
 money_ += land->CalMoney();
}
 
double Accountant::CheckMoney(){
 return money_;
}

class Accountant

{

public:

Accountant() : money_(0) {}

// develop a land, earn the value of the land

void DevelopEstate(Land* land);

// return the value of money_

double CheckMoney();

private:

double money_;

};

int main(int argc, const char *argv[])

{

Accountant py;

Circle *a = new Circle(100, 10000);

Square *b = new Square(100, 50000);

py.DevelopEstate(a);

cout << setprecision(10) << py.CheckMoney() << endl;

py.DevelopEstate(b);

cout << setprecision(10) << py.CheckMoney() << endl;

return 0;

}

时间: 2024-08-10 05:53:28

1001. Estate的相关文章

POJ1228:Grandpa&#39;s Estate——题解

http://poj.org/problem?id=1228 题目大意:给一个凸包,问是否为稳定凸包. ———————————————————————— 稳定凸包的概念为:我任意添加一个点都不能使这个凸包得到扩充,这样的凸包为稳定凸包. 我们求完凸包后枚举边然后枚举有多少点在上面即可. (网上的程序真的大部分是错的……) #include<cstdio> #include<queue> #include<cctype> #include<cstring> #

paste 乙级 1001

1001. 害死人不偿命的(3n+1)猜想 (15) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业

1001 数组中和等于K的数对

1001 数组中和等于K的数对 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数K和一个无序数组A,A的元素为N个互不相同的整数,找出数组A中所有和等于K的数对.例如K = 8,数组A:{-1,6,5,3,4,2,9,0,8},所有和等于8的数对包括(-1,9),(0,8),(2,6),(3,5). Input 第1行:用空格隔开的2个数,K N,N为A数组的长度.(2 <= N <= 50000,-10^9 <= K <= 10^9)

杭电女生赛1001 1002 1003 1005 1008 hdu6023 6024 6025 6027 6030

代码先贴这里 #include "iostream" #include "string.h" #include "stack" #include "queue" #include "string" #include "vector" #include "set" #include "map" #include "algorithm&quo

POJ 1228 Grandpa&#39;s Estate [稳定凸包]

Grandpa's Estate Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13112   Accepted: 3697 Description Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one

BZOJ 1001 [BeiJing2006]狼抓兔子

题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 题意: ... 很容易想到求的是一个最小割=最大流. 之前一直用的刘汝佳的模板STL过题,很久没用过数组模拟了. 再次熟悉一下写法,first数组是索引数组,标记的结点的最后一条边,利用next数组找到上一条边. 1 #include <bits/stdc++.h> 2 3 using namespace std; 4 5 #define N 1100000 6 int n,m,

求最大边/最小边的比值最小的路径 codevs 1001 舒适的路线

codevs 1001 舒适的路线 2006年 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Z小镇是一个景色宜人的地方,吸引来自各地的观光客来此旅游观光.Z小镇附近共有N(1<N≤500)个景点(编号为1,2,3,…,N),这些景点被M(0<M≤5000)条道路连接着,所有道路都是双向的,两个景点之间可能有多条道路.也许是为了保护该地的旅游资源,Z小镇有个奇怪的规定,就是对于一条给定的公路Ri,任何在该公路上行驶的车

PAT (Basic Level) Practise 1001. 害死人不偿命的(3n+1)猜想

1001. 害死人不偿命的(3n+1)猜想 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 卡拉兹(Callatz)猜想: 对任何一个自然数n,如果它是偶数,那么把它砍掉一半:如果它是奇数,那么把(3n+1)砍掉一半.这样一直反复砍下去,最后一定在某一步得到n=1.卡拉兹在1950年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证

bzoj 1001: [BeiJing2006]狼抓兔子 平面图最小割

平面图跑最大流 可以转换为其对偶图跑最短路 一个环对应一个割  找到最小环(即最短路)极为所求,注意辅助边的建立 加入读入优化  不过时间还是一般  估计是dij写的不好   大神勿喷~~~ /************************************************************** Problem: 1001 User: 96655 Language: C++ Result: Accepted Time:1724 ms Memory:95120 kb ****