The largest sub-array of the Unicom version

Source: Internet
Author: User

The basic function of this program is: input array of the number of rows and columns, the program automatically generate corresponding specifications of the array, in the case of connectivity, to find the largest sub-array.

The implementation of the main function is dependent on the traversal of the graph.

Team member: Wang Shuo http://home.cnblogs.com/u/WS1004/
#include <fstream>#include<iostream>#include<ctime>using namespacestd;#defineRAND16 (rand () <<1) + (rand () &1))#defineN 100# define WIDE4294967296typedefstruct{    Long Long intDian[n]; Long Long intXian[n][n]; Long Long intDianx, Xianx;} A;void Set(A &shu,intXinty) {Shu.dianx= x*y;    Srand ((_int32) time (NULL));  for(inti =1; I <= Shu.dianx; i++) {Shu.dian[i]= (RAND16 << -) +RAND16; if(rand ()%2==1) Shu.dian[i]= Shu.dian[i] * (-1); }     for(inti =1; I <= Shu.dianx; i + =y) { for(intj = i; J <= i + Y-2; J + +) {shu.xian[j][j+1] =1; Shu.xian[j+1][J] =1; }    }     for(inti =1+ y; i<shu.dianx; i + =y) { for(intj = i; J <= i + X-1; J + +) {shu.xian[j][j-Y] =1; Shu.xian[j-Y][J] =1; }    }}voidBianli (A &shu,Long Long intVLong Long intVisit[],Long Long int&b,Long Long int&max,Long Long intx) {Visit[v]=1; Max+=Shu.dian[v]; if(Max >=b) B=Max; intA =0, Bo =0;  for(intW =1; W <= Shu.dianx; w++)    {         for(intc =1; C <= Shu.dianx; C++)        {            if((visit[w] = =0) && (shu.xian[c][w] = =1) && (visit[c] = =1) ) {a= W; Bo =1; Break; }        }        if(Bo = =1)             Break; }     for(intW =1; W <= Shu.dianx; w++)    {         for(intc =1; C <= Shu.dianx; C++)        {            if((visit[w] = =0) && (shu.xian[c][w] = =1) && (visit[c] = =1))            {                if(shu.dian[a]<Shu.dian[w]) a=W; }        }    }    if(b + shu.dian[a]<0) {Shu.xian[v][a]=0; }    ElseBianli (Shu, a, visit, B, max, x);}intNovisit (Long Long intvisit[], A Shu) {    intK =0, I;  for(i =1; I <= Shu.dianx; i++)    {        if(Visit[i] = =0) {k=i;  Break; }    }    returnK;}intMain () {cout<<"Please enter the number of array rows:"<<Endl; intx, y; CIN>> x >>y;    A Shu; Set(Shu, x, y); Ofstream Fout ("D:\\input.txt", ios::binary);  for(inti =1; I <= Shu.dianx; i++) {Fout<<Shu.dian[i]; if(Shu.xian[i][i +1] ==1) Fout<<"   "; ElseFout<<"\ r \ n"; }    Long Long intv =1, b[n] = {0}, H =0;  for(inti =1; I <= Shu.dianx; i++)    {        if(shu.dian[i]<0) {B[i]=Shu.dian[i]; }        Else        {            Long Long intVisit[n] = {0 }; Long Long intMax =0;        Bianli (Shu, I, visit, B[i], Max, x); }    }    Long Long intmax = b[1];  for(inti =2; I <= Shu.dianx; i++)    {        if(b[i]>max) Max=B[i]; } fout<<"the same as the maximum number of interconnected sub-arrays:"<< Max <<Endl;}

Summarize:

There are some problems in this programming, the output in the file can not be changed, after the Internet learned to change the Endl \ r \ n.

This programming has two times the foundation of the programming, the thought of the difficult easy to play a very big role.

The largest sub-array of the Unicom version

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.