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 ...
随机推荐
- 20191231--python学习第五天
1.内容回顾与补充 int类型 (1)py2与py3的区别 (2)除法 (3)强制转换 int('字符串') [重要] int(布尔值):返回的结果只有0和1 bool类型 (1)强制转换: bool ...
- pytorch之 optimizer comparison
import torch import torch.utils.data as Data import torch.nn.functional as F import matplotlib.pyplo ...
- Mysql 字符问题
先看一下mysql支持的字符范围 *数值类型:1.整形: 类型 大小 范围 ...
- Angular RxJs:针对异步数据流编程工具
一. RxJs:针对异步数据流编程工具 1. 创建subject类对象(发送方) 2. subject.subscribe(观察者); (注册观察者对象observer,可以注册多个相当于回调函数取数 ...
- drf序列化高级、自定义只读只写、序列化覆盖字段、二次封装Response、数据库查询优化(断关联)、十大接口、视图家族
目录 自定义只读 自定义只写 序列化覆盖字段 二次封装Response 数据库关系分析 断外键关联关系 ORM操作外键关系 ORM四种关联关系 基表 系列化类其他配置(了解) 十大接口 BaseSer ...
- Node.js的__dirname,__filename,process.cwd(),./的一些坑
参考博客:https://github.com/jawil/blog/issues/18
- Ubuntu下LAMP的环境配置教程
总体来说,Ubuntu下安装LAMP环境是比较简单的,只需按照命令行执行即可,记录操作以备不时之需. 一,首先更新Ubuntu里面所有的软件 sudo apt-get update 二.之后安装Apa ...
- IO流之File对象
File类: 用来将文件或者文件夹封装成对象 方便对文件与文件夹的属性等信息进行操作(因为流只能操作文件中的数据) File对象可以作为参考传递给流的构造函数 上下级文件夹之间使用分隔符分开: 在Wi ...
- Linux运维---02.制作trove-redis镜像
redis-3.2 镜像制作及验证 镜像制作 1.安装redis yum install redis yum install epl-release yum install python-pip gi ...
- c# 匿名方法(函数) 匿名委托 内置泛型委托 lamada
匿名方法:通过匿名委托 .lamada表达式定义的函数具体操作并复制给委托类型: 匿名委托:委托的一种简单化声明方式通过delegate关键字声明: 内置泛型委托:系统已经内置的委托类型主要是不带返回 ...