A.模拟,注意单人的时候判断顺序。

#include<bits/stdc++.h>
using namespace std; int n,a,b; int main()
{
ios::sync_with_stdio();
cin >> n >> a >> b;
int b1 = b,b2 = ,ans = ;
for(int i = ;i <= n;i++)
{
int x;
cin >> x;
if(x == )
{
if(a) a--;
else if(b1)
{
b1--;
b2++;
}
else if(b2) b2--;
else ans++;
}
else
{
if(b1) b1--;
else ans += ;
}
}
cout << ans << endl;
return ;
}

B.对于每个B点,更新最极端边界,确定最后的长宽,注意不用涂和不成立的情况。

#include<bits/stdc++.h>
using namespace std; int n,m;
string s[]; int main()
{
ios::sync_with_stdio();
cin >> n >> m;
for(int i = ;i <= n;i++)
{
cin >> s[i];
s[i] = ' '+s[i];
}
int l = ,r = ,h = ,d = ,cnt = ;
for(int i = ;i <= n;i++)
{
for(int j = ;j <= m;j++)
{
if(s[i][j] == 'W') continue;
cnt++;
l = min(l,j);
r = max(r,j);
h = max(h,i);
d = min(d,i);
}
}
int ans = max(r-l+,h-d+);
if(ans <= )
{
cout << << endl;
return ;
}
if(ans > n || ans > m)
{
cout << - << endl;
return ;
}
cout << ans*ans-cnt << endl;
return ;
}

C.对于每一个串,选择更后面的起点更新。

#include<bits/stdc++.h>
using namespace std; char a[] = "";
int n; int main()
{
ios::sync_with_stdio();
cin >> n;
int len = ;
while(n--)
{
string s;
int x,now = ;
cin >> s >> x;
while(x--)
{
int xx;
cin >> xx;
int i = max(now,xx);
for(int j = i-xx;j < s.length();i++,j++)
{
len = max(len,i);
a[i] = s[j];
}
now = max(now,i);
}
}
for(int i = ;i <= len;i++)
{
if(a[i]) cout << a[i];
else cout << 'a';
}
cout << endl;
return ;
}

D.从一点个拉出k条链来,每条链长度尽可能相等。

#include<bits/stdc++.h>
using namespace std; int n,k; int main()
{
ios::sync_with_stdio();
cin >> n >> k;
int t = n-k-;
if(t%k == ) cout << +t/k* << endl;
else if(t%k == ) cout << +t/k*+ << endl;
else cout << +t/k*+ << endl;
int i;
for(i = n-;i >= max(n-k,);i--) cout << n << " " << i << endl;
for(;i >= ;i--) cout << i+k << " " << i << endl;
return ;
}

E.因为询问的串长最多为10,我们可以每个字母对应的长度都开个树状数组。

#include<bits/stdc++.h>
using namespace std; string s;
int q,tree[][][][] = {};
map<char,int> mp; inline int lowbit(int x)
{
return x&-x;
} void add(int x,int y,int z,int pos,int xx)
{
while(pos < s.length())
{
tree[x][y][z][pos] += xx;
pos += lowbit(pos);
}
} int getsum(int x,int y,int z,int pos)
{
int sum = ;
while(pos > )
{
sum += tree[x][y][z][pos];
pos -= lowbit(pos);
}
return sum;
} int main()
{
ios::sync_with_stdio();
cin >> s >> q;
s = ' '+s;
mp['A'] = ;
mp['G'] = ;
mp['C'] = ;
mp['T'] = ;
for(int i = ;i < s.length();i++)
{
for(int j = ;j <= ;j++) add(mp[s[i]],i%j,j,i,);
}
while(q--)
{
int x;
cin >> x;
if(x == )
{
string ss;
cin >> x >> ss;
for(int i = ;i <= ;i++) add(mp[s[x]],x%i,i,x,-);
for(int i = ;i <= ;i++) add(mp[ss[]],x%i,i,x,);
s[x] = ss[];
}
else
{
int l,r;
string ss;
cin >> l >> r >> ss;
int sum = ;
for(int i = ;i < ss.length()&&l+i <= r;i++) sum += getsum(mp[ss[i]],(l+i)%ss.length(),ss.length(),r)-getsum(mp[ss[i]],(l+i)%ss.length(),ss.length(),l-);
cout << sum << endl;
}
}
return ;
}

Codeforces_828的更多相关文章

随机推荐

  1. 小小知识点(二十七)20大5G关键技术

    5G网络技术主要分为三类:核心网.回传和前传网络.无线接入网. 核心网 核心网关键技术主要包括:网络功能虚拟化(NFV).软件定义网络(SDN).网络切片和多接入边缘计算(MEC). 1 网络功能虚拟 ...

  2. Groovy重载操作符

    重载一时爽,一直重载一直爽. 最近在读<Groovy in action>一本书重新复习了Groovy的一些语法特性,迷恋上这个重载操作符的功能,坚持爽的不要要的.分享一个Demo. 由于 ...

  3. 2017CCPC杭州(ABCDJ)

    所有的题目在这里<--- 待补... Problem A. HDU6264:Super-palindrome 题意: 题目定义了一个超级回文串,这个串满足:它的任一奇数长度的串都是回文串. 现在 ...

  4. 如何添加.pch文件

    1.Create a pch , call name is project+xxx.pch For example: DuoME-PrefixHeader.pch 2.在project——>Bu ...

  5. VSCode前端 插件

    https://www.cnblogs.com/karthuslorin/p/8577224.html

  6. SpringMvc简单使用

    SpringMvc框架的简单使用 第一步:导入依赖 <dependencies> <dependency> <groupId>org.springframework ...

  7. tomcat启动时检测到循环继承而栈溢出的问题:Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/test] due to a StackOverflowError. Possible root causes include

    最近在公司更新一个老项目的时候,发现部署项目后tomcat报错,错误如下: Caused by: java.lang.IllegalStateException: Unable to complete ...

  8. java异步调用方法

    一.利用多线程 直接new线程 Thread t = new Thread(){ @Override public void run() { longTimeMethod(); } }; 使用线程池 ...

  9. Mybatis基础(一)

    mybatis概述: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis ...

  10. ArcGIS10.2安装教程

    1,首先要下载Arcgis 10.2软件,很大大约有2个多G.下载后分别全部解压. 2,首先,安装相应的LicenseManager,双击Arcgis 10.2打开安装界面,选择安装. 3,开始安装L ...