首页 > 其他分享 >Educational Codeforces Round 154 (Rated for Div. 2)(A—C)

Educational Codeforces Round 154 (Rated for Div. 2)(A—C)

时间:2023-09-02 17:00:19浏览次数:35  
标签:Educational Rated 154 s2 sum Codeforces long solve s1

A. Prime Deletion

思路:

从1到9,每个数后面都可以加一个数构成一个含有两个数的质数,只需要从s[1]~s[9]中找到一个数与s[0]构成质数即可

代码实现

/*******************************
| Author:  CHC
| Problem: A. Prime Deletion
| Contest: Codeforces - Educational Codeforces Round 154 (Rated for Div. 2)
| URL:     https://codeforces.com/contest/1861/problem/A
| When:    2023-08-31 22:55:13
|
| Memory:  512 MB
| Time:    2000 ms
*******************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[11] = {0, 13, 23, 31, 41, 53, 61, 71, 83, 97};
void solve()
{
    string s;
    cin >> s;
    for (int i = 1; i < 10; i++)
        if (s[0] - '0' == i) {cout << a[i] << endl; break;}
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

B. Two Binary Strings

思路:

观察样例即可发现两个字符串只要在相同位置都有01存在就能成功实现转换时两个字符串相等

代码实现

/*******************************
| Author:  CHC
| Problem: B. Two Binary Strings
| Contest: Codeforces - Educational Codeforces Round 154 (Rated for Div. 2)
| URL:     https://codeforces.com/contest/1861/problem/B
| When:    2023-09-02 10:10:12
|
| Memory:  256 MB
| Time:    2000 ms
*******************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve()
{
    string a, b;
    cin >> a >> b;
    for (int i = 1; i < a.size(); i++)
    {
        if (a[i - 1] == '0' && a[i] == '1' && b[i - 1] == a[i - 1] && b[i] == a[i])
        {
            cout << "YES" << endl;
            return;
        }
    }
    cout << "NO" << endl;
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

C. Queries for the Array

思路

可以先假设字符串是可以成立的,那么接下来就判断它什么时间是不会成立就行了。
只有尾部增删操作,可以用 \(sum\) 记录当前整数的个数,用 \(s1\) 记录当前 \(s1\) 个数有序(这里用有序代表"\(a_1≤⋯≤a_n\)"),用 \(s2\) 记录当前 \(s2\) 个数无序。

  • s[i] == 1但前面有无序时(s2 ≤ sum)不会成立,具体看代码
  • s[i] == 0但前面有无序时(s1 ≥ sum)不会成立,具体看代码

代码实现

/*******************************
| Author:  CHC
| Problem: C. Queries for the Array
| Contest: Codeforces - Educational Codeforces Round 154 (Rated for Div. 2)
| URL:     https://codeforces.com/contest/1861/problem/C
| When:    2023-08-31 23:25:51
|
| Memory:  256 MB
| Time:    2000 ms
*******************************/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9
void solve()
{
    string s;
    cin >> s;

    int sum = 0, s1 = 1, s2 = INF;//sum记录当前整数个数,s1记录前s1个数递增,s2记录前s2个数不满足递增条件
    for (char c : s) {
        if (c == '+') sum++;
        else if (c == '-') {
            sum--;
            if (sum > 0 && s1 > sum) s1 = sum;//前sum个数递增
            if (s2 > sum) s2 = INF;//不能判断前s2-1个整数的无序性,s2赋值为INF
        }
        //两种判断“NO”的情况
        else if (c == '1') {
            if (s2 <= sum) { cout << "NO\n"; return; }//c==1但前面有无序时
            s1 = max(s1, sum);//否则更新s1
        }
        else {
            if (s1 >= sum) { cout << "NO\n"; return; }//c==0但前sum个数都是有序时
            s2 = min(s2, sum);//否则更新s2
        }
    }
    cout << "YES\n";
}

