Codeforces_834
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的更多相关文章
随机推荐
- SpringBoot集成Mybatis动态多数据源后,MybatisPlus的IPage失效的问题解决方案
背景 之前做数据抽取的时候,搭了一个mybatis动态数据源切换的架子.方便他们写抽取的代码.今天同事问我,架子里面的mybatisplus的IPage失效了是什么问题.想了一下,应该是写动态数据源的 ...
- 【转】python中查询某个函数的使用方法
使用help(),例查询sum函数的用法 使用官方文档: 1)打开python的IDLE: 2)点击help,选择python doc(这是python的官方文档,或者你也可以直接按f1键) 3)在调 ...
- 基于Arduino的按键控制LED实验
I/O 口的意思即为INPUT 接口和OUTPUT 接口,到目前为止我们设计的小灯实验都还只是应用到Arduino 的I/O 口的输出功能,这个实验我们来尝试一下使用Arduino的I/O 口的输入功 ...
- Java虚拟机OOM问题和四大引用问题简述
一.请你谈谈实际的项目中在Java虚拟机会抛出哪些异常,每个异常都是怎么产生的? 1.java.lang.StackOverflowError 栈空间满了 public static void sta ...
- 初级程序员如何一分钟?解决一个BUG
博主说明 -- 重要.重要.重要的事情说三遍 写这篇文章是主要锻炼写博客的能力以及记录自己的成长经历,要是写的不对欢迎大佬评论指正,同时希望对大家有所帮助.然后我写博客尽量简洁+图片+宏观的方式,便于 ...
- GDAl C++ 创建Shp
用于GDAL,C++开发环境测试. #include <iostream> #include "gdal_priv.h" #include "ogrsf_fr ...
- Sql Server学习笔记
1.指定路径创建数据库 create database student on--创建库的时候必须写 ( name=student, filename='E:\database\student.mdf' ...
- Go的内存对齐和指针运算详解和实践
uintptr 和 unsafe普及 uintptr 在Go的源码中uintptr的定义如下: /* uintptr is an integer type that is large enough t ...
- vue学习笔记3: 动态绑定
一.知识点 动态绑定: vue-class: 三目写法 对象写法 数组写法 vue-style: 三目写法 对象写法 数组写法 二.代码示例 1. vue-class vue-class三目写法 &l ...
- redis 其他操作
1.设定服务端密码 1.1.编辑 redis的配置文件 [root@centos7 ~]# vim /usr/local/redis/etc/redis.conf requirepass 123 # ...