牛客网暑期ACM多校训练营(第五场)

                                                                                        A-gpa

链接:https://www.nowcoder.com/acm/contest/143/A
来源:牛客网
 

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld

题目描述

Kanade selected n courses in the university. The academic credit of the i-th course is s[i] and the score of the i-th course is c[i].

At the university where she attended, the final score of her is 

Now she can delete at most k courses and she want to know what the highest final score that can get.

输入描述:

The first line has two positive integers n,k

The second line has n positive integers s[i]

The third line has n positive integers c[i]

输出描述:

Output the highest final score, your answer is correct if and only if the absolute error with the standard answer is no more than 10-5

 

示例1

输入

复制

3 1
1 2 3
3 2 1

输出

复制

2.33333333333

说明

Delete the third course and the final score is 

备注:

1≤ n≤ 105

0≤ k < n

1≤ s[i],c[i] ≤ 103

思路:二分查找/01分数规划

代码:

 

                                                                                        G-max

链接:https://www.nowcoder.com/acm/contest/143/G
来源:牛客网


Give two positive integer c, n. You need to find a pair of integer (a,b) satisfy 1<=a,b<=n and the greatest common division of a and b is c.And you need to maximize the product of a and b

题目意思:给一个数c,一个数n,从1-n中找两个数,这两个数数的最大公约数为c,求这两个数乘积的最大值。

链接:https://www.nowcoder.com/acm/contest/143/G
来源:牛客网
 

输入描述:

The first line has two positive integer c,n

输出描述:

Output the maximum product of a and b.

If there are no such a and b, just output -1

 

示例1

输入

复制

2 4

输出

复制

8

说明

a=2,b=4

备注:

1<=c,n<=10^9

思路:看注释

牛客网暑期ACM多校训练营(第五场)_第1张图片

代码:

# include 
using namespace std;
typedef long long ll;
int main(){
        ll c, n;
        cin >> c >> n;
        ll k1 = n/c, k2 = n/c - 1;
        if(c > n)
                cout << -1 << endl;
        else if(c > n/2)//如果c大于n/2,那么找到的两个数的最大公约数只能c,并且那两个数也是c 
                cout << c*c << endl;
        else if(n == c)//c==n的话就更显然了
                cout << n*c << endl;
        else{//这个就结论就厉害 
                k1 *= c, k2*= c;
                cout << k1*k2 << endl;
        }
        return 0;
}

                                                                                        J-plan

链接:https://www.nowcoder.com/acm/contest/143/J
来源:牛客网
 

题目描述

There are n students going to travel. And hotel has two types room:double room and triple room. The price of a double room is p2 and the price of a triple room is p3

Now you need to calulate the minimum total cost of these students.

输入描述:

The first line has three integers n, p2, p3

输出描述:

Output the minimum total cost.

 

示例1

输入

复制

4 2 3

输出

复制

4

示例2

输入

复制

5 1 3

输出

复制

3

备注:

1<=n<=10^9

1<=p2,p3<=10^9

思路:贪心,枚举就过了,不过要考虑清楚哦,注释上写了各种情况,似乎没考虑相除-1得负数的情况

代码:

#include
#include
#include
using namespace std;
typedef long long int ll;
int main()
{
	ll p1,p2,p3,sum=0,yu;
	double dp2,dp3;
	cin>>p1>>p2>>p3;
	dp2=double(p2)/2;
	dp3=double(p3)/3;
	if(dp2==dp3){//三人间,两人间单价相同,不浪费空间花费最低 
		if(p1%2) sum=(p1/2-1)*p2+p3;//余一个人 
		else sum=p1/2*p2;
		cout<dp3){//三人间单价更低 
		yu=p1%3,sum=p1/3;//sum为开的间数 
		if(yu==1){//多一个人,                 //    2    3 
		          //按四个人处理 
		    int a,b,c;//直接比较三种情况 
			a=2*p2,b=p2+p3,c=p3+p3; 
			sum=(sum-1)*p3+min(a,min(b,c));   // 5   3    4
		}                                     //     2+3<3+3 
		else if(yu==2){//多两个人 
			if(p2 <
		if(yu) {
			if(p2*2>=p3){//开两间二人房大于等于开一间三人房的花费 
				sum=(sum-1)*p2+p3; 
			}
			else sum=sum*p2+p2;
		}
		else sum=sum*p2;
		cout<

 

你可能感兴趣的:(新思路,简单题)