QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#294570#4832. TelepathyForever_Young#Compile Error//C++144.0kb2023-12-30 14:40:582023-12-30 14:40:58

Judging History

你现在查看的是最新测评结果

  • [2023-12-30 14:40:58]
  • 评测
  • [2023-12-30 14:40:58]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long LL;
mt19937 gene(233);
int cnt[10][2][10];
int select[1024], go[1024];
int sta[]={0,0,1,0,2,2,1,0,0,0,1,1,2,0,2,0};
vector<int> encode1(int n, int k, string s) {
    vector<int> res;
    //cout << s << endl;
    for(int i = 0; i < 3 * k; i += 3) {
        int msk = 0;
        for(int j = 0; j < 3; j++) {
            msk = msk * 2 + s[i + 2 - j] - '0';
            //cout << s[j] << ' ' << msk << endl;
        }
        res.pb(i + sta[msk]);
        /*int cnt = 0;
        vector<int> vec[2];
        for(int j = 0; j < n / k; j++) {
            cnt += s[i + j] == '1';
            vec[s[i + j] - '0'].pb(i + j);
        }
        if(cnt >= 5) {
            res.pb(vec[1][gene() % vec[1].size()]);
        }else {
            res.pb(vec[0][gene() % vec[0].size()]);
        }*/
    }
    return res;
}
vector<int> encode2(int n, int k, string s) {
    vector<int> res;
    for(int i = 0; i < 3 * k; i += 3) {
        int msk = 0;
        for(int j = 0; j < 3; j++) {
            msk = msk * 2 + s[i + 2 - j] - '0';
        }
        res.pb(i + sta[msk + 8]);
        /*int cnt = 0;
        vector<int> vec[2];
        for(int j = 0; j < n / k; j++) {
            cnt += s[i + j] == '1';
            vec[s[i + j] - '0'].pb(i + j);
        }
        if(cnt == 0 || cnt == n / k) {
            res.pb(i);
        }else {
            if(gene() % 2) {
                res.pb(vec[0][0]);
            }else {
                res.pb(vec[1][0]);
            }
        }*/
    }
    return res;
}
void check(string s1, string s2, vector<int> v1, vector<int> v2) {
    string t1, t2;
    for(int i : v1) {
        t1.pb(s2[i]);
    }
    for(int i : v2) {
        t2.pb(s1[i]);
    }
    assert(t1.size() == t2.size());
    int cnt = 0;
    for(int i = 0; i < (int)t1.size(); i++) {
        cnt += t1[i] == t2[i];
    }
    printf("cnt = %d\n", cnt);
}
int main() {
    string t;
    cin >> t;
    /*for(int i = 0; i < 1024; i++) {
        go[i] = gene() % 10;
        for(int j = 0; j < 10; j++) {
            if((i >> j) & 1) {

            }else {
                go[i] = j;
            }
        }
        for(int j = 0; j < 10; j++) {
            int d = (i >> j) & 1;
            cnt[j][d][go[i]]++;
        }
    }
    for(int i = 0; i < 1024; i++) {
        int mx = -1, mxj = -1;
        for(int j = 0; j < 10; j++) {
            int c = 0;
            for(int d = 0; d < 2; d++) {
                int sum =0 ;
                for(int k = 0; k < 10; k++) {
                    sum += cnt[j][d][k];
                    if(((i >> k) & 1) == d) {
                        c += cnt[j][d][k];
                    }
                }
                //printf("sum = %d c = %d\n", sum, c);
            }
            if(c > mx) {
                mx = c;
                mxj = j;
            }
        }
        //printf("%d %d\n", mx, mxj);
        select[i] = mxj;
    }*/
    if(t == "Flim") {
        int n, k;
        scanf("%d%d", &n, &k);
        string s;
        cin >> s;
        vector<int> vec = encode1(n, k, s);
        for(int i = 0; i < k; i++) {
            printf("%d%c", vec[i], i == k - 1 ? '\n' : ' ');
        }
    } else if(t == "Flam") {
        int n, k;
        scanf("%d%d", &n, &k);
        string s;
        cin >> s;
        vector<int> vec = encode2(n, k, s);
        for(int i = 0; i < k; i++) {
            printf("%d%c", vec[i], i == k - 1 ? '\n' : ' ');
        }
    } else {
        assert(t == "test");
        string s(1000000, ' ');
        for(int i = 0; i < 100; i++) {
            for(char & c : s) {
                c = gene() % 2 ? '0' : '1';
            }
            vector<int> v1 = encode1(1000000, 100000, s);
            string s1 = s;
            for(char & c : s) {
                c = gene() % 2 ? '0' : '1';
            }
            vector<int> v2 = encode2(1000000, 100000, s);
            check(s1, s, v1, v2);
        }
    }
}

Details

answer.code:7:16: error: ‘int select [1024]’ redeclared as different kind of entity
    7 | int select[1024], go[1024];
      |                ^
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:179,
                 from /usr/include/stdlib.h:394,
                 from /usr/include/c++/11/bits/std_abs.h:38,
                 from /usr/include/c++/11/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:41,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/sys/select.h:101:12: note: previous declaration ‘int select(int, fd_set*, fd_set*, fd_set*, timeval*)’
  101 | extern int select (int __nfds, fd_set *__restrict __readfds,
      |            ^~~~~~
answer.code: In function ‘int main()’:
answer.code:115:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  115 |         scanf("%d%d", &n, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~
answer.code:124:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  124 |         scanf("%d%d", &n, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~