Beispiel #1
0
/* 
 * ===  FUNCTION  ======================================================================
 *         Name:  main
 *  Description:  
 * =====================================================================================
 */
    int
main ()
{
    int i,n,m,j;
    int idNum,idMax;
    int num[2000][5]={(0,0,0,0,0)};
    int numLook[2000]={0};
    int numOrder[4];
    char ch[5] = "ACME";
    scanf ( "%d %d", &n, &m );
    
    for ( i = 0; i < n; i += 1 ) {
        scanf ( "%d %d %d %d", num[i], num[i]+2, num[i]+3, num[i]+4 );
        num[i][1] = (num[i][4]+num[i][2]+num[i][3])/3;
    }

    for ( i = 0; i < m; i += 1 ) {
        scanf ( "%d", &numLook[i] );
        idNum = findId(num,numLook[i], n);
        if(idNum == -1)
            printf ( "N/A\n" );
        else
        {
            
            for ( j = 1; j < 5; j += 1 ) {
                numOrder[j-1] = calOrder(num,idNum, j, n);
            }
            idMax = calMax(numOrder);
           printf ( "%d %c\n",numOrder[idMax], ch[idMax] );
        }

    }
    return EXIT_SUCCESS;
}				/* ----------  end of function main  ----------*/
Beispiel #2
0
void* VerCover_APPROX1(void* arg) 
{
	MGraph* G = (MGraph*) arg; 
	
	int VerticeNum,EdgeNum,i,j,m,maxNode;
	int vNum;
	//MGraph G;	
	VerticeNum = G -> numVertexes;  
	EdgeNum = G -> numEdges;
	
	/*a_1d is to store the time that one node appear in an edge*/
	int *a_1d = (int*)malloc(sizeof(int)*VerticeNum);
	for(i=0;i<VerticeNum;i++)
	{
		a_1d[i] = 0;
	}
	/*a_2d is to store whether a node is selected as a vertex*/
	int *a_2d = (int*)malloc(sizeof(int)*VerticeNum);
	for(i=0;i<VerticeNum;i++)
	{
		a_2d[i] = 0;
	}


	m = 1;
	while(m!=0){
		/*calulating the vertex of the highest degree*/
		m = 0;
		
		for(i=0;i< VerticeNum-1;i++) 
		{
			if (a_2d[i] == 1)
			{
				continue;
			}
			else
			{	
				for(j=i+1;j< VerticeNum;j++)
				{
					if (a_2d[j] == 1)
					{
						continue;
					}
					else
					{		
						if (G->arc[i][j]==1)
						{
							a_1d[i] = a_1d[i]+1;					
							a_1d[j] = a_1d[j]+1;
							m++;			
						}
					}
				}
			}
		}
		maxNode=calMax(VerticeNum, a_1d); //calculate which node is of the highest degree
		a_2d[maxNode] = 1;

	}

	/*to print out the vertexes*/
	printf("APPROX-VC-1: ");
	vNum = 0;
	for (i = 0; i < VerticeNum; i++)
	{
		if(a_2d[i]==1)
		{
			if(vNum == 0)
				printf("%d",i);
			else
				printf(",%d",i);
			vNum = vNum + 1;
		}	
	}
	printf("\n");
	fflush(stdout);

	free(a_1d);
	a_1d = NULL;
	
	free(a_2d);
	a_2d = NULL;

	return NULL;
}
int main ( int argc, char *argv[] )
{

    int T;
    scanf("%d",&T);


    while(T-- > 0)
    {
        int p,c;
        scanf("%d %d",&p,&c);
        int i=0;
        int j=0;
        PlayerSc PS[p]; //Declaring array of structure of p palyers
        while(i<p)
        {
            PS[i].max=0;
            scanf("%s",PS[i].name);
            j=0;
            for(j=0; j<c; j++)
                scanf("%d %d",&PS[i].scP[j][0],&PS[i].scP[j][1]);
            i++;

        }

//								display(PS,p,c);
        int unknown=-1;
        for(j=0; j<c; j++) {
            char str1[10];
            char str2[10];
            scanf("%s %s",str1,str2);
            int ret=calMax(PS,p,c,str1,str2,j);
            if(ret!=-1)
                unknown=ret;

        }

        //				display(PS,p,c);
        int arrW[p];
        int val=CalcWinners(PS,p,c);

        if(unknown!=-1)
        {
            PWinnerUnk(PS,p,c,unknown,arrW);
            i=0;
            int cnt=0;
            for(i=1; i<p; i++)
            {
                if(arrW[i-1]==arrW[i])
                    cnt++;
                else
                    break;

            }
            if(cnt==p-1)
            {
                printWinners(PS,p,c,val,15);
            }
            else
            {

                printWinners(PS,p,c,val,10);
            }

        }
        else
        {
            //printf("val: %d \n",val);
            printWinners(PS,p,c,val,0);
        }

    }
    return EXIT_SUCCESS;
}
Beispiel #4
0
void* VerCover_APPROX1(void* arg) 
{
	Graph_struct* p = (Graph_struct*) arg; 
	
	int VerticeNum,EdgeNum,i,j,maxNode;
	MGraph G;
	VerticeNum = p -> VertexNum;
	EdgeNum = p -> EdgeNum;
	int vNum;
	
	//to malloc two dimension array
	int **a = (int **)malloc(sizeof(int)*VerticeNum);
	for(i=0;i<VerticeNum;i++)
	{
		a[i] = (int*)malloc(sizeof(int)*VerticeNum);
	}
	
	/*a_1d is to store the time that one node appear in an edge*/
	int *a_1d = (int*)malloc(sizeof(int)*VerticeNum);
	for(i=0;i<VerticeNum;i++)
	{
		a_1d[i] = 0;
	}
	/*a_2d is to store whether a node is selected as a vertex*/
	int *a_2d = (int*)malloc(sizeof(int)*VerticeNum);
	for(i=0;i<VerticeNum;i++)
	{
		a_2d[i] = 0;
	}


	G = p -> G;

	for(i=0;i< VerticeNum;i++) 
	{	
		for(j=0;j< VerticeNum;j++)
		{		
			a[i][j] = G.arc[i][j];
		}
	}

	while(EdgeNum!=0){
		/*calulating the vertex of the highest degree*/
		for(i=0;i< VerticeNum-1;i++) 
		{	
			for(j=i+1;j< VerticeNum;j++)
			{		
				if (a[i][j]==1)
				{
					a_1d[i] = a_1d[i]+1;					a_1d[j] = a_1d[j]+1;			
				}
			}
		}
		maxNode=calMax(VerticeNum, a_1d); //calculate which node is of hthe highest degree
		for(i=0;i<VerticeNum;i++)
		{
			if (a[maxNode][i]==1)
			{
				a[maxNode][i] = 0;
				a[i][maxNode] = 0;
				a_2d[maxNode] = 1; //indicating that maxNode is selected to be one vertex
				EdgeNum = EdgeNum - 1; //an edge is used
			}	
		}
	}

	/*to print out the vertexes*/
	printf("APPROX-VC-1: ");
	vNum = 0;
	for (i = 0; i < VerticeNum; i++)
	{
		if(a_2d[i]==1)
		{
			printf("%d ",i);
			vNum = vNum + 1;
		}	
	}
	printf("\n");
	fflush(stdout);


	for (i=0;i<VerticeNum;i++)
	{
		free(a[i]);
		a[i] = NULL;	
	}
	//free(a);
	//a = NULL;

	free(a_1d);
	a_1d = NULL;
	
	free(a_2d);
	a_2d = NULL;

	p -> vNum = vNum;

	return NULL;
}