Blue Bridge Cup VIP questions training algorithm maximum profit

Examination training algorithm maximum profit

Resource constraints
Time limit: 1.0s memory limit: 256.0MB
Problem Description
  Chakra is a young entrepreneur, most recently in the food and beverage industry to enter. He open up the market in the country, bought a total of N Hotel. In the early market research, he will one day be divided into M time period, and you know i th hotel in the j-th time period, there will be Aij and Bij bit attendant when the value of clients visit. He also analyzed the different time periods to the different needs of the hotel, get the i-th hotel in the j-th time period, the average consumption per customer Cij yuan. In order to create a brand image, Chakra decided to select a time period for each restaurant is open every day only, every waiter up front A customer (the customer if the customer number is more than the number of staff, more than part of the day can not be consumed in the store).
  The purpose of entrepreneurs eventually profit. Please arrange business hours and tell Chakra day total spending up to much.
Input format
  of the first row two integers, N, M.
  A second row sequentially given three matrices A (N M), B (N M), C (N * M).
Output format
  line an integer, the largest total spending.
Sample input
2. 3
. 1 2. 3
. 3 2. 1
. 3. 1 2
. 1 2. 3
. 4. 5 2
. 3. 1. 6
sample output
16
data size and conventions
  . 1 <= M, N <= 100
  . 1 <= Aij of, Bij <5000 =
  0 <= Cij <= 10 ^ 9

Ideas: the beginning did not quite understand the meaning of the questions that each row of three numbers representing Aij, Bij and Cij, later found inconsistent with the meaning of the questions, let's look at three found are representative of the whole matrix, so do it the simple. Each matrix input value (large value, or may be long long long), then determines, attendant larger than the number of customers, customer number is multiplied by the average consumption current period profit (Cij is = Cij is Bij); otherwise attendant multiplication average consumption (Cij is = Cij is Aij of), then each time the profit per base sorting hotels, restaurants each block period of the maximum profit the sum evaluate to a subject.

code show as below:

#include<stdio.h>
int main(){
	long long a[105][105],b[105][105],c[105][105],t=0,l;
	int n,m,i,j,k;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%lld",&a[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%lld",&b[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%lld",&c[i][j]);
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			if(a[i][j]>b[i][j]){
				c[i][j]*=b[i][j];
			}
			else{
				c[i][j]*=a[i][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			for(k=0;k<m;k++){
				if(c[i][j]<c[i][k]){
					l=c[i][j];
					c[i][j]=c[i][k];
					c[i][k]=l;
				}
			}
		}
	}
	for(i=0;i<n;i++){
		t+=c[i][m-1];
	}
	printf("%lld",t);
	return 0;
}
Published 26 original articles · won praise 25 · views 636

Guess you like

Origin blog.csdn.net/weixin_45269353/article/details/104497316