• Codeforces Round #786 (Div. 3) ABCDE


    https://codeforces.com/contest/1674/problem/A

    题目大意:给定两个数x和y,问我们能否得出a,b(a表示相乘的次数,b表示和x相乘,如果可以通过x*b相乘a次得到y,那么就可以输出a b,否则输出0 0)

    input

    3
    3 75
    100 100
    42 13
    

    output

    2 5
    3 1
    0 0

    简化思维,x能否被y整除即可,可以的话一次性整除完

    不可以的话就是0

    特判一下当x>y的时候也是0 

    1. #include<iostream>
    2. #include<cmath>
    3. #include<algorithm>
    4. #include<cstring>
    5. #include<cstdlib>
    6. #include<string>
    7. #include<cstdio>
    8. #include<map>
    9. #include<vector>
    10. #include<set>
    11. using namespace std;
    12. int aa[200200];
    13. int main()
    14. {
    15. cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    16. int t;
    17. cin>>t;
    18. while(t--)
    19. {
    20. int a,b;
    21. cin>>a>>b;
    22. int x=0,y=0;
    23. if(a>b) cout<<x<<" "<<y<<endl;
    24. else if(a==b) cout<<"1 1"<<endl;
    25. else
    26. {
    27. if(b%a==0)
    28. {
    29. cout<<"1 "<<b/a<<endl;
    30. }
    31. else cout<<x<<" "<<y<<endl;
    32. }
    33. }
    34. return 0;
    35. }

    https://codeforces.com/contest/1674/problem/B

    题目大意:伯兰语是由一个字符串两个小写英文字母构成的,两个英文字母不能相同。这些单词是按照他们在字典中的顺序进行排列的,第一个就是ab,第二个ac以此类推。

    给定我们若干个伯兰语,问我们他们的索引是啥?也就是指第几个的意思。

    input

    7
    ab
    ac
    az
    ba
    bc
    zx
    zy
    

    out

    1
    2
    25
    26
    27
    649
    650

    这样想,英文字目一共有26个,不能有重复的,所以s[0]一旦发生变化,前面为25的倍数;

    当记录当前s[0]和s[1]的位置的情况时,要考虑一下是s[1]在不在s[0]的前面。

    因为受到相等位置的影响。

    1. #include<iostream>
    2. #include<cmath>
    3. #include<algorithm>
    4. #include<cstring>
    5. #include<cstdlib>
    6. #include<string>
    7. #include<cstdio>
    8. #include<map>
    9. #include<vector>
    10. #include<set>
    11. using namespace std;
    12. int aa[200200];
    13. int main()
    14. {
    15. cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    16. int t;
    17. cin>>t;
    18. while(t--)
    19. {
    20. string s;
    21. cin>>s;
    22. int sum=(s[0]-'a')*25;
    23. if(s[1]-'a'>s[0]-'a') sum+=s[1]-'a';
    24. else sum+=s[1]-'a'+1;
    25. cout<<sum<<endl;
    26. }
    27. return 0;
    28. }

    https://codeforces.com/contest/1674/problem/C

    题目大意:给定一个字符串s,仅由字母' a '组成,和一个字符串t,由小写字母组成。

    在一次移动中,可以用字符串t替换字符串s中的任何字母“a”。(在替换后的字符串s可能包含除“a”以外的字母),可以执行任意次数的移动(包括零次)。问能获得多少不同的字符串?

    如果无限数量输出-1

    input

    3
    aaaa
    a
    aa
    abc
    a
    b
    

    output

    1
    -1
    2

    判断c中a的个数

    以及思考s中的a可以变换的过程即可 

    1. #include<iostream>
    2. #include<cmath>
    3. #include<algorithm>
    4. #include<cstring>
    5. #include<cstdlib>
    6. #include<string>
    7. #include<cstdio>
    8. #include<map>
    9. #include<vector>
    10. #include<set>
    11. using namespace std;
    12. int aa[200200];
    13. int main()
    14. {
    15. cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    16. int t;
    17. cin>>t;
    18. while(t--)
    19. {
    20. string s;
    21. cin>>s;
    22. string c;
    23. cin>>c;
    24. if(c=="a") cout<<"1"<<endl;
    25. else
    26. {
    27. bool flag=true;
    28. for(int i=0;i<c.size();i++)
    29. if(c[i]=='a'&&c.size()>=2) flag=false;
    30. if(flag==false) cout<<"-1"<<endl;
    31. else
    32. {
    33. long long ti=s.size();
    34. long long sum=1;
    35. while(ti--)
    36. {
    37. sum*=2;
    38. }
    39. cout<<sum<<endl;
    40. }
    41. }
    42. }
    43. return 0;
    44. }

    https://codeforces.com/contest/1674/problem/D

    题目大意:给定3个数组a,b和c,最初,数组a由n个元素组成,数组b和c是空的。

    执行两个步骤:

    步骤1:当a不为空时,从a中取出最后一个元素,并将其移动到数组b的中间。如果b当前的长度为奇数,您可以选择:将a中的元素放在b中间元素的左侧或右侧。结果,a变为空,b由n个元素组成。
    步骤2:当b不为空时,从b中取出中间的元素,并将其移动到数组c的末尾。如果b当前的长度为偶数,则可以选择两个中间元素中的哪一个。结果,b变成空的,c现在由n个元素组成。
    问我们能不能让数组c按非降序(升序)排序?

    input

    3
    4
    3 1 5 3
    3
    3 2 1
    1
    7331
    

    output

    YES
    NO
    YES

     

    1. #include<iostream>
    2. #include<cmath>
    3. #include<algorithm>
    4. #include<cstring>
    5. #include<cstdlib>
    6. #include<string>
    7. #include<cstdio>
    8. #include<map>
    9. #include<vector>
    10. #include<set>
    11. using namespace std;
    12. int a[200200];
    13. int main()
    14. {
    15. //cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    16. int t;
    17. cin>>t;
    18. while(t--)
    19. {
    20. int n;
    21. cin>>n;
    22. for(int i=1;i<=n;i++)
    23. cin>>a[i];
    24. vector<int> v;
    25. vector<int> ve;
    26. for(int i=n;i>=2;i-=2)
    27. {
    28. if(a[i]<a[i-1])
    29. {
    30. v.push_back(a[i]);
    31. ve.push_back(a[i-1]);
    32. }
    33. else
    34. {
    35. ve.push_back(a[i]);
    36. v.push_back(a[i-1]);
    37. }
    38. }
    39. //if(n%2==1) v.push_back(a[1]);
    40. reverse(v.begin(),v.end());
    41. reverse(ve.begin(),ve.end());
    42. /*
    43. for(int i=0;i<v.size();i++) cout<<v[i]<<" "; cout<<endl;
    44. for(int i=0;i<ve.size();i++) cout<<ve[i]<<" "; cout<<endl;
    45. */
    46. bool flag=true;
    47. int maxn=0;
    48. if(n%2==1) maxn=a[1];
    49. for(int i=0;i<v.size();i++)
    50. {
    51. if(v[i]>=maxn&&v[i]<=ve[i]) maxn=ve[i];
    52. else flag=false;
    53. }
    54. if(flag==true) cout<<"YES"<<endl;
    55. else cout<<"NO"<<endl;
    56. }
    57. return 0;
    58. }

    https://codeforces.com/contest/1674/problem/E

    题目大意:一堵连续长度为n的墙,第i段初始有耐久性ai。如果某一部分的耐久性变为0或更小,则该部分被视为破损。

    要攻击对手,至少需要打破两段墙(任意两段:可能相邻,也可能不相邻)。有一种武器可以用来破坏墙壁的任何部分,这个射击对目标区域造成2点伤害,对邻近区域造成1点伤害。换句话说,如果、向x部分射击,那么x部分的耐久性减少2,而x1和x+1部分(如果存在)的耐久性各减少1。

    问我们想要至少打破两个部分所需的最少次数?

     input

    5
    20 10 30 10 20
    

    output

    10
    

    input

    3
    1 8 1
    

    output

    1
    

    input

    6
    7 6 6 8 5 8
    

    output

    4
    

    input

    6
    14 3 8 10 15 4
    

    output

    4
    

    input

    4
    1 100 100 1
    

    output

    2
    

    input

    3
    40 10 10
    

    output

    1. #include<iostream>
    2. #include<cmath>
    3. #include<algorithm>
    4. #include<cstring>
    5. #include<cstdlib>
    6. #include<string>
    7. #include<cstdio>
    8. #include<map>
    9. #include<vector>
    10. #include<set>
    11. using namespace std;
    12. const int N=2002000;
    13. int a[N],b[N];
    14. int main()
    15. {
    16. cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    17. int n;
    18. cin>>n;
    19. for(int i=1;i<=n;i++)
    20. {
    21. cin>>a[i];
    22. if(a[i]%2==1) b[i]=(a[i]+1)/2;
    23. else b[i]=a[i]/2;
    24. }
    25. sort(b+1,b+n+1);
    26. int sum=b[1]+b[2];//这一步是找到最极端情况下的最小步数
    27. for(int i=1;i<=n-1;i++)//两个两个一起找
    28. {
    29. int minn=min(a[i],a[i+1]);
    30. int maxn=a[i]+a[i+1]-minn;
    31. if(maxn>=minn*2) sum=min(sum,(maxn+1)/2);//如果想要消除这两个,那必须把大的消除了
    32. else sum=min(sum,(a[i]+a[i+1]+2)/3);
    33. }
    34. for(int i=2;i<=n-1;i++)//三个三个一起找
    35. {
    36. int maxn=max(a[i-1],a[i+1]);
    37. sum=min(sum,maxn);
    38. sum=min(sum,min(a[i+1],a[i-1])+((abs(a[i+1]-a[i-1])+1)/2));
    39. }
    40. cout<<sum<<endl;
    41. return 0;
    42. }

    期末考试终于结束了,奖励自己一场cf hh 

  • 相关阅读:
    单元格法近似求解多边形最大内接矩形问题【思路讲解+java实现】
    Today‘s web RPC案例
    切换为root用户后,conda:未找到命令
    Go重写Redis中间件 - Go实现内存数据库
    Android Studio 截屏
    虚拟机安装配置Hadoop(图文教程)
    思维模型 棘轮效应
    【STM32】TF卡&&FTA32文件系统
    【BOOST C++ 18 数字处理】(4)Boost.Random
    django setting.py中的SECRET_KEY
  • 原文地址:https://blog.csdn.net/qq_51376774/article/details/124597472