POJ1005 I Think I Need a Houseboat

所拥有的土地以圆的形式扩张,第一个输入是节点个数。
同时又是连续输入,连续输出的情况,再次用到链表。
没有考虑到面积的增大是半圆,并不是精度带来的问题。
关键公式就是 1/2πr2=50n

后面在测试代码的时候,发现,自己所采用的的方案,比较会带来误差。

       double x = current->x,y = current->y;
        int area_order = 1;
        double r_square = area_order*100/3.1415926;
        for(;r_square < x*x+y*y;area_order++)
        {
            r_square = area_order*100/3.1415926;
            cout<<r_square<<endl;
        }

连续输出版本,好几次ac不了在于最后一个句号漏了,可见解题要细心。
不连续输出只需要稍作改动。

#include <iostream>
#include <cmath>
using namespace std;
struct Node
{
    public:
    double x;
    double y;
    Node* next;
};

class List
{
    Node*head;
    Node* tail;
    int num;
    public:
    //默认构造函数
    List(){head = NULL;num = 0;}
    void pushList(double a,double b);//链表结点的插入
    void outputList();//链表结点的输出

};

void List::pushList(double a,double b)
{
    if(head == NULL)
    {
        head=(Node*)new Node;
        head->x = a;
        head->y = b;
        head->next = NULL;
        tail=head;
        num++;
    }
    else
    {

        Node* s=(Node*)new Node;
        s->x = a;
        s->y = b;
        s->next = NULL;
        tail->next = s;
        tail = s;
        num++;
    }

}
void List::outputList()
{
    Node* current = head;
    for(int seq = 1;current!=NULL;seq++)
    {
        double x = current->x,y = current->y;
        cout<<"Property "<<seq<<": This property will begin eroding in year "<<ceil(3.1415926*(x*x+y*y)/100.0)<<"."<<endl;
        current=current->next;
    }
}
int main()
{
    int m = 0;
    List mlist;
    cin>>m;
    while(m>0)
    {
        m--;
        double a,b;
        cin>>a>>b;
        mlist.pushList(a,b);
    }
    mlist.outputList();
    cout<<"END OF OUTPUT."<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值