• Educational Codeforces Round 135 (构造、优先队列、区间DP)


    A. Colored Balls: Revisited

    普通签到题 找最大的序号

    1. #include
    2. using namespace std;
    3. pair<int,int> a[103];
    4. bool cmp(pair<int,int>a,pair<int,int>b){
    5. return a.first>b.first;
    6. }
    7. int main()
    8. {
    9. int t;cin>>t;
    10. while(t--){
    11. int n;cin>>n;
    12. for(int i=1;i<=n;i++){cin>>a[i].first;a[i].second=i;}
    13. sort(a+1,a+n+1,cmp);
    14. cout<1].second<<'\n';
    15. }
    16. return 0;
    17. }

    B. Best Permutation

    比较巧妙的构造题

    因为n-2+n-1 >n (n>2), 所以要找最大的话, 答案直接就是2n-1。

    构造数组的话无论前面怎么输出,最后几个数是 n-2 1 n-1 n 就可以了。

    1. #include
    2. using namespace std;
    3. int main()
    4. {
    5. int t;cin>>t;
    6. while(t--){
    7. int n;cin>>n;
    8. for(int i=n-3;i>1;i--)cout<" ";
    9. cout<-2<<" "<<1<<" "<-1<<" "<'\n';
    10. }
    11. return 0;
    12. }

    C. Digital Logarithm

    优先队列直接做

    1. #include
    2. using namespace std;
    3. priority_queue<int,vector<int>,less<int> >qa,qb;
    4. int f(int x){
    5. int ans=0;
    6. while(x){x/=10;ans++;}
    7. return ans;
    8. }
    9. int main()
    10. {
    11. int t;cin>>t;
    12. while(t--){
    13. int n;cin>>n;int res=0,aaa,bbb;
    14. for(int i=1;i<=n;i++){cin>>aaa;qa.push(aaa);}
    15. for(int i=1;i<=n;i++){cin>>bbb;qb.push(bbb);}
    16. while(!qa.empty()){
    17. int aa=qa.top(),bb=qb.top();
    18. if(aa==bb){qa.pop();qb.pop();}
    19. else if(aa>bb){int x=f(aa);qa.pop();qa.push(x);res++;}
    20. else {int x=f(bb);qb.pop();qb.push(x);res++;}
    21. }
    22. cout<'\n';
    23. }
    24. return 0;
    25. }

    D. Letter Picking

    已知 Bob不可能赢 所以只有 Alice赢 和 平局 两个结果。

    设字符串范围是[ i , j ]。

    假设Alice拿了s[i],那么Bob拿s[i+1]或者s[j],剩下的范围是dp[i+2][j]和dp[i+1][j-1],若范围显示是Alice赢,则最终结果是Alice赢;若范围显示是平局,那么比较 Alice拿到的 和 Bob拿到的:若Bob随便怎么拿,Alice拿的都比Bob小,则Alice胜利,否则平局。

    假设Alice拿了s[j],那么Bob拿s[i]或者s[j-1],剩下的范围是dp[i][j-2]和dp[i+1][j-1],

    剩下的都是同理了……

    1. #include
    2. using namespace std;
    3. bool check(char a,char b,bool fl){// 1是Alice
    4. if(fl)return 1;
    5. else if(areturn 1;
    6. else return 0;
    7. }
    8. int main()
    9. {
    10. int T;cin>>T;
    11. while(T--){
    12. bool dp[2005][2005]={0};
    13. string s;cin>>s;
    14. s=" "+s;int n=s.size()-1;
    15. for(int k=2;k<=n;k+=2){
    16. for(int i=1;i+k-1<=n;i++){
    17. int j=i+k-1;
    18. dp[i][j]=0;
    19. if(check(s[i],s[j],dp[i+1][j-1])&&check(s[i],s[i+1],dp[i+2][j]))dp[i][j]=1;
    20. if(check(s[j],s[i],dp[i+1][j-1])&&check(s[j],s[j-1],dp[i][j-2]))dp[i][j]=1;
    21. }
    22. }
    23. if(dp[1][n])cout<<"Alice\n";
    24. else cout<<"Draw\n";
    25. }
    26. return 0;
    27. }

  • 相关阅读:
    常见JVM面试题及答案整理
    计算机毕业设计php_thinkphp_vue的校园论坛网站
    【Flutter 】get-cli init报错处理
    JMeter--监听器--聚合报告
    springboot整合minio上传文件
    【跨级组件的通信&组件的生命周期&React的常用特性】
    单车&车路:中国的车路双智能到底有多牛?丨曼孚科技
    vue3 - Ts版本
    Jackson关于Western Blot、IHC 和 ELISA 的显色检测分析
    javascript基础学习大纲梳理
  • 原文地址:https://blog.csdn.net/zy98zy998/article/details/126782421