CodeForces round 967 div2 题解(A~E)
本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉
最后一题没搞懂怎么做,恳请大神指教
欢迎大家在评论区提问.
A |
稳定版题面 https://cn.vjudge.net/problem/CodeForces-967A
水题, 不写题解了, 浪费空间
细节处理见代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct tim{
int h, m;
}t[1001];
int gap(int i, int j){
return (t[j].h - t[i].h)*60 + t[j].m - t[i].m;
}
void print(int i, int dur){ //自动把分钟的延迟进位到小时
t[i].m += dur;
while(t[i].m >= 60){
t[i].m -= 60;
t[i].h ++;
}
cout<<t[i].h<<' '<<t[i].m<<endl;
}
int n, s;
signed main(){
cin>>n>>s;
t[0].h = t[0].m = 0;
for(int i = 1; i <= n; i++)
cin>>t[i].h>>t[i].m;
t[n+1].h = t[n+1].m = 1000001;
if(gap(0,1) >= s+1){
cout<<0<<' '<<0<<endl;
return 0;
}
for(int i = 1; i <= n; i++)
if(gap(i,i+1) >= 2*s+2) {
print(i,s+1);
break;
}
return 0;
}
B |
我没看官方题解, 我的做法是二分答案.
二分答案判定还是很方便的. 只需要贪心堵上出水量最大的孔(特判第一个孔)
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5+5;
int s[maxn],a[maxn],n,A,B;
bool cmp(int a, int b){return a>b;}
bool check(int pos){
return a[1]*A/(s[pos]) >= B;
}
signed main(){
cin>>n>>A>>B>>a[1];
for(int i = 2; i <= n; i++) cin>>a[i];
sort(a+2,a+n+1);//特判a[1]
s[0] = 0;
for(int i = 1; i <= n; i++) s[i] = s[i-1] + a[i];
//l意为最多不堵多少个孔(区间左闭右开)
int l = 1, r = n+1, mid = (l+r)>>1;
while(r - l > 1){
mid = (l+r)>>1;
if(check(mid)) l = mid;
else r = mid;
}
cout<<n-l<<endl;
return 0;
}
C |
因为电梯和楼梯在所有楼层都有, 而且所有电梯速度一样,所以不用换电梯/楼梯, 直达最优
所以易知: 距离任意一个端点的水平距离最近的电梯/楼梯最优. 我们可以用lower_bound查找最近的电梯/楼梯
画一下图, 分类讨论一下很容易理解.
有一个小技巧: 把不合法的状态(找不到)设成inf,这样就不要特判了
再算一下坐电题和走楼梯哪种更优.
注意考虑不需要坐电梯/楼梯的情况!!! 我因为没考虑这种情况被hack了, 伤心...
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5+5;
int n,m, l[maxn], e[maxn] ,v, q, cl, ce;
inline int divis(int a, int b){
if(a % b == 0) return a / b;
else return a/b + 1;
}
signed main(){
cin>>n>>m>>cl>>ce>>v;
memset(l, 0x3f, sizeof l);
memset(e, 0x3f, sizeof e);
for(int i = 1; i <= cl; i++)
cin>>l[i];
for(int i = 1; i <= ce; i++)
cin>>e[i];
cin>>q;
while(q--){
int ans = 1e15+5, x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
if(x1 > x2){
swap(x1,x2);
swap(y1,y2);
}
if(x1 == x2){
cout<<abs(y1 - y2)<<endl;
continue;
}
//by walk(no stairs or elevators needed)
int pos1 = lower_bound(l+1, l+cl+1, y1) - l, ans1 = 1e15+5, pos2, ans2;
if(pos1 > 1) pos2 =upper_bound(l+1, l+cl+1, y1) - l - 1,
ans1 = min(abs(y1 - l[pos1])+abs(y2 - l[pos1]), abs(y1 - l[pos2])+abs(y2 - l[pos2]))
+ abs(x1 - x2);
else ans1 = abs(y1 - l[pos1])+abs(y2 - l[pos1])+ abs(x1 - x2);
//by stairs
pos1 = lower_bound(e+1, e+ce+1, y1) - e, ans2 = 1e15+5;
if(pos1 > 1) pos2 =upper_bound(e+1, e+ce+1, y1) - e - 1,
ans2 = min(abs(y1 - e[pos1])+abs(y2 - e[pos1]), abs(y1 - e[pos2])+abs(y2 - e[pos2]))
+ divis(abs(x1 - x2), v);
else ans2 = abs(y1 - e[pos1])+abs(y2 - e[pos1])+ divis(abs(x1 - x2),v);
//by elevator
ans = min(ans1, ans2);
cout<<ans<<endl;
}
return 0;
}
D |
想出了正解, 没时间写了...
先把所有服务器排个序
可以发现每个service最优的选择策略 选择的server 在排序后的序列中都是连续的
预处理出对于一个service, 以第 i 个server (或之后的server)开头, 最少选几个server
然后暴力枚举即可
#include<bits/stdc++.h>
using namespace std;
#define int long long
template<typename T>
void read(T &ans){T f = 1; char c = getchar();ans = 0;while(!isdigit(c)){if(c == '-')f = -1;c = getchar();}while( isdigit(c)){ans = ans*10 + c - '0';c = getchar();}ans *= f;}
const int maxn = 3e5 + 5, inf = 1e15;
struct server{
int c, ord;
inline bool operator <(const server &rhs) const{
return c < rhs.c;
}
}s[maxn];
int x1, x2, cnt1[maxn], cnt2[maxn], p1, p2, n;
inline int divis(int a, int b){
if(a % b == 0) return a / b;
else return a/b + 1;
}
signed main(){
read(n), read(x1), read(x2);
for(int i = 1; i <= n; i++){
read(s[i].c); s[i].ord = i;
}
sort(s + 1, s + n + 1);
memset(cnt1, 0x3f, sizeof cnt1);
memset(cnt2, 0x3f, sizeof cnt2);
for(int i = 1; i <= n; i++){
cnt1[i] = divis(x1, s[i].c);
cnt2[i] = divis(x2, s[i].c);
}
p1 = p2 = inf;
for(int i = 1; i <= n; i++){
if(i + cnt1[i] <= n && cnt1[i] + cnt2[i + cnt1[i]] + i - 1 <= n){
p1 = i, p2 = i + cnt1[i];
break;
}
if(i + cnt2[i] <= n && cnt2[i] + cnt1[i + cnt2[i]] + i - 1 <= n){
p1 = i + cnt2[i], p2 = i;
break;
}
}
if(p1 == inf){
puts("No");
}
else {
puts("Yes");
printf("%lld %lld\n", cnt1[p1], cnt2[p2]);
for(int i = p1; i < p1 + cnt1[p1]; i++){
printf("%lld ", s[i].ord);
}
puts("");
for(int i = p2; i < p2 + cnt2[p2]; i++){
printf("%lld ", s[i].ord);
}
puts("");
}
return 0;
}
未完待续.....
CodeForces round 967 div2 题解(A~E)的更多相关文章
- [Codeforces Round #461 (Div2)] 题解
[比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys [算法] 当y = 0 , 不可以 当 ...
- Codeforces Round #407 div2 题解【ABCDE】
Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...
- Codeforces Round #467(Div2)题解
凌晨起来打CF,0:05,也是我第一次codeforces 第一题: 我刚开始怀疑自己读错题了,怎么会辣么水. 判除了0的数字种类 #include <cstdio> ; ]; int m ...
- Codeforces Round#704 Div2 题解(A,B,C,D,E)
FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...
- Codeforces Round#687 Div2 题解
打这场的时候迷迷糊糊的,然后掉分了( A Prison Break: 题面很复杂,但是题意很简单,仅需求出从这个点到四个角的最大的曼哈顿距离即可 #include <bits/stdc++.h& ...
- CodeForces Round #516 Div2 题解
A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...
- Codeforces Round #539 div2
Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...
- Codeforces Round #543 Div1题解(并不全)
Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...
- Codeforces Round #545 Div1 题解
Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...
随机推荐
- 一个简单的binlog恢复测试
日常的数据备份及恢复测试,是DBA工作重中之重的事情,所以要做好备份及测试,日常的备份常见有mysqldump+binlog备份.xtrabackup+binlog备份,无论那一种,几乎都少不了对bi ...
- logical_backup: expdp/impdp
Table of Contents 1. 注意事项 2. 前期准备 3. 常用参数及示例 4. 常用语句示例 5. 交互式命令 6. 技巧 6.1. 不生成文件直接导入目标数据库 6.2. 通过she ...
- 让simplejson支持datetime类型的序列化
simplejson是Python的一个json包,但是觉得有点不爽,就是不能序列化datetime,稍作修改就可以了: 原文:http://blog.csdn.net/hong201/article ...
- 【C++ Primer | 15】继承的构造函数
继承的构造函数 子类为完成基类初始化,在C++11之前,需要在初始化列表调用基类的构造函数,从而完成构造函数的传递.如果基类拥有多个构造函数,那么子类也需要实现多个与基类构造函数对应的构造函数. cl ...
- 在Git.oschina.net中配置TortoiseGit使用sshkey,无需输入账号和密码
ssh的方式 git@oschina.com:用户名/版本库t.git 此篇文章针对于这种 黄海正在开发的项目位置 https://gitee.com/dslx/BigData.g ...
- 有道词典Linux版下载安装
http://cidian.youdao.com/index-linux.html Ubuntu http://codown.youdao.com/cidian/linux/youdao-dict_1 ...
- Redis的搭建和Redis的集群搭建
1.Redis的官网:https://redis.io/ Redis的测试网站:http://try.redis.io/ 2.参考博客:https://www.cnblogs.com/maf ...
- 一脸懵逼学习Hadoop-HA机制(以及HA机制的配置文件,测试)
1:能否让两个NameNode都正常影响客户端请求? 应该让两个NameNode节点在某个时间只能有一个节点正常影响客户端请求,相应请求的必须为Active状态的那一台. 2:standBy状态的节点 ...
- bzoj4773: 负环
题解: 网上还有一种spfa+深度限制的算法 https://www.cnblogs.com/BearChild/p/6624302.html 是不加队列优化的spfa,我觉得复杂度上限是bellma ...
- 【BZOJ1778】[Usaco2010 Hol]Dotp 驱逐猪猡
题解: 网上有一种复杂的方法..好像复杂度并没有优势就没看 定义f[i]表示i的期望经过次数,f[i]=sigma{f[j]*p/q/du[j]}+(i==1); 然后高斯消元就可以了 最后求出来的f ...