Codeforces Educational Round 81 解题报告
前置扯淡
赛前:这场\(Div2\)呀,那我写\(3\)题就行,\(D\)题尽力就好
赛中:啊啊,\(ABC\)我全过了\(pretest\),我太强了!!这把上蓝稳了
赛后:\(woc\),为啥被\(hack\)了两道!!\(newbie\) \(yspm\)认证成功了……
题目&&解答
A.Display The Number
思路
水题一道,直接\(1\)和\(7\)随便输出就行
CODE
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
inline void work()
{
int x=read(); if(x%2==0) while(x) cout<<1,x-=2;
else{cout<<7; x-=3; while(x) cout<<1,x-=2;}
return cout<<endl,void();
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
}
signed main(){return yspm::main(); }
B.Infinite Prefixes
思路
这个题细节有一点点多
预处理出来\(s\)串中每一个前缀的\(0\)和\(1\)的差值,记为\(a[\space ]\)
看\(a[s.length()]\)的值
\(1^0\) 如果为\(0\),就考虑正无穷的情况
如果有一个\(a_i\)的值与\(x\)相同,就直接为正无穷,否则为\(0\)
\(2^0\) 如果不为\(0\),就考虑同余
当前位置的\(a[\space]\)值和\(x\)是否关于\(a[s.length()]\)同余即可
还要注意正负性
CODE
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=1e5+10;
int a[N],n,x; string s;
inline void work()
{
a[0]=0; n=read(); x=read(); cin>>s;
for(int i=0;i<n;++i)
{
if(s[i]=='0') a[i+1]=a[i]+1;
else a[i+1]=a[i]-1;
}
int p=a[n];
if(!p)
{
for(int i=1;i<=n;++i)
{
if(a[i]==x) return puts("-1"),void();
}puts("0");
}
else
{
int ans=(x==0);
for(int i=1;i<=n;++i)
{
if((x-a[i])*p>=0&&(x-a[i])%p==0) ++ans;
} printf("%lld\n",ans);
}
return ;
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
}
signed main(){return yspm::main(); }
这个题当时没有想到怎么处理正负性,这个乘积与\(0\)的大小关系还是可以进行频繁利用的
C. Obtain The String
思路
其实就是一个简单的模拟,里面套了一个\(upper_bound\)(或者说二分)
预处理\(s\)中每一个字母出现的位置(开\(26\)个\(vector\)),每一次直接模拟\(t\)中的字母,记录最后出现的位置\(las\)
1.如果当前\(t\)中的字母\(s\)中没有,就直接\(puts("-1")\)
2.就直接二分\(las\)后该字母出现的第一个位置,更新\(las\)的值,如果没有了就\(++ans\),\(las\)为该字母第一个出现位置(结论由简单贪心直接成立)
CODE
#include<bits/stdc++.h>
using namespace std;
#define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k=='-') f=-1;
while(isdigit(k)) res=res*10+k-'0',k=getchar();
return res*f;
}
const int N=1e5+10;
vector<int> vec[26];
string s,t;
int ls,lt,ans;
inline void work()
{
cin>>s>>t; for(int i=0;i<26;++i) vec[i].clear(); ans=1;
ls=s.length(); lt=t.length();
for(int i=1;i<=ls;++i) vec[s[i-1]-'a'].push_back(i-1);
int las=-1;
for(int i=0;i<lt;++i)
{
int tmp=t[i]-'a';
if(vec[tmp].empty()){return puts("-1"),void();}
if(vec[tmp].back()<=las)++ans,las=vec[tmp].front();
else las=vec[tmp][upper_bound(vec[tmp].begin(),vec[tmp].end(),las)-vec[tmp].begin()];
}
return cout<<ans<<endl,void();
}
signed main()
{
int T=read(); while(T--) work();
return 0;
}
}
signed main(){return yspm::main(); }
D.Same GCDs
Solution
E.Permutation Separation
Solution
F.Good Contest
Solution
这个题被吐槽为跟\(APIO2016\) 划艇那道有一点像
光看题目描述真的非常像
但是做法还是不很会,留坑待填
Codeforces Educational Round 81 解题报告的更多相关文章
- Codeforces Global Round 1 解题报告
A 我的方法是: #include<bits/stdc++.h> using namespace std; #define int long long typedef long long ...
- Codeforces Educational Round 92 赛后解题报告(A-G)
Codeforces Educational Round 92 赛后解题报告 惨 huayucaiji 惨 A. LCM Problem 赛前:A题嘛,总归简单的咯 赛后:A题这种**题居然想了20m ...
- Codeforces Educational Round 33 题解
题目链接 Codeforces Educational Round 33 Problem A 按照题目模拟,中间发现不对就直接输出NO. #include <bits/stdc++.h> ...
- [CodeForces]Educational Round 52
幸好我没有打这场,我VP的时候在C题就卡死了,我果然还是太菜了. A Vasya and Chocolate 题意:一个巧克力\(c\)元,买\(a\)赠\(b\),一共有\(n\)元,问能买几个巧克 ...
- Codeforces Round #300 解题报告
呜呜周日的时候手感一直很好 代码一般都是一遍过编译一遍过样例 做CF的时候前三题也都是一遍过Pretest没想着去检查... 期间姐姐提醒说有Announcement也自信不去看 呜呜然后就FST了 ...
- Codeforces Round #513解题报告(A~E)By cellur925
我是比赛地址 A:Phone Numbers $Description$:给你一串数字,问你能组成多少开头为8的11位电话号码. $Sol$:统计8的数量,与$n$%11作比较. #include&l ...
- Codeforces Round #302 解题报告
感觉今天早上虽然没有睡醒但是效率还是挺高的... Pas和C++换着写... 544A. Set of Strings You are given a string q. A sequence o ...
- Codeforces Round #301 解题报告
感觉这次的题目顺序很不合理啊... A. Combination Lock Scrooge McDuck keeps his most treasured savings in a home sa ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
随机推荐
- springboot入门学习1
springboot学习1 SpringBoot对Spring的缺点进行的改善和优化,基于约定优于配置的思想,可以让开发人员不必在配置与逻辑 业务之间进行思维的切换,全身心的投入到逻辑业务的代码编写中 ...
- Mac 用终端(命令行)打开vscode编辑器
1.打开控制面板(⇧⌘P) 2.输入 shell command 在提示里看到 Shell Command: Install ‘code’ command in PATH, 就可以了. 3.使用: c ...
- torch文档学习笔记
下面为官方文档学习笔记 http://pytorch.org/docs/0.3.0/index.html 1.torch.Tensor from __future__ import print_ ...
- 连接数据库方法2-DBCP
DBCP(连接池): 解决对数据库建立以及关闭连接时消耗大量资源的解决方案. 程序创建和关闭对数据库连接时会消耗大量的资源,连接池技术帮我们 在程序运行的开始时就预先创建大量的连接,这些连接组成一个池 ...
- 字符串处理 - ANSI - Unicode - UTF8 转换
#include <stdio.h> #include <windows.h> #include <locale.h> #define BUFF_SIZE 1024 ...
- 浅入深出Java输入输出流主线知识梳理
Java把不同类型的输入.输出,这些输入输出有些是在屏幕上.有些是在电脑文件上, 都抽象为流(Stream) 按流的方向,分为输入流与输出流,注意这里的输出输出是相对于程序而言的,如:如对于一个J ...
- Python连接Oracle问题
Python连接Oracle问题 1.pip install cx_oracle 2.会出现乱码问题: 方法一:配置环境变量 export NLS_LANG="SIMPLIF ...
- github访问过慢解决
为了更加愉快地使用全球最大同性交友网站上的优质资源,我们来做一些简单的本机上的调整. 通过查看下载链接,能够发现最终被指向到Amazon的服务器(http://github-cloud.s3.amaz ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习: DOM
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- idea创建远程分支
1.先从远程拉取一个完整的分支,master或dev 2.新建一个分支,new,新建的同时checkout 出来 3.把新建的分支push到远程 4.如果新建完分支后写代码了,需要先把代码提交然后一起 ...