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. 1059 C语言竞赛 (20 分)C语言

    C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 0.冠军将赢得一份"神秘大奖"(比如很巨大的一本学生研究论文集--). 1 ...

  2. 01_垂直居中body中的应用

    1: 应用场景 在body中书写一个代码块, 使其相对于body垂直居中 <!DOCTYPE html> <html lang="en"> <head ...

  3. 为云而生,腾讯云服务器操作系统TencentOS内核正式开源

    ​1月9日,腾讯云宣布将开源其服务器操作系统TencentOS内核.相比业内其它版本Linux 内核,腾讯云 TencentOS 内核在资源调度弹性.容器支持.系统性能及安全等层面极具竞争力,特别适合 ...

  4. Java 发展简史:初生遇低谷,崛起于互联网

    Java 起源与诞生 20世纪90年代,单片式计算机系统诞生,单片式计算机系统不仅廉价,而且功能强大,使用它可以大幅度提升消费性电子产品的智能化程度. SUN公司为了抢占市场先机,在1991年成立了一 ...

  5. Sample Code之Take a screenshot of a SceneView

    周末事情太多了,以后就工作日发布随笔吧.周末的话,看心情,也许也会发~ 今天的实例代码解析是Take a screenshot of a SceneView,也就是获取快照,话不多说,进入正题. 首先 ...

  6. Java 中的四种权限修饰符

    * * private: * Java语言中对访问权限限制的最窄的修饰符,一般称之为“私有的”. * 被其修饰的属性以及方法只能被该类的对象 访问,其子类不能访问,更不能允许跨包访问. * * def ...

  7. NetCore下的log4

    https://www.cnblogs.com/zhangxiaoyong/p/9463791.html 这一篇也不错 .NET常用的日志组件有NLog.Log4net等,.NET CORE下微软也自 ...

  8. windows环境下使用python3.x自带的CGI服务器测试cgi脚本(转)

    1.在桌面上新建一个文件夹作为服务器目录文件夹(文件夹名称自定义,文件夹位置自定义),在www文件下再建一个文件夹,文件夹名为“cgi-bin”,须是这个文件名,其他试过不行(原因暂时未知)

  9. 各种反弹shell方法总结

    获取shell的方法总结: shell分为两种,一种是正向shell,另一种是反向shell.如果客户端连接服务器,客户端主动连接服务器,就称为正向shell.如果客户端连接服务器,服务器想要获得客户 ...

  10. jmeter使用—计数器的使用

    说一下jmeter中,配置元件-计数器的使用. 如果需要引用的数据量较大,且要求不能重复或者需要自增,那么可以使用计数器来实现. 1.启动jmeter,添加线程组,右键添加配置元件——计数器,如下图: ...