一道难题
以下的代码是前3张图片的代码,有没有哪位能人帮我把程序写完。有什么疑问的可以联系我QQ:369710920
程序代码:
#include <iostream> #include <cmath> using namespace std; #define N 8 #define R 0.2 #define maxSize 6 class list; class well { private: double x,y; int num; bool b; public: well():b(true){} ~well(){} void input(){cin>>num>>x>>y;} void output(){cout<<num<<' ';} void incorporate(){b=false;} int getNum(){return num;} double getX(){return x;} double getY(){return y;} double distance(well &a){return sqrt(pow((x-a.getX()),2.0)+pow((y-a.getY()),2.0));} bool isInGroup(){return b;} }; class node { friend list; private: well w[N]; int len; node *next; public: node():len(0),next(NULL){} ~node(){} void print(); void insert(well &x){w[len++]=x;} bool judge(well&); bool isFull(){return len==maxSize;} }; bool node::judge(well &x) { int i; for(i=0;i<len;i++) if(w[i].distance(x)>2*R) break; return i==len; } void node::print() { for(int i=0;i<len;i++) cout<<w[i].getNum()<<' '; cout<<endl; } class list { private: node *head,*last; public: list(){head=new node;last=head;} ~list(); node *getNode(){return last;} int createNewNode(); void print(); }; int list::createNewNode() { node *p=new node; if(p==NULL) return 0; last->next=p; last=p; return 1; } void list::print() { node *p=head->next; while(p!=NULL) { p->print(); p=p->next; } } list::~list() { node *p=head->next; while(p!=NULL) { head->next=p->next; delete p; p=head->next; } delete head; } int isComplete(well *w) { int i; for(i=0;i<N;i++) if(w[i].isInGroup()) break; return i; } int main() { well w[N]; list l; int i,j; for(i=0;i<N;i++) w[i].input(); for(i=0;i<N;i++) { if((i=isComplete(w))==N) break; l.createNewNode(); node *p=l.getNode(); p->insert(w[i]); w[i].incorporate(); for(j=i+1;j<N;j++) { if(p->isFull()) break; while(!w[j].isInGroup()) j++; if(p->judge(w[j])) { p->insert(w[j]); w[j].incorporate(); } } } l.print(); return 0; }