Codeforces Round #591 (Div. 1)A.Save the Nature

Wrong answer on test 215 ms0 KB

 

感觉思路上就有问题,把问题搞复杂了?心态爆炸。。。心情好了再改?

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <windows.h>
#include <deque>
#include <unordered_set>
#include <stack>
using namespace std;
typedef unsigned long UL;
typedef long long LL;

class API {
public:
	static int Min_num(int a, int b);
	static LL call(vector<UL>& P, int & count, int a, int b, int x, int y, LL k);
};

bool compare(UL a, UL b) {
	return a > b;
}
int main() {
	int q, n, x, y;
	q = n = x = y = 0;
	int a, b;
	LL k;
	cin >> q;
	while (q) {
		cin >> n;
		vector<UL>* P = new vector<UL>(n, 0);
		for (int i = 0; i < n; i++) {
			cin >> (*P)[i];
		}
		cin >> x >> a >> y >> b;
		cin >> k;
		sort(P->begin(), P->end(), compare);//递减排序

		LL ret = 0;
		int count = 0;
		ret = API::call((*P), count, a, b, x, y, k);
		if (ret < k)
			count = -1;
		cout << count << endl;
		delete(P);
		q--;
	}
	return 0;
}


int API::Min_num(int a, int b)
{
	int tmp = 0;
	if (!(b%a))
		tmp = b;
	else {
		tmp = a * b;
	}
	return tmp;
}

LL API::call(vector<UL>& P, int & count, int a, int b, int x, int y, LL k)
{
    int len = P.size();
    if(!len)
        return 0;
    double _len,_a,_b,_x,_y;
    _len = len;
    _a = a;
    _b = b;
    _x = x;
    _y = y;
	if (_len*_y/_b < _len*_x/_a) {
		int tmp = a;
		a = b;
		b = tmp;
		tmp = x;
		x = y;
		y = tmp;
	}
	
	int A, B, AB;
	LL ret = 0;
	A = B = AB = 0;
	for (int i = 1; i <= len; i++) {
		if (i%a == 0)
			A++;
		if (i%b == 0)
			B++;
		if (!((i%a) || (i%b)))
			AB++;
	}
	int t_A, t_B, t_AB;
	t_A = A;
	t_B = B;
	t_AB = AB;
	A -= AB;
	B -= AB;
	//count = Min_num(a,b)*AB;
	for (UL mem : P) {
		mem /= 100;
		if (AB) {
			ret += mem * (x + y);
			AB--;
		}
		else if (B) {
			ret += mem * (y);
			B--;
		}
		else if (A) {
			ret += mem * (x);
			A--;
		}
		else {
			break;
		}
		if (ret >= k)
			break;
	}
	count = (t_AB - AB)*Min_num(a, b) > (t_A - A - AB)*a ? (t_AB - AB)*Min_num(a, b) : (t_A - A - AB)*a;
	count = count > (t_B - B - AB)*b ? count : (t_B - B - AB)*b;
	return LL(ret);
}

第一个用力通过:

InPut:

4
1
100
50 1
49 1
100
8
100 200 100 200 100 200 100 100
10 2
15 3
107
3
1000000000 1000000000 1000000000
50 1
50 1
3000000000
5
200 100 100 100 100
69 5
31 2
90


OutPut:

-1
6
3
4

=====
Used: 31 ms, 0 KB

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值