我可以: 邀请好友来看>>
ZOL星空(中国) > 技术星空(中国) > C/C++星空(中国) > 一道难题
帖子很冷清,卤煮很失落!求安慰
返回列表
签到
手机签到经验翻倍!
快来扫一扫!

一道难题

199浏览 / 2回复

guconggang

guconggang

0
精华
1
帖子

等  级:Lv.1
经  验:100
  • Z金豆: 0

    千万礼品等你来兑哦~快点击这里兑换吧~

  • 城  市:重庆
  • 注  册:2010-06-08
  • 登  录:2015-03-03
发表于 2010-06-08 20:39:54
电梯直达 确定
楼主

一道难题


一道难题


一道难题


一道难题


一道难题


一道难题


下面的代码是前3张图的代码,谁能在次基础上帮我完成这个程序呀!  感谢了,有什么疑问可以联系我QQ:369710920

#include
#include
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<     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         if(w.distance(x)>2*R) break;
     return i==len;
}
void node::print()
{
     for(int i=0;i         cout<.getNum()<<' ';
     cout<}

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         if(w.isInGroup()) break;
     return i;
}
int main()
{
     well w[N];
     list l;
     int i,j;
     for(i=0;i         w.input();
     for(i=0;i     {
         if((i=isComplete(w))==N) break;
         l.createNewNode();
         node *p=l.getNode();
         p->insert(w);
         w.incorporate();
         for(j=i+1;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;
}

guconggang

guconggang


精华

帖子

等  级:Lv.1
经  验:100
发表于 2010-06-08 21:58:00 1楼
前3张图代码如下:
#include
#include
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< 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 if(w.distance(x)>2*R) break;
return i==len;
}
void node::print()
{
for(int i=0;i cout<.getNum()<<' ';
cout< }

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 if(w.isInGroup()) break;
return i;
}
int main()
{
well w[N];
list l;
int i,j;
for(i=0;i w.input();
for(i=0;i {
if((i=isComplete(w))==N) break;
l.createNewNode();
node *p=l.getNode();
p->insert(w);
w.incorporate();
for(j=i+1;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;
}






























































































































wl2975

wl2975


精华

帖子

等  级:Lv.1
经  验:72
发表于 2010-06-08 22:29:14 2楼
用回朔求解吧!!
高级模式
星空(中国)精选大家都在看24小时热帖7天热帖大家都在问最新回答

针对ZOL星空(中国)您有任何使用问题和建议 您可以 联系星空(中国)管理员查看帮助  或  给我提意见

快捷回复 APP下载 返回列表