• E1. Madhouse (Easy version) (交互题)


    题目链接:https://codeforces.com/contest/1287/problem/E1

    首先需要知道什么是交互题:https://www.cnblogs.com/mch5201314/p/10875698.html

    题意:

    想法:

    #include <algorithm>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <map>
    #include <stack>
    #include <set>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <iomanip>
    #include <time.h>
    #include <bitset>
    #include <cmath>
    #include <sstream>
    #include <iostream>
    #include <cstring>
    
    #define LL long long
    #define ls nod<<1
    #define rs (nod<<1)+1
    #define pii pair<int,int>
    #define mp make_pair
    #define pb push_back
    #define INF 0x3f3f3f3f
    
    const double eps = 1e-10;
    const int maxn = 100 + 10;
    const LL mod = 1e9 + 7;
    
    int sgn(double a){return a < -eps ? -1 : a < eps ? 0 : 1;}
    using namespace std;
    
    string s;
    multiset<string> st;
    string ss[maxn];
    
    char ans[maxn*maxn];
    bool cmp (string s1,string s2) {
        return s1.size() < s2.size();
    }
    
    int buc[maxn*maxn];
    
    int main() {
        int n;
        cin >> n;
        if (n == 1) {
            cout << "? " << 1 << " " << 1 << endl;
            fflush(stdout);
            char c;
            cin >> c;
            cout << "! " << c;
            fflush(stdout);
            return 0;
        }
        cout << "? " << 1 << " " << n << endl;
        fflush(stdout);
        for (int i = 0;i < n*(n+1)/2;i++) {
            cin >> s;
            sort(s.begin(),s.end());
            st.insert(s);
        }
        cout << "? " << 2 << " " << n << endl;
        fflush(stdout);
        for (int i = 0;i < n*(n-1)/2;i++) {
            cin >> s;
            sort(s.begin(),s.end());
            st.erase(st.find(s));
        }
        int cnt = 0;
        for (auto p : st) {
            ss[cnt++] = p;
        }
        sort(ss,ss+cnt,cmp);
        ans[0] = ss[0][0];
        for (int i = 1;i < cnt;i++) {
            for (auto p : ss[i])
                buc[p]++;
            for (auto p : ss[i-1])
                buc[p]--;
            for (int j = 0;j < 127;j++) {
                if (buc[j] > 0) {
                    buc[j] = 0;
                    ans[i] = j;
                    break;
                }
            }
        }
        cout<<"! "<<ans;
        fflush(stdout);
        return 0;
    }

    参考博客:https://www.luogu.com.cn/blog/Rhodoks/solution-cf1286c1

  • 相关阅读:
    字符串删减
    iOS-AFNetworking与ASIHTTPRequest的区别
    iOS-清理缓存
    iOS-addSubView时给UIView添加效果
    iOS-明杰解决字段冲突,及数组映射
    iOS-开发将文本复制到剪切板
    iOS-加载html字符串
    iOS-UILabel加线
    iOS-获取webView的高度
    iOS-plist文件的写读
  • 原文地址:https://www.cnblogs.com/-Ackerman/p/12451616.html
Copyright © 2020-2023  润新知