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;
    }
    

      

  • 相关阅读:
    变量的创建和初始化
    HDU 1114 Piggy-Bank (dp)
    HDU 1421 搬寝室 (dp)
    HDU 2059 龟兔赛跑 (dp)
    HDU 2571 命运 (dp)
    HDU 1574 RP问题 (dp)
    HDU 2577 How to Type (字符串处理)
    HDU 1422 重温世界杯 (dp)
    HDU 2191 珍惜现在,感恩生活 (dp)
    HH实习 acm算法部 1689
  • 原文地址:https://www.cnblogs.com/ramanujan/p/5296259.html
Copyright © 2011-2022 走看看