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. Kubernetes资源与对象简述

    资料 k8s基本对象概念 背景 资源和对象   Kubernetes 中的所有内容都被抽象为"资源",如 Pod.Service.Node 等都是资源."对象" ...

  2. Spring Boot 集成 Seata 解决分布式事务问题

    seata 简介 Seata 是 阿里巴巴2019年开源的分布式事务解决方案,致力于在微服务架构下提供高性能和简单易用的分布式事务服务.在 Seata 开源之前,Seata 对应的内部版本在阿里内部一 ...

  3. input 只允许输入小数

    oninput = "value=value.replace(/[^\d]/g,'')" 输入浮点数不好使 突发奇想自己写一个与众不同的... oninput="valu ...

  4. 【转】oracle条件子句执行顺序

    Oracle WHERE条件执行顺序:ORACLE采用自下而上的顺序解析WHERE子句 1.据此那些可以过滤掉最大数量记录的条件必须写在WHERE子句的末尾例如:SELECT … FROM EMP E ...

  5. python 面向对象的内置方法

    要求:了解即可,能用最好 """ 1.print(obj), str(obj), %s % (obj), 都调用obj.__str__()方法,若类中没有找__repr_ ...

  6. 「 从0到1学习微服务SpringCloud 」09 补充篇-maven父子模块项目

    系列文章(更新ing): 「 从0到1学习微服务SpringCloud 」06 统一配置中心Spring Cloud Config 「 从0到1学习微服务SpringCloud 」07 RabbitM ...

  7. java"小心机"(1)【资源彩蛋!】

    每天进步一点点,距离大腿又近一步! 阅读本文大概需要9分钟 java"小心机"系列文章在此开篇.在这,将会给你带来曾经错过.忽略或感到模糊的知识,也许它很基础,微不足道,但它能修复 ...

  8. Error connecting to the Service Control Manager: 拒绝访问 Mongodb问题-解决

    原文地址:https://blog.csdn.net/carrot5032/article/details/74742888 发现在mongodb.log里出现  2017-07-07T17:01:5 ...

  9. 大叔 Frameworks.Entity.Core 3 Predicate

    Frameworks.Entity.Core\Commons\Predicate\ 1LinqEntity.cs /// IQueryable扩展方法:条件过滤与排序功能    /// Modify ...

  10. 51Nod 2026 Gcd and Lcm

    题目传送门 分析: 开始玩一个小小的trick 我们发现\(f(n)=\sum_{d|n}\mu(d)\cdot d\)是一个积性函数 所以: \(~~~~f(n)=\prod f(p_i^{a_i} ...