1379A
传送门

Acacius is studying strings theory. Today he came with the following
problem.

You are given a string s of length n consisting of lowercase English
letters and question marks. It is possible to replace question marks
with lowercase English letters in such a way that a string “abacaba”
occurs as a substring in a resulting string exactly once?

Each question mark should be replaced with exactly one lowercase
English letter. For example, string “a?b?c” can be transformed into
strings “aabbc” and “azbzc”, but can’t be transformed into strings
“aabc”, “a?bbc” and “babbc”.

Occurrence of a string t of length m in the string s of length n as a
substring is a index i (1≤i≤n−m+1) such that string s[i…i+m−1]
consisting of m consecutive symbols of s starting from i-th equals to
string t. For example string “ababa” has two occurrences of a string
“aba” as a substring with i=1 and i=3, but there are no occurrences of
a string “aba” in the string “acba” as a substring.

Please help Acacius to check if it is possible to replace all question
marks with lowercase English letters in such a way that a string
“abacaba” occurs as a substring in a resulting string exactly once.

Input First line of input contains an integer T (1≤T≤5000), number of
test cases. T pairs of lines with test case descriptions follow.

The first line of a test case description contains a single integer n
(7≤n≤50), length of a string s.

The second line of a test case description contains string s of length
n consisting of lowercase English letters and question marks.

Output For each test case output an answer for it.

In case if there is no way to replace question marks in string s with
a lowercase English letters in such a way that there is exactly one
occurrence of a string “abacaba” in the resulting string as a
substring output “No”.

Otherwise output “Yes” and in the next line output a resulting string
consisting of n lowercase English letters. If there are multiple
possible strings, output any.

You may print every letter in “Yes” and “No” in any case you want (so,
for example, the strings yEs, yes, Yes, and YES will all be recognized
as positive answer).

大概是比较简单的字符串处理?然而太饿了,所以没做(其实是练少了)
这应该是近来最难的div2A吧?

#include <bits/stdc++.h>//1379Ausing namespace std;
string s1,s2,s3;
int over_roll(string sc)//统计
{int cnt=0;for(int i=0;i<=sc.size()-s3.size();i++){if(sc.substr(i,s3.size())==s3)cnt++;}return cnt;
}
int main()
{ios::sync_with_stdio(0);int t;int n;bool output_check,circulate_check;s3="abacaba";cin>>t;while(t--){cin>>n;cin>>s1;output_check=0;for(int i=0;i<=n-s3.size();i++){s2=s1;circulate_check=0;for(int j=0;j<s3.size();j++){if(s2[j+i]!=s3[j]&&s2[j+i]!='?'){circulate_check=1;break;}s2[i+j]=s3[j];}if(!circulate_check&&over_roll(s2)==1){for(int j=0;j<n;j++){if(s2[j]=='?')s2[j]='y';}output_check=1;cout<<"Yes"<<endl;cout<<s2<<endl;break;}}if(!output_check)cout<<"No"<<endl;}
}

1379B
传送门

Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l≤a,b,c≤r, and then he computes the encrypted value m=n⋅a+b−c.
Unfortunately, an adversary intercepted the values l, r and m. Is it possible to recover the original values of a, b and c from this information? More formally, you are asked to find any values of a, b and c such that
a, b and c are integers,
l≤a,b,c≤r,
there exists a strictly positive integer n, such that n⋅a+b−c=m.
Input
The first line contains the only integer t (1≤t≤20) — the number of test cases. The following t lines describe one test case each.
Each test case consists of three integers l, r and m (1≤l≤r≤500000, 1≤m≤1010). The numbers are such that the answer to the problem exists.
Output
For each test case output three integers a, b and c such that, l≤a,b,c≤r and there exists a strictly positive integer n such that n⋅a+b−c=m. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions.

(做B题时饿晕了,醒来比赛结束了 )
m+c-b 的取值区间是[m-r+l,m+r-l]
n=(m+c-b)/a 让n向下取值
遍历寻找一个a,让n*a的值在取值区间中
这时输出合法的b,c值就解出来了

