AtCoder Grand Contest 011

水平有限、只做了两个题

A

题意:n个人,每辆bus只能做c个人, 每个人最长等待时间是k, 给出每个人的到达时间,问最小需要多少辆车可以把人全部运走

这题还是很友好的,到达时间从小到大排一次, 维护每一辆车最先到达那个人的极限时间,按着题意模拟即可。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define REP(i, x, n)	for(int i = x; i < n; ++i)
const int qq = 1e5 + 10;
int n;
LL t[qq];
LL n, c, k;
int main(){
	scanf("%lld%lld%lld", &n, &c, &k);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", t + i);
	sort(t + 1, t + n + 1);
	int bus = 0;
	LL dis = t[1] + k;
	int people = 1;
	for(int i = 2; i <= n; ++i){
		if(people == c){
			++bus;
			people = 1;
			dis = t[i] + k;
			continue;
		}
		if(t[i] > k){
			++bus;
			people = 1;
			dis = t[i] + k;
			continue;
		}
		++people;
	}
	if(people)	++bus;
	printf("%d\n", bus);
	return 0;
}


B

题意:n个生物,每个生物有一个尺寸和颜色,生物之间可以互相吞并。比如A生物吞并B生物, 最后得到的生物是C生物, C生物的尺寸是 A生物的尺寸加上B生物的尺寸,C生物的颜色是A生物的颜色,但是可以吞并的条件是 B生物的尺寸小于等于两倍A生物的尺寸。问吞并到只剩一种生物,这种生物的颜色有多少种可能

首先我们要知道最后剩下那个生物的颜色是如何来的? 肯定是它独自一人去吞并其他所有生物才可以得来,。。。 说不清楚啦 看代码好啦   ///~///

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <sstream>
#include <iostream>
#include <algorithm>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define REP(i, x, n)	for(int i = x; i < n; ++i)
const int qq = 1e5 + 10;
int n;
LL sum[qq], num[qq];
bool cmp(LL a, LL b){
	return a > b;
}
int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
		scanf("%lld", num + i);
	sort(num + 1, num + 1 + n, cmp);
	for(int i = n; i >= 1; --i)
		sum[i] = sum[i + 1] + num[i];
	int res = 1;
	for(int i = 2; i <= n; ++i)
		if((LL)2 * (num[i] + sum[i + 1]) >= num[i - 1])	res++;
		else{
			break;
		}
	printf("%d\n", res);
	return 0;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值