阿里笔试3.30

太久没做题,对题目的敏感度都没了,两题就做了一个题,哭了。
这是第一题的代码:
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<vector>
#include<iostream>
#include<time.h>
#include<math.h>
using namespace std;
//-------------------------------------------------------
#define LL long long
//#define LL __int64
template<typename T>T Max(T a, T b){ return a>b ? a : b; }
template<typename T>T Min(T a, T b){ return a<b ? a : b; }
template<typename T>void Swap(T &a, T &b){ T c = a; a = b; b = c; }
template<typename T>T Abs(T a){ return a >= 0 ? a : -a; }
#define clr_all(a,b) memset(a,b,sizeof(a))
#define clr(a,b,n) memset(a,b,sizeof(a[0])*n)
const int MAXN = 100000 + 5;
const int MAXM = 500 + 5;
const int mod = 1000000007;
const int INF = 0x7FFFFFFF;
//-------------------------------------------------------

LL N, M, K;
priority_queue<LL> q;

int main(){
	scanf("%lld%lld%lld", &N, &M, &K);
	for (LL i = 0; i < N; i++){
		LL tmp;
		scanf("%lld", &tmp);
		q.push(tmp);
	}
	//printf("%d\n", q.top());
	for (LL i = 1; i <= M; i++){
		LL tmp = q.top();
		q.pop();
		tmp = tmp - i*K;
		if (tmp % 2 != 0)
			tmp -= 1;
		tmp /= 2;
		q.push(tmp);
	}
	LL ans = 0;
	while (!q.empty()){
		ans += q.top();
		q.pop();
	}
	ans += M*K*N;
	printf("%lld\n", ans);
	return 0;
}
思路大概就是,每次每个厂都增加K,这个K让他保持不动,然后每次取出最大数的时候,将本来应该减少的K/2,从最大数上减去,这样就可以始终保持所有数的累计增加是K的倍数,为了防止超时,可以用优先队列来做。

#阿里笔试2020##阿里巴巴##笔试题目#
全部评论
谢谢分享
点赞 回复 分享
发布于 2020-03-31 00:01
第一题AC了吗?
点赞 回复 分享
发布于 2020-03-30 22:16

相关推荐

在看数据的傻狍子很忙碌:学生思维好重,而心很急,自己想想真的能直接做有难度的东西吗?任何错误都是需要人担责的,你实习生可以跑路,你的同事领导呢
点赞 评论 收藏
分享
头像
05-16 11:16
已编辑
东华理工大学 Java
牛客737698141号:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
点赞 评论 收藏
分享
评论
2
6
分享

创作者周榜

更多
牛客网
牛客企业服务