#include <bits/stdc++.h>using namespace std;int main()
{ios::sync_with_stdio(0);long long t,l,r,m,a,up1,down1,ans;cin>>t;while(t--){cin>>l>>r>>m;long long tes;down1=m-r+l;//下界up1=m+r-l;//上界for(a=l;a<=r;a++){tes=(up1)/a;if(tes*a<=up1&&tes*a>=down1)break;//寻找一个可//以在取值区间中//发挥作用的a值}ans=r-m+tes*a;if(ans>r){//防止越界ans=l-m+tes*a;r=l;}cout<<a<<" "<<r<<" "<<ans<<endl;}
}

1379A. Acacius and String + 1379B.B. Dubious Cyrpto相关推荐

  1. [codeforces 1379B] Dubious Cyrpto 公式推导

    Codeforces Round #657 (Div. 2)   参与排名人数8684   错过了难得17:00比赛,可惜 [codeforces 1379B]   Dubious Cyrpto  公 ...

  2. Codeforces Round #657 (Div. 2)B. Dubious Cyrpto

    思路 题目要求: na+b−c=mna+b-c=m na+b−c=m 我们可以转换为 na−m=c−bna-m=c-b na−m=c−b 然后c−bc-bc−b是固定不变的,我们去枚举a,在枚举的a的 ...

  3. Codeforces 1379B.Dubious Cyrpto

    1 题目描述(题目链接) 2 题解   由题意得,na=m+c−bna=m+c-bna=m+c−b,则na∈[m+l−r,m+r−l]na\in [m+l-r,m+r-l]na∈[m+l−r,m+r− ...

  4. B. Dubious Cyrpto

    https://codeforces.com/contest/1379/problem/B 如果m>i,则有两种情况,m%i在范围内或者i-m%i在范围内,m<i,只有i-m%i的情况. ...

  5. Codeforces Round #657 (Div. 2) B题 Dubious Cyrpto

    m是被除数,a是除数,n的商,b-c是余数.切记,考虑b-c是负数的情况.切记 !切记 ! 二话不说上代码: #include <iostream> #include <algori ...

  6. Codeforces1379 B. Dubious Cyrpto(枚举)

    题意: 给定l,r,m 要求构造出一组a,b,c,满足: l<=a,b,c<=r,存在一个正整数n,na+b-c=m 数据范围:l,r<=5e5,m<=1e10 解法: 容易想 ...

  7. Codeforces B. Dubious Cyrpto (枚举 / 模拟) (Round #657 Div.2)

    传送门 题意: 已知存在三个数a,b,c满足l <= a,b,c <= r,且m = n * a + b - c.现在告诉你l,r和m的值,需要你找到一组可行的a,b,c. 思路: 枚举a ...

  8. Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(思维,数学)

    题目链接 题意: m=n⋅a+b−c(n为任意正整数),给出m的值a,b,c的范围l,r(l<=a,b,c<=r),求出a,b,c. 思路: 由推倒知0<=|b-c|<=r-l ...

  9. codeforces1379B Dubious Cyrpto

    https://codeforces.com/contest/1379/problem/B 可以想到其实就是让n*a=(m-(r-l),m+r-l)中的一个数 然后直接枚举a=l->r 令l2= ...

最新文章

  1. python简单装饰器_python装饰器的简单示例
  2. tc溜溜865手机投屏卡_下半年发布新品手机盘点:骁龙865+是性能之王 红米抢入门市场...
  3. java12章_从零开始学Java 第12章 异常处理
  4. java中nextLine(),读取换行符的解决
  5. C# 判断一字符串是否为合法数字(正则表达式)
  6. 这样才是代码管理和 Commit 的正确姿势 | 研发效能提升36计
  7. 利用火狐浏览器Firebug查看网页相关属性
  8. 如何制作HTML5 SVG描边文字
  9. 22.使用非阻塞IO 1
  10. Oracle 权限管理
  11. 金山电脑公司总经理雷军(转载)
  12. android自定义dialog大小,android – 自定义对话框大小匹配Theme.Holo.Light.Dialog
  13. A Lookahead Read Cache论文总结
  14. 机器学习:Experiment 5: Regularization
  15. 浙江大学软件学院2020年保研真题Distance of Triples (25 分)
  16. 第十一届蓝桥杯国赛题目
  17. 解决程控电话交换机内线有杂音问题
  18. uva10306-电子硬币
  19. java ftp文件大小_java如何获得ftp服务器上指定文件的大小
  20. 2D spine动画 消融

热门文章

  1. 我的博客网站开发1——博客首页设计
  2. 记录项目中遇到的坑(三)兼容IE浏览器
  3. ZEMAX设计锥透镜/轴锥镜
  4. C/C++变量之整型变量
  5. NAND_FLASH(K9F1208U0C)驱动分析
  6. element-ui小图标位置调整
  7. tomcat限速_网络限速
  8. 什么是 BusyBox 以及它在哪里使用?
  9. 运营小技能:分析订阅号文章数据来提升账号权重
  10. 有意思的数学--数系的发展历史