您的位置:首页 > 其它

POJ1005 I Think I Need a Houseboat

2017-01-20 18:20 417 查看
所拥有的土地以圆的形式扩张,第一个输入是节点个数。

同时又是连续输入,连续输出的情况,再次用到链表。

没有考虑到面积的增大是半圆,并不是精度带来的问题。

关键公式就是1/2∗π∗r2=50∗n

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

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  链表 acm