int largestRectangleArea_bruteforce(vector<int> &height) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     if (height.empty()) {
         return 0;
     }
     Area max_area(height[0], 1);
     vector<vector<Area> > areas;
     vector<Area> first;
     first.push_back(max_area);
     areas.push_back(first);
     for (int i = 1; i < height.size(); i++) {
         vector<Area> last_areas = areas.back();
         for (int j = 0; j < last_areas.size(); j++) {
             Area &a = last_areas[j];
             a.Set(min(a.height, height[i]), a.width+1);
             max_area = max(max_area, a);
         }
         Area a(height[i], 1);
         last_areas.push_back(a);
         max_area = max(max_area, a);
         areas.push_back(last_areas);
     }
     
     return max_area.area;
 }
示例#2
0
文件: zuhe.c 项目: sydtju/acm
int main(){
	int num[7]={3,4,5,6,8,9,10};
	int h=max_area(num,sizeof(num)/sizeof(num[0]));
	int t =sizeof(num);
	printf("%d",t);
	getchar();
	return 0;
}
示例#3
0
void main()
{
    int A[]={7,10,3,6,4,5};
    int i, maxarea=0;
    int size= sizeof(A)/4;
    printf("\n size is %d ", size);
    maxarea = max_area(A, size);
    printf("\nMax Area of ");
    for (i = 0; i<size; i++)
    {
	printf(" %d ", A[i]);
    }
    printf(" is %d.\n", maxarea);
    return;
}
int main()
{
    int n, board[1000];
    while (~scanf("%d", &n)) {
        int i;
        for (i = 0; i < n; ++i) {
            scanf("%d", &board[i]);
        }

        printf("The max capacity of the container is %d and %d\n", maxArea(board, n), max_area(board, n));
    }

    return 0;
}
示例#5
0
文件: conf.c 项目: svn2github/staden
void calc_conf_values(Read *r, int phred_scale) {
    int i;
    int pos,start_pos,end_pos;

#ifdef AVERAGE_QUAL
    char *conf_buf, val;
    double total;
    
    if (NULL == (conf_buf = (char *)xcalloc(r->NBases, 1))) {
	return;
    }
#endif

    /*
     * Set confidence values for first and last bases to zero to simplify
     * the loop. We reset them later on so it's not too vital.
     */
    
    (r->prob_A)[0] = (r->prob_C)[0] = (r->prob_G)[0] = (r->prob_T)[0] = 0;
    if (r->NBases > 1)  {
	i = r->NBases - 1;
	(r->prob_A)[i] = (r->prob_C)[i] = (r->prob_G)[i] = (r->prob_T)[i] = 0;
    }
    
    
    for (i = 1; i < r->NBases-1; i++) {

	/* Clear the probability arrays */
	(r->prob_A)[i] = (r->prob_C)[i] =
	    (r->prob_G)[i] = (r->prob_T)[i] = 0;
	pos = (r->basePos)[i];
	start_pos = (r->basePos)[i]-((r->basePos)[i] - (r->basePos[i-1])) /2;
	end_pos   = (r->basePos)[i]+((r->basePos)[i+1] - (r->basePos[i])) /2;

	switch ((r->base)[i]) {
	case 'A':
	case 'a':
#ifdef AVERAGE_QUAL
	    conf_buf[i] =
#else
	    (r->prob_A)[i] =
#endif
		probFromQual((max_area(r->traceC, r->traceG, r->traceT,
				       start_pos, end_pos) /
			      get_area(r->traceA, start_pos, end_pos)));
	    break;

	case 'C':
	case 'c':
#ifdef AVERAGE_QUAL
	    conf_buf[i] =
#else
	    (r->prob_C)[i] =
#endif
		probFromQual((max_area(r->traceA, r->traceG, r->traceT,
				       start_pos, end_pos) /
			      get_area(r->traceC, start_pos, end_pos)));
	    break;
	    
	case 'G':
	case 'g':
#ifdef AVERAGE_QUAL
	    conf_buf[i] =
#else
	    (r->prob_G)[i] =
#endif
		probFromQual((max_area(r->traceC, r->traceA, r->traceT,
				       start_pos, end_pos) /
			      get_area(r->traceG, start_pos, end_pos)));
	    break;

	case 'T':
	case 't':
#ifdef AVERAGE_QUAL
	    conf_buf[i] =
#else
	    (r->prob_T)[i] =
#endif
		probFromQual((max_area(r->traceC, r->traceG, r->traceA,
				       start_pos, end_pos) /
			      get_area(r->traceT, start_pos, end_pos)));
	    break;

	default:
	    break;
	}
    }

    if (r->NBases > 1) {
#ifdef AVERAGE_QUAL
	conf_buf[0] = conf_buf[1];
	conf_buf[r->NBases-1] = conf_buf[r->NBases-2];
#else
	(r->prob_A)[0] = (r->prob_A)[1];
	(r->prob_C)[0] = (r->prob_C)[1];
	(r->prob_G)[0] = (r->prob_G)[1];
	(r->prob_T)[0] = (r->prob_T)[1];

	(r->prob_A)[r->NBases-1] = (r->prob_A)[r->NBases-2];
	(r->prob_C)[r->NBases-1] = (r->prob_C)[r->NBases-2];
	(r->prob_G)[r->NBases-1] = (r->prob_G)[r->NBases-2];
	(r->prob_T)[r->NBases-1] = (r->prob_T)[r->NBases-2];
#endif
    }

    /* Average confidence values */
#ifdef AVERAGE_QUAL
    /*
     * Calculate average over a specified window size.
     * For the ends of the array we cheat and copy the nearest average.
     * It's easy to do and this is only temporary anyway.
     */
    
    /* Initialise total */
    total = 0;
    for (i = 0; i < WINDOW_SIZE && i < r->NBases; i++) {
	total += conf_buf[i];
    }
    
    /* Loop around for inner section of quality buffer */
    for (i = WINDOW_SIZE/2; i < r->NBases - WINDOW_SIZE/2 - 1; i++) {
	switch((r->base)[i]) {
	case 'A':
	case 'a':
	    (r->prob_A)[i] = total / WINDOW_SIZE;
	    break;

	case 'C':
	case 'c':
	    (r->prob_C)[i] = total / WINDOW_SIZE;
	    break;

	case 'G':
	case 'g':
	    (r->prob_G)[i] = total / WINDOW_SIZE;
	    break;

	case 'T':
	case 't':
	    (r->prob_T)[i] = total / WINDOW_SIZE;
	    break;
	}
	total += conf_buf[i + WINDOW_SIZE/2+1] - conf_buf[i - WINDOW_SIZE/2];
    }

    /* do left end - extend from first done */
    i = WINDOW_SIZE/2+1 < r->NBases
	? WINDOW_SIZE/2+1 : (r->NBases > 0 ? r->NBases-1 : 0);
    val = conf_buf[i];
    for (i = 0; i < WINDOW_SIZE/2 && i < r->NBases; i++) {
	switch ((r->base)[i]) {
	case 'A':
	case 'a':
	    (r->prob_A)[i] = val;
	    break;
	case 'C':
	case 'c':
	    (r->prob_C)[i] = val;
	    break;
	case 'G':
	case 'g':
	    (r->prob_G)[i] = val;
	    break;
	case 'T':
	case 't':
	    (r->prob_T)[i] = val;
	    break;
	}
    }
    

    /* do right end - extend from last done */
    i = r->NBases - WINDOW_SIZE/2 >= 0 ? r->NBases - WINDOW_SIZE/2 : 0;
    val = conf_buf[i];
    for (; i < r->NBases; i++) {
	switch ((r->base)[i]) {
	case 'A':
	case 'a':
	    (r->prob_A)[i] = val;
	    break;
	case 'C':
	case 'c':
	    (r->prob_C)[i] = val;
	    break;
	case 'G':
	case 'g':
	    (r->prob_G)[i] = val;
	    break;
	case 'T':
	case 't':
	    (r->prob_T)[i] = val;
	    break;
	}
    }
    
    xfree(conf_buf);
#endif

    if (phred_scale) {
	rescale_scores(r);
    }

    return;
}