Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)
A. Erasing Zeroes (模拟)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
int main(){
int t;cin>>t;
while(t--){
string s;cin>>s;
bool f1 = ,f2 = ;
int cnt = ;
int ans = ;
for(int i = ;i<s.length();i++){
if(s[i] == ''){
if(f1 == ) {
ans+=cnt;
cnt = ;
f1 = ;
}
if(f1 == ) f1 = ;
}
else{
if(f1 == ) cnt++;
}
}
cout<<ans<<endl;
}
return ;
}
B. National Project (数学题 周期计算)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
int main(){
int t;cin>>t;
while(t--){
ll n,g,b;
cin>>n>>g>>b;
ll tn = n;
if(n% == ) n = n/+;
else n = n/;
if(n<=g ) {
cout<<tn<<endl;continue;
}
else{
ll t = g+b;//一个周期
ll c = n/g;//至少需要几个周期
if(n%g == ) {
if(c*t-b<tn) cout<<tn<<endl;
else cout<<c*t-b<<endl;
continue;
}
ll d = n%g;
ll ans = c*t+d;
if(ans<tn) ans+=(tn-ans);
cout<<ans<<endl;
continue;
}
// 4 1 1
}
return ;
}
C. Perfect Keyboard (dfs 图论)
#include<bits/stdc++.h>
using namespace std;
struct node{
vector<int> v;
}g[];
string ans;
int vis[];
void init(){
for(int i = ;i<;i++) g[i].v.clear(),vis[i] = ;
ans = "";
}
void dfs(int cur){
vis[cur] = ,ans+='a'+cur;
for(int i = ;i<g[cur].v.size();i++){
if(!vis[g[cur].v[i]]) dfs(g[cur].v[i]);
}
}
void solve(){
string s;
cin>>s;
init();
map<pair<int,int>,int > m;
for(int i = ;i<s.length();i++){
int a = s[i-] - 'a',b = s[i] - 'a';
if(a<b) swap(a,b);
if(m[{a,b}] == ){
m[{a,b}] = ;
g[a].v.push_back(b);
g[b].v.push_back(a);
}
}
for(int i = ;i<;i++){
if(g[i].v.size()>) {
cout<<"NO"<<endl;
return;
}
}
for(int i = ;i<;i++){
if(!vis[i] && g[i].v.size()<){
dfs(i);
}
}
if(ans.length() == ) {
cout<<"YES"<<endl;
cout<<ans<<endl;
return;
}
else{
cout<<"NO"<<endl;
}
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return ;
}
D. Fill The Bag(贪心 二进制位运算 状态压缩)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+;
const int maxBit = ;
int cnt[maxBit];
void solve(){
ll n;int m;
scanf("%lld%d",&n,&m);
memset(cnt,,sizeof(cnt));
ll sum = ;
for(int i = ;i<=m;i++) {
ll x;
scanf("%lld",&x);
sum+=x;
for(int j = ;j<=maxBit;j++){
if((x>>j)& == ) {
cnt[j+]++;
break;
}
}
}
if(sum<n) {
cout<<-<<endl;return ;
}
int ans = ;
for(int i = ;i<=maxBit;i++){
if((n>>(i-))&){
if(!cnt[i]){
int indx = -;
for(int j = i;j<=maxBit;j++){
if(cnt[j]) {
indx = j;
break;
}
}
while(indx!=i){
cnt[indx]--,cnt[indx-]+=,ans++,indx--;
}
// n^=(1<<(i-1));
}
cnt[i]--;
}
cnt[i+] += cnt[i]/;
}
cout<<ans<<endl;
}
//
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return ;
}
E. Erase Subsequences (字符串上dp)
#include<bits/stdc++.h>
using namespace std;
const int maxn = ;
int dp[maxn][maxn];
bool check(string s,string t){
int indx = ;
for(int i = ;i<s.length();i++){
if(t[indx] == s[i]) indx++;
}
if(indx == t.length()) return true;
return false;
}
bool check(string s,string t1,string t2){
memset(dp,-,sizeof(dp));
dp[][] = ;
for(int i = ;i<s.length();i++){
for(int j = ;j<=t1.size();j++){
if(dp[i][j]<) continue;
if(j<t1.size() && s[i] == t1[j]){
dp[i+][j+] = max(dp[i+][j+],dp[i][j]);
}
if(dp[i][j]<t2.size() && s[i] == t2[dp[i][j]]){
dp[i+][j] = max(dp[i+][j],dp[i][j]+);
}
dp[i+][j] = max(dp[i+][j],dp[i][j]);
}
}
if(dp[s.length()][t1.length()] == t2.length()) return true;
return false;
}
void solve(){
string s,t;
cin>>s>>t;
if(check(s,t)){
cout<<"YES"<<endl;
return;
}
for(int i = ;i<t.length()-;i++){
string t1 = t.substr(,i+);
string t2 = t.substr(i+,t.size());
if(check(s,t1,t2)){
cout<<"YES"<<endl;
return;
}
}
cout<<"NO"<<endl;
return;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return ;
}
Educational Codeforces Round 82 (Rated for Div. 2) A-E代码(暂无记录题解)的更多相关文章
- Educational Codeforces Round 82 (Rated for Div. 2)
题外话 开始没看懂D题意跳了,发现F题难写又跳回来了.. 语文好差,码力好差 A 判第一个\(1\)跟最后一个\(1\)中\(0\)的个数即可 B 乘乘除除就完事了 C 用并查集判一下联通,每个联通块 ...
- Educational Codeforces Round 82 (Rated for Div. 2)E(DP,序列自动机)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ],t[]; int n,m; ][]; ...
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
从低位到高位枚举,当前位没有就去高位找到有的将其一步步拆分,当前位多余的合并到更高一位 #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h&g ...
- [CF百场计划]#3 Educational Codeforces Round 82 (Rated for Div. 2)
A. Erasing Zeroes Description You are given a string \(s\). Each character is either 0 or 1. You wan ...
- Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship
Problem Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...
- Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)
Problem Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...
- Educational Codeforces Round 43 (Rated for Div. 2)
Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
随机推荐
- Mysql 删除从数据库的relay logs最佳方式、最安全方式
情景 MySQL数据库主从复制在默认情况下从库的relay logs会在SQL线程执行完毕后被自动删除.但是:在relay_log_purge = 0和MHA集群下,不会被自动删除,需要手动删除.如何 ...
- [Python]Bytes 和 String转换
#----string to bytes------ # 方法一:直接复制bytes类型 b'<str>' b = b'Hello World' print(type(b)) print( ...
- cesium结合geoserver实现地图空间查询(附源码下载)
前言 cesium 官网的api文档介绍地址cesium官网api,里面详细的介绍 cesium 各个类的介绍,还有就是在线例子:cesium 官网在线例子,这个也是学习 cesium 的好素材. 内 ...
- 源码浅析:InnoDB聚集索引如何定位到数据的物理位置,并从磁盘读取
索引结构概述: MyISAM索引文件和数据文件是分离的,索引文件仅保存数据记录的地址.这与Oracle的索引结构相似,比较好理解.那么,常用的Innodb聚集索引结构是怎样的呢? InnoDB的数据文 ...
- redis 5.0.7 源码阅读——字典dict
redis中字典相关的文件为:dict.h与dict.c 与其说是一个字典,道不如说是一个哈希表. 一.数据结构 dictEntry typedef struct dictEntry { void * ...
- 【算法】蓝桥杯 试题 基础练习 Huffuman树
资源限制 时间限制:1.0s 内存限制:512.0MB 问题描述 Huffman树在编码中有着广泛的应用.在这里,我们只关心Huffman树的构造过程. 给出一列数{pi}={p0, p1, …, ...
- nginx location展示及文件共享
nginx 目录展示及文件访问 效果: [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-d5G9wfKK-1570116907804)(E:\Users\FangJunX ...
- mac 15 IDA7.0 下载安装
吾爱破解上有相应的解决办法,在低版本mac上安装完成后,直接拖到15版本,再打上补丁,补丁可以自己去找,下面是转好了的,mac解压最好不要用自带的解压软件,用BetterZip试试,不行就多解压几次, ...
- 广度优先搜索BFS---求出矩阵中“块”的个数
题目: 给出一个 m x n 的矩阵,矩阵中的元素为0或1.如果矩阵中有若干个 1是相邻的,那么称这些1构成了一个“块”.求给定的矩阵中“块”的个数. 0 1 1 1 0 0 1 0 0 1 0 0 ...
- 题解【CF1311F Moving Points】
\[ \texttt{Preface} \] 赛时,把 " 任意时刻 " 理解成 " 整数时刻 " 了,看起来一脸不可做的亚子,还各种推式子. 话说我为什么觉得 ...