l2-007. Home Real Estate C + + version answer

Source: Internet
Author: User

Given everyone's family members and their own property, ask you to count the number of people in each family, the per capita housing area and the real estate.

Input format:

Enter the first line to give a positive integer n (<=1000), followed by n rows, and each line gives a person's property in the following format:

Number parents K Child 1 ... The total area of the child K property

Where the number is a unique 4-digit number for each person, and the parent is the number of that person's parent (if it has passed, show -1);k(0<=k <=5) is the number of children of that person, and child I is the number of his or her child.

Output format:

First output the number of families in the first row (all relatives belong to the same family). The information for each family is then exported in the following format:

Minimum number of family members household population per capita housing area per capita

Where the per capita value requires the retention of 3 digits after the decimal point. Family information is first output in descending order of per capita area, and if there is a juxtaposition, it is output by member number ascending.

Input Sample:

106666 5551 5552 1 7777 1 1001234 5678 9012 1 0002 2 3008888-1-1 0 1 10002468 0001 0004 1 2222 1 5007777 6666-1 0 2 300 3721-1-1 1 2333 2 1509012-1-1 3 1236 1235 1234 1 1001235 5678 9012 0 1 502222 1236 2468 2 6661 6662 1 3002333-1 3721 3 6661 6662 6663 1 100

Sample output:

38888 1 1.000 1000.0000001 15 0.600 100.0005551 4 0.750 100.000

#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace Std;
struct QQ
{
Vector<int> family;

int num;

int area;

BOOL Flag;

QQ ()
{
num=0;

area=0;

flag=0;
}

};

struct WW
{
int id;

int area;

int HN;

int num;
};

BOOL Gg (WW A,WW b)
{
Double q= (double) a.area/(double) a.hn;

Double w= (double) b.area/(double) b.hn;

if (q>w) return true;

else if (q<w) return false;

Return a.id<b.id;
}


Class ZZ
{
Private

QQ a[10000];

WW b[10000];

Vector<int> C;

Public

ZZ ()
{
int n,i;

cin>>n;

while (n--)
{
int q,k;

cin>>q;

A[q].flag=false;

C.push_back (q);

for (i=0;i<2;i++)
{
cin>>k;

A[q].family.push_back (k);

if (k!=-1) a[k].family.push_back (q);

}

cin>>k;

int e;

while (k--)
{
cin>>e;

A[q].family.push_back (e);

if (e!=-1) a[e].family.push_back (q);
}

cin>>a[q].num>>a[q].area;
}
}


void Dfs (int q,int j)
{

if (a[q].flag==true) return;

A[q].flag=true;

if (q==-1) return;

b[j].hn++;

int i;

if (b[j].id>q) b[j].id=q;

B[j].num+=a[q].num;

B[j].area+=a[q].area;

For (I=0;i<a[q].family.size (); i++)

{
if (a[q].family[i]!=-1)
{
DFS (A[Q].FAMILY[I],J);
}
}
}

void Dfs1 ()
{

for (int i=0;i<c.size (); i++)
{
b[i].num=0;

b[i].area=0;

b[i].hn=0;

b[i].id=10000;

DFS (c[i],i);


}
}

void Dis ()
{

Sort (b,b+c.size (), GG);

int sum=0;

for (int j=0;j<c.size (); j + +)
{
if (b[j].hn!=0) sum++;

else break;
}

cout<<sum<<endl;


for (int i=0;i<sum;i++)
{
if (b[i].hn!=0)
{
int K=b[i].hn;

int w=b[i].id;

if (w<10) cout<< "<<w;"

else if (w<100) cout<< "XX" <<w;

else if (w<1000) cout<< "0" <<w;

else cout<<w;

cout<< "" <<k<< "<<fixed<<setprecision (3) << (double) b[i].num/(double) k< < "" << (Double) b[i].area/(double) k<<endl;
}

}
}

};

int main ()
{

ZZ ZX;

ZX.DFS1 ();

Zx.dis ();


return 0;
}

l2-007. Home Real Estate C + + version answer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.