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;
}
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;
}
相关文章推荐
- AtCoder Grand Contest 011 E - Increasing Numbers(灵性乱搞)
- AtCoder Grand Contest 011 C - Squared Graph 乱搞
- AtCoder Grand Contest 011 D - Half Reflector 乱搞
- AtCoder Grand Contest 011 E - Increasing Numbers 乱搞+高精度
- AtCoder Grand Contest 011 A\B 贪心、二分
- AtCoder Grand Contest 020 B - Ice Rink Game(贪心+计算机乘法)
- Atcoder Grand 011 E- Increasing Numbers
- AtCoder Grand Contest 016 E - Poor Turkeys 贪心
- AtCoder Grand Contest 010 E - Rearranging 拓扑排序+贪心
- Atcoder Grand Contest 021 简要题解
- AtCoder Grand Contest 074 F - Lotus Leaves
- [AtCoder Grand Contest 016] D: Xor Replace (agc016d)
- AtCoder Grand Contest 023 F - 01 on Tree
- AtCoder Grand Contest 017 A
- AtCoder Grand Contest 018B: Sports Festival 题解
- (组合数学)AtCoder Grand Contest 019 F - Yes or No
- AtCoder Grand Contest 001 E - BBQ Hard 数学+dp
- AtCoder Grand Contest 020 B - Ice Rink Game(贪心+计算机乘法)
- 图论——AtCoder Grand Contest #C Squared Graph
- AtCoder Grand Contest 016 F - Games on DAG SG函数+状压dp