답안 #52621

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52621 2018-06-26T09:46:28 Z someone_aa 비교 (balkan11_cmp) C++17
컴파일 오류
0 ms 0 KB
//#include "cmp.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
bool bit[10000];
void remember(int n) {
    int node = 0;
    int li=0, ri=4095;
    cout<<0<<" ";
    while(li < ri) {
        int sz = ri - li + 1;
        sz = sz / 4;
        int st[4], fh[4];
        for(int i=0;i<4;i++) {
            st[i] = li + i*sz;
            fh[i] = st[i] + sz - 1;
            if(st[i] <= n && n <= fh[i]) {
                node = node * 4 + (i+1);
                li = st[i]; ri = fh[i];
            }
        }
        bit[node] = true;
        cout<<node<<" ";
    } cout<<"\n";
}

int compare(int b) {
    int li=0, ri=4095;
    int node = 0;
    vector<int>v;
    v.push_back(0);
    while(li < ri) {
        int sz = ri - li + 1;
        sz = sz / 4;
        int st[4], fh[4];
        int index = 0;
        for(int i=0;i<4;i++) {
            st[i] = li + i*sz;
            fh[i] = st[i] + sz - 1;
            if(st[i] <= b && b <= fh[i]) {
                index = i + 1;
            }
        }
        node = node * 4 + index;
        li = li + (index-1)*sz;
        ri = li + sz - 1;
        v.push_back(node);
    }

    for(int i:v) cout<<i<<" ";
    cout<<"\n";

    li = 0, ri = v.size() - 1;
    int f = 0;
    while(li <= ri) {
        int mid = (li+ri)/2;

        bool check = false;
        if(v[mid] == 0) check = false;
        else check = bit[v[mid]];
        if(check) {
            f = mid;
            li = mid + 1;
        }
        else ri = mid - 1;
    }

    if(f == v.size()-1) return 0;
    else {
        int myind;
        if(v[f]*4+1 == v[f+1]) myind = 1;
        else if(v[f]*4+2 == v[f+1]) myind = 2;
        else if(v[f]*4+3 == v[f+1]) myind = 3;
        else if(v[f]*4+4 == v[f+1]) myind = 4;
        if(myind == 1) return -1;
        else if(myind == 2) {
            if(bit[v[f]*4+1]) return 1;
            else return -1;
        }
        else if(myind == 3) {
            if(bit[v[f]*4+4]) return -1;
            else return 1;
        }
        else if(myind == 4) return 1;
    }
    return 0;
}

int main() {
    remember(3069);
    cout<<compare(1532);
}

Compilation message

cmp.cpp: In function 'int compare(int)':
cmp.cpp:68:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(f == v.size()-1) return 0;
        ~~^~~~~~~~~~~~~
cmp.cpp:75:9: warning: 'myind' may be used uninitialized in this function [-Wmaybe-uninitialized]
         if(myind == 1) return -1;
         ^~
/tmp/ccdyimQu.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccyi27EN.o:cmp.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status