Huawei OJ Home+work

Source: Internet
Author: User
#include "OJ.h"/* Input: Npapers represents the number of quiz papers (1≤papers≤20), Nremain indicates the remaining time (1≤nremain≤10000), paper[][2] is an array of papers*2, two of each row The elements in turn are the time required to complete the test paper, and the value of the test paper output: *pmaxvalue for the maximum value to be returned: 0: Exception 1: The calculation returned successfully */int getmaxvalue (int npapers, int nremain, int p
 
	APER[][2], double* pmaxvalue) {if (npapers==0 | | nremain==0 | | pmaxvalue==0 | | paper[0]==0) return 0; int costversustime[21]={0};            Record price/performance int pos[21]={0};
	Price/performance sorting, the original position is also sorted for (int i=0;i<npapers;i++) {costversustime[i]= (* (paper[i]+1))/(* (* (paper[i]));
	} for (int i=0;i<npapers;i++) {pos[i]=i;
	    	}//Use a bubbling sort, and also modify the location information for (int i=0;i<npapers;i++) {for (int j=npapers-1;j>i+1;j--) {
	    		if (Costversustime[j]>costversustime[j-1]) {int temp=costversustime[j];
	    		COSTVERSUSTIME[J]=COSTVERSUSTIME[J-1];
	    		
	    		Costversustime[j-1]=temp;
	    		Pos[j]=j-1;
	    	Pos[j-1]=j;
	}}} *pmaxvalue=0;
	int m=0; while (nremain>0 && M&LT;=NPapers) {int temp=pos[m];
    		if (Nremain>*paper[temp])//The remaining time can do a complete test paper {nremain-=*paper[temp];
    	*pmaxvalue+=* (paper[temp]+1);
			else//the remaining time is insufficient to make a Test paper, to obtain part of the value of {*pmaxvalue+= (nremain/(*paper[temp)) * (* (paper[temp]+1)); 
	    nremain=0;
	} m++;
} return 1;
 }

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.