本来准备比完赛就写题解的, 但是一拖拖了一星期, 唉

最后一题没搞懂怎么做,恳请大神指教

欢迎大家在评论区提问.

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)的更多相关文章

  1. [Codeforces Round #461 (Div2)] 题解

    [比赛链接] http://codeforces.com/contest/922 [题解] Problem A. Cloning Toys          [算法] 当y = 0 ,   不可以 当 ...

  2. Codeforces Round #407 div2 题解【ABCDE】

    Anastasia and pebbles 题意:你有两种框,每个框可以最多装k重量的物品,但是你每个框不能装不一样的物品.现在地面上有n个物品,问你最少多少次,可以把这n个物品全部装回去. 题解:其 ...

  3. Codeforces Round #467(Div2)题解

    凌晨起来打CF,0:05,也是我第一次codeforces 第一题: 我刚开始怀疑自己读错题了,怎么会辣么水. 判除了0的数字种类 #include <cstdio> ; ]; int m ...

  4. Codeforces Round#704 Div2 题解(A,B,C,D,E)

    FST ROUND !!1 A Three swimmers: 直接整除一下向上取整就好了: #include <bits/stdc++.h> using namespace std; t ...

  5. Codeforces Round#687 Div2 题解

    打这场的时候迷迷糊糊的,然后掉分了( A Prison Break: 题面很复杂,但是题意很简单,仅需求出从这个点到四个角的最大的曼哈顿距离即可 #include <bits/stdc++.h& ...

  6. CodeForces Round #516 Div2 题解

    A. Make a triangle! 暴力... 就是给你三个数,你每次可以选一个加1,问最少加多少次能构成三角形 #include <bits/stdc++.h> #define ll ...

  7. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  8. Codeforces Round #543 Div1题解(并不全)

    Codeforces Round #543 Div1题解 Codeforces A. Diana and Liana 给定一个长度为\(m\)的序列,你可以从中删去不超过\(m-n*k\)个元素,剩下 ...

  9. Codeforces Round #545 Div1 题解

    Codeforces Round #545 Div1 题解 来写题解啦QwQ 本来想上红的,结果没做出D.... A. Skyscrapers CF1137A 题意 给定一个\(n*m\)的网格,每个 ...

随机推荐

  1. 【python】python版本升级2.6.6到2.7.3(CentOS release 6.2)

    一. 升级python到2.7.3 wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz tar -zxvf Python-2.7. ...

  2. ubuntu18.04进不了桌面

    ubuntu升级18.04进不了桌面 https://chengfeng.site/2018/05/02/ubuntu%E5%8D%87%E7%BA%A718-04%E8%B8%A9%E7%9A%84 ...

  3. 怎么编辑PDF,如何给PDF加水印

    在使用PDF文件的时候,往往会用到PDF编辑器来修改,那么,在使用PDF编辑器修改文件的时候,想要在文件中添加水印,这该怎么操作呢,不会的小伙伴可以看看下面的文章了哦,说不定就会了. 1.打开运行PD ...

  4. 使用tensorflow构造隐语义模型的推荐系统

    先创建一个reader.py,后面的程序将用到其中的函数. from __future__ import absolute_import, division, print_function impor ...

  5. win10远程桌面出现身份验证错误。要求的函数不受支持

    打开组策略,依次展开“计算机配置”->“管理模板”->“系统”->“凭据分配”,设置名称: “加密 Oracle 修正” 为已启用,并设置保护级别为“易受攻击”

  6. C#学习-类和结构

    类和结构体,对两者进行比较 语法上的区别在于,定义类要使用关键字class,而定义结构体则使用关键字struct; 结构体中不可对声明字段进行初始化,但类可以: 如果没有为类显式地定义构造函数,C#编 ...

  7. tomcat 反代配置

    tomcat反代可以基于nginx , http进行反代 反代服务器: 有两个网口  反代服务器一般有两块网卡一块处于外网,一块处于内网用于与后端服务器通信 tomcat 节点处于内网地址 1 tom ...

  8. Python学习(十三) —— 网络编程

    一.操作系统基础 操作系统(Operating System):OS是管理和控制计算机硬件和软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才能运行 ...

  9. BZOJ2141 排队 树状数组 分块

    原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2141.html 题目传送门 - BZOJ2141 题意 给定一个序列 $a$ ,先输出原先的逆序对数. ...

  10. Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第十二集之FastDFS的使用】

    (自己的项目路径)相关项目在web部分中priv.lirenhe.fastdfs 官方提供一个fastdfs开发项目,下载下来maven install 以下内容是借鉴网上的一篇文章,但是不知道网址了 ...