zoukankan      html  css  js  c++  java
  • L2-012. 关于堆的判断

    https://www.patest.cn/contests/gplt/L2-012

    题解:1.sstream读入一行

      2.make_heap,find函数直接建堆

    坑:cin输入挂 下不能puts。。。

    #define _CRT_SECURE_NO_WARNINGS
    #include<cstring>
    #include<cctype>
    #include<cstdlib>
    #include<iomanip>
    #include<cmath>
    #include<cstdio>
    #include<string>
    #include<stack>
    #include<ctime>
    #include<list>
    #include<set>
    #include<map>
    #include<queue>
    #include<vector>
    #include<sstream>
    #include<fstream>
    #include<iostream>
    #include<functional>
    #include<algorithm>
    #include<memory.h>
    //#define INF 0x3f3f3f3f
    #define eps 1e-6
    #define pi acos(-1.0)
    #define e exp(1.0)
    #define rep(i,t,n)  for(int i =(t);i<=(n);++i)
    #define per(i,n,t)  for(int i =(n);i>=(t);--i)
    #define mp make_pair
    #define pb push_back
    #define mmm(a,b) memset(a,b,sizeof(a))
    //std::ios::sync_with_stdio(false);
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    void smain();
    #define ONLINE_JUDGE
    int main() {
        //ios::sync_with_stdio(false);
    #ifndef ONLINE_JUDGE
        FILE *myfile;
        myfile =freopen("C:\Users\SuuTT\Desktop\test\in.txt", "r", stdin);
        if (myfile == NULL)
            fprintf(stdout, "error on input freopen
    ");
        /*FILE *outfile;
        outfile= freopen("C:\Users\SuuTT\Desktop\test\out.txt", "w", stdout);
        if (outfile == NULL)
            fprintf(stdout, "error on output freopen
    ");*/
        long _begin_time = clock();
    #endif
        smain();
    #ifndef ONLINE_JUDGE
        long _end_time = clock();
        printf("time = %ld ms.", _end_time - _begin_time);
    #endif
        return 0;
    }
    int dir[4][2] = { 1,0,0,1,-1,0,0,-1 };
    const int maxn = 2e2 + 5;
    int n, m;
    vector<int>heap;
    int find(int a) {
        return distance(heap.begin(), find(heap.begin(), heap.end(), a));
    }
    void smain() {
        cin >> n >> m;
        while (n--) {
            int x;
            cin >> x;
            heap.push_back(x);
            make_heap(heap.begin(), heap.end(), greater<int>());
        }
        getchar();
        while (m--) {
            string line;
            getline(cin, line);
    
            
    
            int rlen = line.length() - 1;
    
            if (line[rlen] == 't') {
                int x; stringstream ss(line); ss >> x;
                if (heap[0] == x)puts("T");else puts("F");
            }
            else if (line[rlen] == 's') {
                string t;
                int a, b; stringstream ss(line); ss>> a >> t >> b;
                int posa = find(a);
                int posb = find(b);
                posa++, posb++;
                if(posa/2==posb/2)puts("T"); else puts("F");
            }
            else {
                stringstream ss(line);
                int a, b;
                string t1, t2;
                ss >> a >> t1 >> t2;
                if (t2[0] == 't') {//parent
                    ss >> t1 >> t2 >> b;
                    int posb = find(b); posb--;
                    int posa = find(a);
                    if(posa==posb/2)puts("T"); else puts("F");
                }
                else {//child
                    ss >> t1 >> t2 >> b;
                    swap(a, b);
                    int posb = find(b); posb--;
                    int posa = find(a);
                    if (posa == posb / 2)puts("T"); else puts("F");
                }
            }
        }
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    python threading 无法并行问题
    flask
    jinjia2 模板不解析html
    docker 配置lnmp环境(mac环境下)
    docker基础
    django初体验
    Centos6.5 编译安装Mysql 5.5.3.7
    Mysql InnoDB事务
    删除GitHub上项目中的某个文件
    转 WPF MVVM 循序渐进 (从基础到高级)
  • 原文地址:https://www.cnblogs.com/SuuT/p/9006855.html
Copyright © 2011-2022 走看看