A.两个方向都判断。

#include<bits/stdc++.h>
using namespace std; string s1,s2;
map<char,int> mp;
int n; int main()
{
ios::sync_with_stdio();
mp['v'] = ;
mp['<'] = ;
mp['^'] = ;
mp['>'] = ;
cin >> s1 >> s2 >> n;
int x = mp[s1[]],y = mp[s2[]];
n %= ;
if((x+n)% == y && (x-n+)% == y) cout << "undefined" << endl;
else if((x+n)% == y) cout << "cw" << endl;
else cout << "ccw" << endl;
return ;
}

B.统计每个字母首位,前缀和。

#include<bits/stdc++.h>
using namespace std; string s;
map<char,int> l,r;
int n,k,sum[]; int main()
{
ios::sync_with_stdio();
cin >> n >> k >> s;
s = ' '+s;
for(int i = ;i <= n;i++) r[s[i]] = i;
for(int i = n;i >= ;i--) l[s[i]] = i;
for(char c = 'A';c <= 'Z';c++)
{
sum[l[c]]++;
sum[r[c]+]--;
}
int maxx = ;
for(int i = ;i <= n;i++)
{
sum[i] += sum[i-];
maxx = max(maxx,sum[i]);
}
if(maxx > k) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}

C.只要ab是某个数的三次方,并且a和b能整除(ab)^1/3。打表map预处理开三次方。

#include<bits/stdc++.h>
using namespace std; map<long long,int> mp;
int n;
long long a,b; int main()
{
ios::sync_with_stdio();
for(long long i = ;i <= ;i++) mp[i*i*i] = i;
scanf("%d",&n);
while(n--)
{
scanf("%d%d",&a,&b);
long long t = a*b;
if(mp.count(t))
{
long long tt = mp[t];
if(a%tt == && b%tt == ) printf("Yes\n");
else printf("No\n");
}
else printf("No\n");
}
return ;
}

D.线段树更新dp。对于每一个位置,找前面最后一个相同数字的位置,将这一段的值都加一。

#include<bits/stdc++.h>
using namespace std; int n,k,a[],pre[] = {},lastt[] = {},dp[]; struct xx
{
int l,r,x,lazy;
}tree[*]; void pushup(int pos)
{
tree[pos].x = max(tree[pos<<].x,tree[pos<<|].x);
} void pushdown(int pos)
{
if(tree[pos].lazy)
{
int t = tree[pos].lazy;
tree[pos<<].x += t;
tree[pos<<|].x += t;
tree[pos<<].lazy += t;
tree[pos<<|].lazy += t;
tree[pos].lazy = ;
}
} void build(int pos,int l,int r)
{
tree[pos].l = l;
tree[pos].r = r;
tree[pos].lazy = ;
if(l >= r)
{
tree[pos].x = dp[l];
return;
}
int mid = (l+r)/;
build(pos<<,l,mid);
build(pos<<|,mid+,r);
pushup(pos);
} void update(int pos,int l,int r)
{
if(l <= tree[pos].l && tree[pos].r <= r)
{
tree[pos].x++;
tree[pos].lazy++;
return;
}
pushdown(pos);
int mid = (tree[pos].l+tree[pos].r)/;
if(l <= mid) update(pos<<,l,r);
if(r > mid) update(pos<<|,l,r);
pushup(pos);
} int query(int pos,int l,int r)
{
if(l <= tree[pos].l && tree[pos].r <= r) return tree[pos].x;
pushdown(pos);
int mid = (tree[pos].l+tree[pos].r)/;
if(r <= mid) return query(pos<<,l,r);
if(l > mid) return query(pos<<|,l,r);
return max(query(pos<<,l,r),query(pos<<|,l,r));
} int main()
{
ios::sync_with_stdio();
cin >> n >> k;
memset(lastt,-,sizeof(lastt));
int cnt = ;
for(int i = ;i <= n;i++)
{
cin >> a[i];
pre[i] = lastt[a[i]];
lastt[a[i]] = i;
if(pre[i] == -) cnt++;
dp[i] = cnt;
}
for(int kk = ;kk <= k;kk++)
{
build(,,n);
for(int i = kk;i <= n;i++)
{
update(,max(,pre[i]),i-);
dp[i] = query(,,i-);
}
}
cout << dp[n] << endl;
return ;
}

Codeforces_834的更多相关文章

随机推荐

  1. Python库的安装(Windows/Linux通用)

    pip安装 最简单的安装方式,自动下载并安装. pip:包管理工具 安装步骤 执行安装命令:pip install <package_name> wheel安装 在网速较差的情况下适用. ...

  2. React实现座位排布组件

    React实现座位排布组件 最近在开发一个影院系统的后台管理系统,该后台可以设置一个影厅的布局. 后台使用的是react框架,一位大神学长在几天之内就把这个控件研究出来了,并进行了较为严密的封装,佩服 ...

  3. JPA或Hibernate中使用原生SQL实现分页查询、排序

    发生背景:前端展示的数据需要来自A表和D表拼接,A表和D表根据A表的主键进行关联,D表的非主键字段关联C表的主键,根据条件筛选出符合的数据,并且根据A表的主键关联B表的主键(多主键)的条件,过滤A表中 ...

  4. 关于ECShop4.0安装时数据库报错问题解决

    是ECShop版本的问题,重点在$db_host不能带端口号,把这个文件 ecshop4\ecshop\install\includes\lib_installer.php 里面3处db_host开头 ...

  5. 基于Netty和SpringBoot实现一个轻量级RPC框架-Server篇

    前提 前置文章: Github Page:<基于Netty和SpringBoot实现一个轻量级RPC框架-协议篇> Coding Page:<基于Netty和SpringBoot实现 ...

  6. docker 批量删除 镜像 容器

    我们在docker构建和测试时,经常会产生很多无用的镜像或者容器,我们可用如下两条命令一个一个删除. docker container rm 容器id #删除容器 可简写: docker rm 容器i ...

  7. springboot2 + grpc

    项目情况: springboot: 2.2.2 grpc-spring-boot-starter: 2.6.1.RELEASE 项目目录: mypro: - person  - grpc服务端 - l ...

  8. python列表(数组)

    列表(list)  就是 数组 - 列表是Python中的一个对象 - 对象(object)就是内存中专门用来存储数据的一块区域 - 之前我们学习的对象,像数值,它只能保存一个单一的数据 - 列表中可 ...

  9. Django admin的常用方法

    一.HTTP 1.主页面 http://127.0.0.1:8000/admin/ 2.查询页面 http://127.0.0.1:8000/admin/app01/book/ 3.增加页面 http ...

  10. 异步查询转同步加redis业务实现的BUG分享

    在最近的性能测试中,某一个查询接口指标不通过,开发做了N次优化,最终的优化方案如下:异步查询然后转同步,再加上redis缓存.此为背景. 在测试过程中发现一个BUG:同样的请求在第一次查询结果是OK的 ...