Codeforces Round #595 (Div. 3) 题解
前言
大家都在洛谷上去找原题吧,洛谷还是不错的qwq
A
因为没有重复的数,我们只要将数据排序,比较两两之间有没有\(a_j - a_i == 1 (j > i)\) 的,有则输出 \(2\) , 无则输出 \(1\)
普及T1难度
Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define N 107
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
int q,n,ans;
int a[N];
void work() {
memset(a, 0, sizeof(a));
n = read();
for(int i=1;i<=n;++i)
a[i] = read();
sort(a+1, a+1+n);
bool flag = 1;
for(int i=1;i<=n-1;++i) {
if(a[i+1]-a[i] == 1) flag = 0;
}
if(flag) puts("1");
else puts("2");
}
int main()
{
q = read();
while(q--) {
work();
}
return 0;
}
B
通过模拟样例我们可以发现序列上有一些环 (这个很好理解吧?拿出纸笔画画qwq)
先预处理一下每个环的长度,和每个点所在环
然后直接输出即可
普及T2?
Code
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
const int N = 2e5+7;
int n,q,tot;
int p[N],color[N],cnt[N];
void work() {
memset(color, 0, sizeof(color));
tot = 0;
n = read();
for(int i=1;i<=n;++i)
p[i] = read();
for(int i=1,j,sum;i<=n;++i) {
if(!color[i]) {
color[i] = ++tot;
j = p[i], sum = 1;
while(j != i) j = p[j], ++sum, color[j] = tot;
cnt[tot] = sum;
}
}
for(int i=1;i<=n;++i)
printf("%d ",cnt[color[i]]);
putchar('\n');
}
int main()
{
q = read();
while(q--) work();
return 0;
}
C
先把十进制转换为三进制
如 \(17\) -> \(1\) \(2\) \(2\)
从左往右数发现第二位有一个 "\(2\)",
再找 "2" 的前面出现的第一个 "\(0\)" ,把它改为 "\(1\)",如果前面没有 "\(0\)" 了,我们就加一位 (->\(1\) \(1\) \(2\) \(2\)) (第四位是改动的位置)
再从改动的位置向下把它下面的每一位改为 "\(0\)" (->\(1\) \(0\) \(0\) \(0\)) ,这个数我们就找到了
想一想,这样做为什么是对的?
∵ 我们要消除 "\(2\)" ∴ 最高位上的 "\(2\)" 是一定要消去的
∴ 找到比这个 "\(2\)" 高的最近的一位 "0" ,把它改为 "\(1\)" ,相当于进了一位,故把后面所有的数改为 "\(0\)"
提高 Day1T1 难度?
Code
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#define int long long
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
int n,q;
void work() {
vector<int> num;
n = read(); int t = n;
while(n) num.push_back(n%3), n/=3;
int x = -1LL;
for(int i=num.size()-1;i>=0;--i)
if(num[i] == 2) {
x = i; break;
}
if(x == -1LL) printf("%lld\n",t);
else {
num.push_back(0);
for(int i=x+1;i<num.size();++i)
if(!num[i]) {
num[i] = 1;
for(int j=i-1;j>=0;--j) num[j] = 0LL;
break;
}
x = 0LL;
for(int i=num.size()-1;i>=0;--i) x = (x*3) + num[i];
printf("%lld\n",x);
}
}
signed main()
{
q = read();
while(q--) work();
return 0;
}
D
USACO原题 如果考场上快点看了这题就好了
如果用贪心+线段树思路是比较简单的。
线段树做两个事情:1.查询区间最大值(当前区间被线段覆盖得最多的这个点,判断是否还能继续加,不能就说明这条边要删去,计入答案)。2.区间加上一个值(如果这个区间加入一条线段,区间的每个点加一)
这个还是比较好理解的吧
纯贪心有点神仙,我不会qwq
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstdio>
#include<cmath>
using namespace std;
inline int read() {
int x=0,f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+(ch^48); ch=getchar(); }
return x * f;
}
const int N = 2e5+7;
int n,k,ans;
vector<int> v;
struct Node {
int l,r,id;
}a[N];
struct Segment_Tree {
int mx[N<<2],lazy[N<<2];
inline int ls(int p) { return p<<1; }
inline int rs(int p) { return p<<1|1; }
inline void push_up(int p) { mx[p] = max(mx[ls(p)], mx[rs(p)]); }
inline void fl(int p,int x) { lazy[p] += x; mx[p] += x; }
inline void push_down(int p) {
fl(ls(p),lazy[p]); fl(rs(p),lazy[p]); lazy[p] = 0;
}
void update(int nl,int nr,int p,int l,int r,int x) {
if(nl<=l && r<=nr) {
fl(p,x); return ;
}
int mid = (l+r)>>1;
if(nl<=mid) update(nl,nr,ls(p),l,mid,x);
if(nr>mid) update(nl,nr,rs(p),mid+1,r,x);
push_up(p);
}
int Query(int ql,int qr,int p,int l,int r) {
if(ql<=l && r<=qr) return mx[p];
int mid = (l+r)>>1, res = 0;
push_down(p);
if(ql<=mid) res = max(res, Query(ql,qr,ls(p),l,mid));
if(qr>mid) res = max(res, Query(ql,qr,rs(p),mid+1,r));
return res;
}
}T;
bool cmp(Node x,Node y) {
return x.r < y.r;
}
int main()
{
n = read(), k = read(); int m = 0;
for(int i=1;i<=n;++i)
a[i].l = read(), a[i].r = read(), m = max(m,a[i].r), a[i].id = i;
sort(a+1, a+1+n, cmp);
for(int i=1;i<=n;++i) {
int l = a[i].l, r = a[i].r;
int maxx = T.Query(l,r,1,1,m);
if(k-maxx>=1) {
T.update(l,r,1,1,m,1);
} else {
v.push_back(a[i].id);
}
}
printf("%d\n",(int)v.size());
for(int i=0;i<v.size();++i)
printf("%d ",v[i]);
return 0;
}
E
F
Codeforces Round #595 (Div. 3) 题解的更多相关文章
- 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 题解 直接 ...
随机推荐
- 查看Oracle数据库中的执行计划
1.set autotrace traceonly命令 2.explain plan for命令 1)explain plan for select * from dual; 2)select * f ...
- duliu题之狼抓兔子题解
拖了将近5天的正解和AC.........emmmmm........... 事实告诉我们这种毒瘤题一定要建双向边(用了不知道多少个小时质疑建边的人欲哭无泪) 心态爆炸的传送 题了个面 这是个求最小割 ...
- 三十七、python中的logging介绍
A.单文件日志 import logging#定义日志文件#文件格式logging.basicConfig(filename='log.log', format='%(asctime)s-%(name ...
- Linux随笔 - vi/vim 编辑器显示行号
显示行号 1. 打开vi 编辑器 2. 输入 :set number 3. 回车 关闭行号显示 1. 打开vi 编辑器 2. 输入 :set nonumber 3. 回车 行号在每次打开 vi/v ...
- 011-elasticsearch5.4.3【四】-聚合操作【二】-桶聚合【bucket】过滤、嵌套、反转、分组、排序、范围
一.概述 bucketing(桶)聚合:划分不同的“桶”,将数据分配到不同的“桶”里.非常类似sql中的group语句的含义. metric既可以作用在整个数据集上,也可以作为bucketing的子聚 ...
- 013-Spring Boot web【二】静态资源、Servlet、Filter、listenter
一.静态资源 1.1.webapp默认支持静态资源 在src/main/webapp下建立user.html默认支持访问 1.2.默认内置静态资源目录.可被直接访问 查看包:spring-boot-a ...
- astype()函数
1astype()函数可用于转化dateframe某一列的数据类型 如下将dateframe某列的str类型转为int,注意astype()没有replace=True的用法,想要在原数据上修改,要写 ...
- 深入理解任何Binder Client都可以直接通过ServiceManager的0这个Binder句柄创建一个BpBinde
ServiceManager是安卓中一个重要的类,用于管理所有的系统服务,维护着系统服务和客户端的binder通信.对此陌生的可以先看系统服务与ServiceManager来了解应用层是如何使用Ser ...
- 【ABAP系列】SAP ABAP WS_DELIVERY_UPDATE 修改数量、过账日期并发货过账
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP WS_DELI ...
- TensorFlow学习笔记7-深度前馈网络(多层感知机)
深度前馈网络(前馈神经网络,多层感知机) 神经网络基本概念 前馈神经网络在模型输出和模型本身之间没有反馈连接;前馈神经网络包含反馈连接时,称为循环神经网络. 前馈神经网络用有向无环图表示. 设三个函数 ...