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的更多相关文章
随机推荐
- 由数据迁移至MongoDB导致的数据不一致问题及解决方案
故事背景 企业现状 2019年年初,我接到了一个神秘电话,电话那头竟然准确的说出了我的昵称:上海小胖. 我想这事情不简单,就回了句:您好,我是小胖,请问您是? "我就是刚刚加了你微信的 xx ...
- AcWing 240. 食物链 | 并查集
传送门 题目描述 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形. A吃B, B吃C,C吃A. 现有N个动物,以1-N编号. 每个动物都是A,B,C中的一种,但是我们并不知道它到底 ...
- 关于Element对话框组件Dialog在使用时的一些问题及解决办法
Element对话框组件Dialog在我们的实际项目开发中可以说是一个使用频率较高的组件,它能为我们展示提示的功能,如:业务模块提交前展示我们曾经输入或选择过的业务信息,或者展示列表信息中某项业务的具 ...
- 2019版Idea如何激活
1.下载jar包 链接: https://pan.baidu.com/s/1w4B4_hmiiueNDJMjYKaFyQ 提取码: fkpx 2.修改·vmoptions 1.Help" - ...
- Python思维导图(二)—— 数据类型
============================================== =========可点击图片, 放大查看更清晰哦!========= ===========有任何错误请及 ...
- ORM补充文件
models.FileField(verbose_name='头像', upload_to='avatars/') 文件 content = models.TextField() 文本 models. ...
- Java入门 - 语言基础 - 08.运算符
原文地址:http://www.work100.net/training/java-operator.html 更多教程:光束云 - 免费课程 运算符 序号 文内章节 视频 1 概述 2 算术运算符 ...
- SpringMvc简单使用
SpringMvc框架的简单使用 第一步:导入依赖 <dependencies> <dependency> <groupId>org.springframework ...
- Mysql 8+ 版本完全踩坑记录
问题是这样 刚霍霍了一台腾讯云服务器需要安装mysql 然后就选择了8+这个版本. 安装步骤网上有的是. 我只写最主要的部分 绝对不出错 外网可访问 .net java都可以调用 其实不指望有人看 就 ...
- [bzoj2152] [洛谷P2634] 聪聪可可
Description 聪聪和可可是兄弟俩,他们俩经常为了一些琐事打起来,例如家中只剩下最后一根冰棍而两人都想吃.两个人都想玩儿电脑(可是他们家只有一台电脑)--遇到这种问题,一般情况下石头剪刀布就好 ...