阿里笔试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

相关推荐

昨天 18:31
成都理工大学 C++
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
2
6
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务