zoukankan      html  css  js  c++  java
  • 记codeforces两题

    A。http://codeforces.com/contest/653/problem/A

    错在for(int i=0; i<v.size()-2; i++)  //当v.size()<2时,v.size()-2非负。

    #include<stdio.h>
    #include<string.h>
    #include<algorithm>
    #include<vector>
    #include<stdlib.h>
    #include<iostream>
    
    using namespace std;
    
    int main(){
        int n;
        while(scanf(" %d", &n)==1){
            vector<int> v;
            bool have=false;
            for(int i=0; i<n; i++){
                int t;  scanf(" %d", &t);
                v.push_back(t);
            }
          //  cout<<v.size()<<endl;
            sort(v.begin(), v.end());
            v.erase(unique(v.begin(), v.end()), v.end());
          //  cout<<v.size()<<endl;
            for(int i=0; i<v.size()-2; i++){
                int t0=v[i], t1=v[i+1], t2=v[i+2];
                if(abs(t0-t1)<3 && abs(t1-t2)<3 && abs(t2-t0)<3){
                    have=true;   break;
                }
            }
            cout<<(have?"YES":"NO")<<endl;
        }
        return 0;
    }
    

    B。http://codeforces.com/contest/653/problem/B

    状态不超过6^6次方种,暴力即可,

    #stl很好用。

    #include<stdio.h>
    #include<string>
    #include<iostream>
    
    using namespace std;
    
    int n, q;
    string s[36];
    
    int count(const string cur){
        if(cur.size()==n)   return 1;
        int cnt=0;
        for(int i=0; i<q; i++){
            if(cur[0]!=s[i][3]) continue;
            string st(cur);
            st.replace(0, 1, s[i].substr(0,2));
            cnt+=count(st);
        }
        return cnt;
    }
    
    int main(){
        while(cin>>n>>q){
            getchar();
            for(int i=0; i<q; i++){
                getline(cin, s[i]);
      //          cout<<s[i]<<endl;
            }
            cout<<count("a")<<endl;
        }
        return 0;
    }
    

      

  • 相关阅读:
    javascript
    vue-cli3 按需加载loading,服务的方式调用
    chrome devTool
    vuex
    git
    DNS寻址以及IP解析
    es6小记
    webpack 安装vue(两种代码模式compiler 和runtime)
    游戏屏幕朝向
    C#读写Json
  • 原文地址:https://www.cnblogs.com/ramanujan/p/5296259.html
Copyright © 2011-2022 走看看