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 ...
随机推荐
- ng-repeat动态生成的DOM如何获取宽度(封装好的方法)
define(['custom/bootstrapApp'],function(app){ app.filter('getTabWidth',function(){ return function(a ...
- 很多内容是转载或copy各个大佬的
很多内容是转载或copy各个大佬的
- idea自定义模版
点小灯 编辑live模版设置 模版全称 private static final Logger logger = LoggerFactory.getLogger($classname$.class); ...
- 实验吧Web-易-天网管理系统(php弱类型,==号)
打开网页,查看源码,看到 <!-- $test=$_GET['username']; $test=md5($test); if($test=='0') --> 说明用户名需要加密之后为0. ...
- mysql 如何删除数据库中所有的表
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')FROM information_schema.tablesWHERE table_sch ...
- sql优化从300秒到7秒
原始sql select b.jd 街道,b.rglm 楼宇,zzrl 楼宇编号,count(oname) 入楼企业总数, (select count(oname) from ${tablename} ...
- JFrame的面板结构和JPanel的使用
JFrame图解结构 有一窗口框架实例:JFrame win = new JFrame("窗口");在new JFrame()时,构建了JFrame实例对象,在实例中的Layere ...
- HTML超链接实例介绍
<html><head><title>第六节课</title><meta charset="UTF-8"></he ...
- 直击JDD | 京东技术全景图首次展示 四大重磅智能技术驱动产业未来!
11月19日,主题为"突破与裂变"的2019京东全球科技探索者大会(JDDiscovery)在京盛大开幕,京东集团展示了完整的技术布局与先进而丰富的对外技术服务,对外明确诠释了&q ...
- MSE(均方误差)、RMSE (均方根误差)、MAE (平均绝对误差)
1.MSE(均方误差)(Mean Square Error) MSE是真实值与预测值的差值的平方然后求和平均. 范围[0,+∞),当预测值与真实值完全相同时为0,误差越大,该值越大. import n ...