int main()
{
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

标签:Educational,Rated,154,s2,sum,Codeforces,long,solve,s1
From: https://www.cnblogs.com/wsccz/p/17673908.html

相关文章

  • 【题解】Educational Codeforces Round 153(CF1860)
    每次打都想感叹一句,Educational名不虚传。A.NotaSubstring题目描述:有\(t\)组数据,对于每一组数据,你需要判断能否构造一个只由左右括号组成且长度为已经给定字符串的\(2\)倍且已经给定的字符串不是子串的合法字符串。注:合法的字符串是左右括号能完全匹配的字符串。如果能,......
  • Educational Codeforces Round 113
    稳定发挥4题A题文件输出没去掉WA了一发B题特殊情况没判到,WA了好几发,中间还交到D题去了C题简单判断一下无解,然后组合数求一下就行D题其实也挺简单的,考虑严格夹在两条竖线之间的点(不包括边界),如果它们不是在同一水平线上,则必然大于Manhattan距离,而且两个点对之间要么是x方向走多......
  • Educational Codeforces Round 154 (Rated for Div. 2)
    感觉edu的题目都比较有新意;A.PrimeDeletion题意:给定长度为9的数,且1-9每个数字出现一次,求按照原定顺序选几个数组成的质数(起码选择两个);下意识写了一个dfs,过了;1#include<bits/stdc++.h>2usingnamespacestd;3intread(){4charch=getchar();intx=0,f=1;5......
  • Educational Codeforces Round 123
    A.DoorsandKeys#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongvoidsolve(){strings;cin>>s;map<char,int>pos;for(inti=0;i<6;i++)pos[s[i]]=i;if(pos['r&......
  • Educational Codeforces Round 15 A - E
    EducationalCodeforcesRound15目录EducationalCodeforcesRound15A-MaximumIncreaseB-PowersofTwoC-CellularNetworkD-RoadtoPostOfficeE.AnalysisofPathesinFunctionalGraphA-MaximumIncrease一段上升子数组\([l,r]\)最大化\(r-l+1\),我们......
  • Educational Codeforces Round 5 A-E
    EducationalCodeforcesRound5垫底咯,中间老师找我去聊了下新学期的机房借用和训练,但出去前就只有我没出E目录EducationalCodeforcesRound5AComparingTwoLongIntegersBDinnerwithEmmaCTheLabyrinthDLongestk-GoodSegmentE-SumofRemaindersAComparingTwo......
  • TO-277封装肖特基二极管SP1545L:15A 45V
    目前,市面上供应肖特基二极管的厂家、供应商特别地多,更多选择的背后,带来的却是更多的迷茫和不知所措。采购肖特基二极管,哪家好呢?提及“东沃电子DOWOSEMI”这个国产二极管品牌,很多客户可能第一想到他家的TVS二极管、ESD二极管、稳压二极、压敏电阻MOV、陶瓷气体放电管GDT、自恢复保险......
  • 【CF1542C】Strange Function(数论)
    题目大意:#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;constllmod=1e9+7;lln;lllcm(llx,lly){ returnx/__gcd(x,y)*y;}intmain(){ intT; cin>>T; while(T--){ cin>>n; llans=n%mod; for(lli=1,j=1;n/j......
  • 【五期邹昱夫】CCF-A(TIFS'23)SAFELearning: Secure Aggregation in Federated Learning
    "Zhang,Zhuosheng,etal."SAFELearning:SecureAggregationinFederatedLearningwithBackdoorDetectability."IEEETransactionsonInformationForensicsandSecurity(2023)."  本文提出了一种在联邦学习场景下可以保护隐私并防御后门攻击的聚合方法。作者认......
  • Educational Codeforces Round 148 (Rated for Div. 2)E. Combinatorics Problem(组合
    题目链接:https://codeforces.com/contest/1832/problem/E 题意:  当然这是化简后的题意,原题面和这个差距还是有点大的; 分析: 因为组合数有公式:  所以:   嗯,然后就没有了; 时间复杂度:O(n*k); 代码: #include<bits/stdc++.h>#defineintlonglong......