zoukankan      html  css  js  c++  java
  • 寒假ACM集训复习总结Day2-helman

    Day2-STL

    HDU2094
    A题思路是看一个选手是否有败绩
    如果无败绩的人只有一个,那就是YES
    如果无败绩的人不止一个,那就是NO
    要用到map建立选手与败绩的联系
    set储存选手名字

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+7;
    int main(){
        freopen("1.in","r",stdin);
        map<string,int> mp;
        set<string> st;
        int n,flag;
        while(cin>>n&&n){
            flag=0;
            mp.clear();
            st.clear();
            string win,lose;
            while(n--){
                cin>>win>>lose;
                st.insert(win);
                st.insert(lose);
                mp[lose]++;
            }
            set<string >::iterator it;
            for(it=st.begin();it!=st.end();it++){
                if(mp[*it]==0)flag++;
            }
            if(flag==1)cout<<"YES"<<endl;
            else cout<<"NO"<<endl;
        }
        return 0;
    }

    HDU5479

    B题是要找字符串里能匹配多少个括号

    思路是从左到右存'('

    如果遇到')'就去掉一个'('

    如果又遇到一个'('就再存入

    这样相当于往银行里存左半边,遇到一个右半边就取出一个左半边,直到取完为止

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+7;
    int main(){
        freopen("1.in","r",stdin);
        int n;
        string s;
        cin>>n;
        stack<char>st;
        while(n--){
            int cnt=0;
            cin>>s;
            for(int i=0;i<s.length();i++){
                if(!st.empty()){
                    char t=st.top();
                    if(t=='('&&s[i]==')'){
                        cnt++;
                        st.pop();
                    }
                    else st.push(s[i]);
                }
                else st.push(s[i]);
            }
            cout<<cnt<<endl;
        }
        return 0;
    }

    HDU1106

     stringstram的题,记住就行

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+7;
    int main(){
        freopen("1.in","r",stdin);
        int a[10000];
        string s;
        while(cin>>s){
            for(int i=0;i<s.length();i++)
                if(s[i]=='5')s[i]=' ';
            stringstream ss(s);
            int t;
            int cnt=0;
            while(ss>>t)
                a[cnt++]=t;
            sort(a,a+cnt);
            cout<<a[0];
            for(int i=1;i<cnt;i++)
                cout<<' '<<a[i];
            cout<<endl;
        }
        return 0;
    }

     HDU1263

    通过这道题又学到了新的姿势,那就是map里写map,map的双重迭代,和第一二元素的表达方式,这些都会了,那做这道题也就没难度了

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+7;
    int main(){
        freopen("1.in","r",stdin);
        map<string,map<string,int> >mapp;
        int n;
        int m;
        cin>>n;
        while(n--){
            mapp.clear();
            string a,b;
            int c;
            cin>>m;
            while(m--){
                cin>>a>>b>>c;
                mapp[b][a]+=c;
            }
            map<string,map<string,int> >::iterator it;
            map<string,int> ::iterator i;
            for(it=mapp.begin();it!=mapp.end();it++){
                cout<<it->first<<endl;
                for(i=it->second.begin();i!=it->second.end();i++)
                    cout<<"   |----"<<i->first<<'('<<i->second<<')'<<endl;
            }
            if(n)cout<<endl;
        }
        return 0;
    }

    第一次使用队列做题,记住这个案例就大概能知道什么样的题适合用队列

    这道题是通过一遍遍的报到去除人数,直到不大于三个人

    思路就是将每次报到时出列的人去掉,不出列的排到队尾,以免影响之后的报到

    代码如下

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int maxn=1e6+7;
    int main(){
        freopen("1.in","r",stdin);
        int n;
        cin>>n;
        int m;
        while(n--){
            cin>>m;
            queue<int> q;
            for(int i=1;i<=m;i++)
                q.push(i);
            int cnt=0;
            while(q.size()>3){
                cnt++;
                int l=q.size();
                if(cnt%2==1){
                    for(int i=1;i<=l;i++){
                        int t=q.front();
                        if(i%2==1)q.push(t);
                        q.pop();
                    }
                }
                else {
                    for(int i=1;i<=l;i++){
                        int t=q.front();
                        if(i%3!=0)q.push(t);
                        q.pop();
                    }
                }
            }
            cout<<q.front();
            q.pop();
            while(!q.empty()){
                int t=q.front();
                q.pop();
                cout<<' '<<t;
            }
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    (十六)字段表集合
    (十五)类索引
    (十四)访问标志 Access_flags
    (一)单例模式
    (二十三)IDEA 构建一个springboot工程,以及可能遇到的问题
    (十三)class文件结构:常量池(转)
    Hive优化
    标签整理
    一些学习资料
    jstree树形菜单
  • 原文地址:https://www.cnblogs.com/helman/p/10461495.html
Copyright © 2011-2022 走看看