您的位置:首页 > 其它

AtCoder Grand Contest 011

2017-03-13 19:25 330 查看
水平有限、只做了两个题

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: