当前位置:   article > 正文

Codeforces Round #700 (Div. 2)_codeforces round 700 (div. 2)

codeforces round 700 (div. 2)

A

Yet Another String Game

题意:Alice和Bob轮流改变字符串,Alice先手,每次改变可以选择未被改变过的位置改成除原字符外的任意字符,Alice想让字典序尽可能小,Bob想让字典序尽可能大,问最后的字符串

思路:Alice一定是选靠前的位置改成字典序小的字母,Bob也是选择靠前的位置改成字典序大的字母,所以从前往后,Alice与Bob交替更改。

  1. #include <bits/stdc++.h>
  2. #define lowbit(x) x&(-x)
  3. #define endl '\n'
  4. #define sf(x) scanf("%d",&x)
  5. #define rep(i,x) for(i=0;i<(x);i++)
  6. #define gen(x) x##_
  7. #define ios std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
  8. #define PII pair<int,int>
  9. typedef long long ll;
  10. const int N=1e6+10;
  11. const int inf=0x3f3f3f3f;
  12. using namespace std;
  13. string s;
  14. void solve()
  15. {
  16. s.clear();
  17. cin>>s;
  18. int len=s.length();
  19. for(int i=0;i<len;i++)
  20. {
  21. if(i&1)
  22. {
  23. if(s[i]=='z') s[i]='y';
  24. else s[i]='z';
  25. }
  26. else
  27. {
  28. if(s[i]=='a') s[i]='b';
  29. else s[i]='a';
  30. }
  31. }
  32. cout<<s<<'\n';
  33. }
  34. int main()
  35. {
  36. //ios;
  37. int _t=1;
  38. cin>>_t;
  39. while(_t--)
  40. {
  41. solve();
  42. }
  43. system("pause");
  44. return 0;
  45. }

B

 The Great Hero

题意:英雄初始的攻击力A,生命值B,n个怪兽及每个怪兽的攻击力a[i],生命值b[i]。每次战斗英雄的生命值变为B-a[i],怪的生命值变为b[i]-A。对每个怪可以发动多次战斗。若英雄能打死全部怪兽(即使最后英雄也死去)则输出YES,否则输出NO

思路:因为英雄受到的总伤害是不变的,可以先计算出总伤害为sa,如果sa<=B,显然输出YES;如果sa>B,则需要讨论英雄在被杀的时候,是否可以杀死最后一只怪物,当存在sa-a[k]<B,则在击杀第k只怪时,是可以完成一换一的。即只需当sa-maxa<B,就输出YES。否则NO

  1. #include <bits/stdc++.h>
  2. #define lowbit(x) x &(-x)
  3. #define endl '\n'
  4. #define sf(x) scanf("%d", &x)
  5. #define rep(i, x) for (i = 0; i < (x); i++)
  6. #define gen(x) x##_
  7. #define ios \
  8. std::ios::sync_with_stdio(false); \
  9. cin.tie(0), cout.tie(0)
  10. #define PII pair<int, int>
  11. typedef long long ll;
  12. const int N = 1e5 + 10;
  13. const int inf = 0x3f3f3f3f;
  14. using namespace std;
  15. struct node
  16. {
  17. ll a, b;
  18. } m[N];
  19. ll A, B, n;
  20. void solve()
  21. {
  22. //memset(m,0,sizeof m);
  23. //cin >> A >> B >> n;
  24. scanf("%lld %lld %lld",&A,&B,&n);
  25. for (int i = 1; i <= n; i++)
  26. scanf("%lld",&m[i].a);
  27. //cin >> m[i].a;
  28. for (int i = 1; i <= n; i++)
  29. scanf("%lld",&m[i].b);
  30. //cin >> m[i].b;
  31. ll sa=0,amax=0;
  32. for (int i = 1; i <= n; i++)
  33. {
  34. ll t = (m[i].b +A-1)/ A; //t为轮数m[i].b/A向上取整
  35. sa+=t*m[i].a;
  36. amax=max(m[i].a,amax);
  37. }
  38. if(sa-amax>=B) cout<<"NO\n";
  39. else cout<<"YES\n";
  40. }
  41. int main()
  42. {
  43. // ios;
  44. int _t = 1;
  45. cin >> _t;
  46. while (_t--)
  47. {
  48. solve();
  49. }
  50. system("pause");
  51. return 0;
  52. }

C

 Searching Local Minimum

 题意:交互题,有一个长度为n的数组,其中存放着1~n的全排列。让你在100次询问之内找到局部最小值。最初只知道数组的大小,数组每个位置上的值需要通过询问得到

若ai为局部最小值,a_{i-1}>a_{i}&&a_{i}<a_{i+1}

思路:起初a_{l-1}>a_{l}&&a_{r}<a_{r+1},若我们在二分的时候能维护住这个性质,则二分到l=r时,这个点就满足比两边小。

若a[mid]<a[mid+1],则[l,mid]仍满足这个性质。

若a[mid]>a[mid+1],则[mid+1,r]仍满足这个性质。

所以我们总能维护满足性质的区间,时间复杂度为log(2)n

  1. #include <bits/stdc++.h>
  2. #define lowbit(x) x&(-x)
  3. #define endl '\n'
  4. #define sf(x) scanf("%d",&x)
  5. #define rep(i,x) for(i=0;i<(x);i++)
  6. #define gen(x) x##_
  7. #define ios std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
  8. #define PII pair<int,int>
  9. typedef long long ll;
  10. const int N=1e5+10;
  11. const int inf=0x3f3f3f3f;
  12. using namespace std;
  13. int a[N];
  14. int n;
  15. void get(int x)
  16. {
  17. if(x>n||x<1||a[x]) return ;
  18. cout<<"? "<<x<<'\n';
  19. fflush(stdout);
  20. cin>>a[x];
  21. }
  22. void solve()
  23. {
  24. cin>>n;
  25. a[0]=1e9,a[n+1]=1e9;
  26. int l=1,r=n;
  27. while(l<r)
  28. {
  29. int mid=l+r>>1;
  30. get(mid);get(mid+1);
  31. if(a[mid]<a[mid+1]) r=mid;
  32. else l=mid+1;
  33. }
  34. cout<<"! "<<l<<'\n';
  35. }
  36. int main()
  37. {
  38. //ios;
  39. int _t=1;
  40. //cin>>_t;
  41. while(_t--)
  42. {
  43. solve();
  44. }
  45. system("pause");
  46. return 0;
  47. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/71352
推荐阅读
相关标签
  

闽ICP备14008679号