编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#21089 #1001. A. 神秘谜题 Time Limit Exceeded 0 1520 ms 380 K C++ 11 / 2.0 K InNoVation 2020-01-09 20:08:43
显示原始代码
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <cstring>
#include <algorithm>
using namespace std;
using std::vector;

vector<int> vec;

int sign_function(string a, string b) {
    // cout<<"二进制a:"<<a<<endl;
    // cout<<"二进制b:"<<b<<endl;
    string s;
    int max_len = max(a.size(), b.size());
    if (a.size() < max_len) {
        for (int i = 0; i < max_len - a.size(); i++) {
            a.push_back('0');
        }
    }
    if (b.size() < max_len) {
        for (int i = 0; i < max_len - b.size(); i++) {
            b.push_back('0');
        }
    }
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == b[i])
            s.push_back('0');
        else
            s.push_back('1');
    }
    reverse(s.begin(), s.end());
    // cout<<"计算结果:"<<s<<endl;
    int num = 0;
    for (int i = 0; i < s.size(); i++) {
        num += (s[i] - '0') * int(pow(2, s.size() - i - 1));
    }
    return num;
}

string trans(int a) {
    string s;
    if (a != 0) {
        while (a != 1) {
            s.push_back(a % 2 + '0');
            a = a / 2;
        }
        s.push_back('1');
    } else {
        s.push_back('0');
    }
    // reverse(s.begin(),s.end());
    return s;
}

void work_function() {
    int _final = 0;
    for (int i = 0; i < vec.size(); i++) {
        if (i == 0) {
            _final = vec[i];
        } else {
            _final = sign_function(trans(_final), trans(vec[i]));
        }
    }
    cout << _final << endl;
}

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a;
        if (a == 1) {
            for (int j = 0; j < vec.size(); j++) {
                vec[j]++;
            }
            // output
            work_function();
        } else {
            cin >> b;
            vec.push_back(b);
            // output;
            work_function();
        }
    }
    system("pause");
    return 0;
}

/*
问题:
        1.不同位数异或操作怎么做;
        2.进制转换问题;
*/
子任务 #1
Time Limit Exceeded
得分:0
测试点 #1
Time Limit Exceeded
得分:0
用时:755 ms
内存:380 KiB

输入文件(1.in

200000
2 526767110
2 724642759
2 567837900
2 104106873
2 357915481
2 33997211
2 444788944
2 
<1586974 bytes omitted>

答案文件(1.ans

526767110
877985729
361528077
330887284
116239149
82537142
510237286
843295274
453728745
55
<2188330 bytes omitted>

用户输出

526767110
877985729
361528077
330887284
116239149
82537142
241801830
37988906
185293289
290828257
591990166
445105122
789378050

<8999 bytes omitted>
测试点 #2
Time Limit Exceeded
得分:0
用时:765 ms
内存:360 KiB

输入文件(2.in

200000
2 515979308
2 512702340
2 684230440
2 488136957
2 598252313
2 283603971
2 349877373
2
<1586842 bytes omitted>

答案文件(2.ans

515979308
5115816
679905408
899606653
372667236
114362215
302756634
473674072
520218589
525
<2192841 bytes omitted>

用户输出

515979308
5115816
8816768
94300285
104231780
114362215
34321178
71020888
117565405
122403661
300495142
361937528
878144675
98375
<8963 bytes omitted>