Codeforces Round #707 Editorial Div2 题解
CF1501 Div2 题解
CF1501A
这道题其实是一道英语阅读题,然后样例解释又不清晰,所以我看了好久,首先它告诉了你每个站点的预期到达时间 \(a_i\) ,以及每个站点的预期出发时间 \(b_i\) 。
那么对每个站点来说,从上一个站点的预期出发时间 \(b_{i-1}\) 到当前站点的预期到达时间 \(a_{i}\) ,那么中间差的时间就是你从上一个站点到达这个站点的时间,计算出 \(go_i\) \(=\) \(a_i - b_{i-1}\) 就计算出第 \(i-1\) 个站点到达第 \(i\) 个站点的时间。
然后考虑限制:
- 你需要在预期出发时间后出发
- 你在一个站点至少要待 \(\lceil \cfrac{b_i-a_i}{2} \rceil\) 的时间
那么对于限制 \(2\) ,首先我们就加上这么多的时间,然后如果加上这么多的时间后,我们当前时间仍然小于预期时间,那就将时间更新为预期时间,然后就做完了。
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<typename T> inline void read(T &x){
T f=1;x=0;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x*=f;
}
const int N = 3000;
int T,n;
struct node{
int x,y;
}f[N];
int t[N],go[N];
signed main(){
read(T);
while(T--){
memset(f,0,sizeof(f));
memset(t,0,sizeof(t));
memset(go,0,sizeof(go));
read(n);
for(int i=1;i<=n;i++){
read(f[i].x),read(f[i].y);
go[i]=f[i].x-f[i-1].y;
}
for(int i=1;i<=n;i++){
read(t[i]);
go[i]+=t[i];
}
int now=0;
for(int i=1;i<=n;i++){
now+=go[i];
// now+=t[i];
if(i==n){
printf("%lld\n",now);
break;
}
int lt=ceil((double)(f[i].y-f[i].x) /2.0);
now+=lt;
if(now<f[i].y){
now=f[i].y;
}
//now+=t[i];
}
}
return 0;
}
CF1501B
这道题的题意就贼清晰了,然后就很简单了。
发现如果 \(a_i = 0\) 时,那么你就只用正常的叠加一层没被涂的。
否则,你就要叠一层,并且往下进行染色。
暴力进行染色肯定是会超时的,因为 \(1\) 个点有可能被染色多次,所以我采用了一种方式,那就是用树状数组来进行修改。
对要染色的区间的值都加上 \(1\) ,最后进行单点查询,如果值不为 \(0\) ,那就输出 \(1\) ,否则输出 \(0\).
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<typename T> inline void read(T &x){
T f=1;x=0;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x*=f;
}
const int N = 2e6;
int T,n,a[N],vis[N],tot=0,f[N],num;
vector<int>b;
vector<pair<int,int> > c;
int lowbit(int x){
return x&(-x);
}
int c1[N],c2[N];
void update(int x,int k){
int i=x;
while(x<=n){
c1[x]+=k;
c2[x]+=i*k;
x+=lowbit(x);
}
}
int sum(int x){
int ans=0,i=x;
while(x>0){
ans+=c1[x]*(i+1);
ans-=c2[x];
x-=lowbit(x);
}
return ans;
}
signed main(){
read(T);
while(T--){
read(n);
for(int i=1;i<=n;i++){
read(a[i]);
}
for(int i=1;i<=n;i++){
f[++num]=0;
if(a[i]){
// f[++num]=1;
int last=num-a[i]+1;
if(last<=0) last=1;
c.push_back( make_pair(last,num) );
}
}
for(int i=0;i<c.size();i++){
int l=c[i].first;
int r=c[i].second;
update(l,1);
update(r+1,-1);
}
for(int i=1;i<=num;i++){
int x=sum(i);
if(sum(i)-sum(i-1)==0){
printf("0 ");
}
else printf("1 ");
}
puts("");
for(int i=0;i<=num;i++) c1[i]=c2[i]=0;
c.clear();
num=0;
}
return 0;
}
CF1500A
这道题很显然就有一个暴力的平方想法,你可能认为会超时,但是实际是不会的。所以不要怕,直接暴力碾压就完事了吗,具体证明就不发了,因为我也不会,所以这篇就不交题解了。
#include<bits/stdc++.h>
using namespace std;
template<typename T> inline void read(T &x){
T f=1;x=0;
char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
x*=f;
}
const int N =6e6;
int n,a[N];
pair<int,int>vis[N];
int main(){
read(n);
for(int i=1;i<=n;i++) read(a[i]);
for(int i=1;i<=n;i++){
for(int j=i+1;j<=n;j++){
int s=a[i]+a[j];
if(!vis[s].first&&!vis[s].second){
vis[s]=make_pair(i,j);
}
else{
if(vis[s].first!=i&&vis[s].second!=i&&vis[s].second!=j&&vis[s].second!=i){
puts("YES");
printf("%d %d %d %d",vis[s].first,vis[s].second,i,j);
return 0;
}
}
}
}
puts("NO");
return 0;
}
Codeforces Round #707 Editorial Div2 题解的更多相关文章
- Codeforces Round #182 (Div. 1)题解【ABCD】
Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...
- Codeforces Round #608 (Div. 2) 题解
目录 Codeforces Round #608 (Div. 2) 题解 前言 A. Suits 题意 做法 程序 B. Blocks 题意 做法 程序 C. Shawarma Tent 题意 做法 ...
- Codeforces Round #525 (Div. 2)题解
Codeforces Round #525 (Div. 2)题解 题解 CF1088A [Ehab and another construction problem] 依据题意枚举即可 # inclu ...
- Codeforces Round #528 (Div. 2)题解
Codeforces Round #528 (Div. 2)题解 A. Right-Left Cipher 很明显这道题按题意逆序解码即可 Code: # include <bits/stdc+ ...
- Codeforces Round #466 (Div. 2) 题解940A 940B 940C 940D 940E 940F
Codeforces Round #466 (Div. 2) 题解 A.Points on the line 题目大意: 给你一个数列,定义数列的权值为最大值减去最小值,问最少删除几个数,使得数列的权 ...
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #665 (Div. 2) 题解
Codeforces Round #665 (Div. 2) 题解 写得有点晚了,估计都官方题解看完切掉了,没人看我的了qaq. 目录 Codeforces Round #665 (Div. 2) 题 ...
- Codeforces Round #160 (Div. 1) 题解【ABCD】
Codeforces Round #160 (Div. 1) A - Maxim and Discounts 题意 给你n个折扣,m个物品,每个折扣都可以使用无限次,每次你使用第i个折扣的时候,你必须 ...
- Codeforces Round #383 (Div. 2) 题解【ABCDE】
Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...
随机推荐
- 在Spring Bean实例过程中,如何使用反射和递归处理的Bean属性填充?
作者:小傅哥 博客:https://bugstack.cn 沉淀.分享.成长,让自己和他人都能有所收获! <Spring 手撸专栏>目录 [x] 第 1 章:开篇介绍,我要带你撸 Spri ...
- Guava-retry,java重试组件
使用场景 在日常开发中,我们经常会遇到需要调用外部服务和接口的场景.外部服务对于调用者来说一般都是不可靠的,尤其是在网络环境比较差的情况下,网络抖动很容易导致请求超时等异常情况,这时候就需要使用失败重 ...
- GO学习-(24) Go语言操作Redis
Go语言操作Redis 在项目开发中redis的使用也比较频繁,本文介绍了Go语言中go-redis库的基本使用. Redis介绍 Redis是一个开源的内存数据库,Redis提供了多种不同类型的数据 ...
- GO学习-(3) VS Code配置Go语言开发环境
VS Code配置Go语言开发环境 VS Code配置Go语言开发环境 说在前面的话,Go语言是采用UTF8编码的,理论上使用任何文本编辑器都能做Go语言开发.大家可以根据自己的喜好自行选择.编辑器/ ...
- JAVA并发(5)-并发队列LinkedBlockingQueue的分析
本文介绍LinkedBlockingQueue,这个队列在线程池中常用到.(请结合源码,看本文) 1. 介绍 LinkedBlockingQueue, 不支持null,基于单向链表的可选有界阻塞队列. ...
- TensorFlow解析常量、变量和占位符
TensorFlow解析常量.变量和占位符 最基本的 TensorFlow 提供了一个库来定义和执行对张量的各种数学运算.张量,可理解为一个 n 维矩阵,所有类型的数据,包括标量.矢量和矩阵等都是特殊 ...
- 算法编程Algos Programming
算法编程Algos Programming 不同算法的集合,用于编程比赛,如ACM ICPC. 算法按主题划分.大多数算法都可以从文件中按原样运行.每种算法都有一个参考问题,并对其时间和空间复杂度作了 ...
- 新特性,推荐一款超强接口管理神器 Apifox
去年,在公众号给大家推荐了一款新面市不久的接口测试神器:Apifox,如果还未了解的读者,感兴趣的话可查阅原文:推荐一款技术人必备的接口测试神器:Apifox 为了照顾新进来的读者,且最近一年,Api ...
- 【题解】Luogu P3110 [USACO14DEC]驮运Piggy Back
[题解]Luogu P3110 [USACO14DEC]驮运Piggy Back 题目描述 Bessie and her sister Elsie graze in different fields ...
- system表空间
system : 1.空间,管理:字典所在,不放用户数据;一般单个数据文件即可. 如果system表空间不够大,即可设置自动扩展,或者bigfile 2.system 备份 必须归档下 才能open下 ...