QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#812068#9156. 百万富翁dvbs2000Compile Error//C++142.9kb2024-12-13 11:13:482024-12-13 11:13:56

Judging History

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

  • [2024-12-13 11:13:56]
  • 评测
  • [2024-12-13 11:13:48]
  • 提交

answer

#include "richest.h"
#include <vector>

// 声明 ask 函数,根据题目要求,这个函数由交互库提供
std::vector<int> ask(std::vector<int> a, std::vector<int> b);

// 实现 richest 函数
int richest(int N, int T, int S) {
    // 初始化所有客户为候选者
    std::vector<int> candidates;
    candidates.reserve(N);
    for(int i = 0; i < N; ++i){
        candidates.push_back(i);
    }

    int remaining_queries = S;
    int remaining_requests = T;

    // 进行淘汰赛,直到找到最终胜者
    while(candidates.size() > 1 && remaining_requests > 0 && remaining_queries > 0){
        std::vector<int> a;
        std::vector<int> b;

        // 生成当前轮的比较对
        size_t i = 0;
        size_t size = candidates.size();
        for(; i + 1 < size; i += 2){
            a.push_back(candidates[i]);
            b.push_back(candidates[i+1]);
        }

        // 计算本轮需要的比较次数
        size_t comparisons = a.size();

        // 检查是否超过剩余的查询次数
        if(comparisons > remaining_queries){
            // 如果剩余查询次数不足以完成所有比较对,分批发送
            size_t batch_size = remaining_queries;
            if(batch_size == 0){
                break; // 无法继续比较
            }

            // 发送一个批次的比较
            std::vector<int> a_batch(a.begin(), a.begin() + batch_size);
            std::vector<int> b_batch(b.begin(), b.begin() + batch_size);
            std::vector<int> c = ask(a_batch, b_batch);

            // 更新查询次数和请求次数
            remaining_queries -= batch_size;
            remaining_requests -= 1;

            // 替换原来的部分比较结果
            for(size_t j = 0; j < c.size(); ++j){
                a[j] = c[j];
            }

            // 将胜者添加到新候选者列表
            for(size_t j = 0; j < c.size(); ++j){
                a[j] = c[j];
            }

            // 重置候选者为胜者
            candidates.assign(a.begin(), a.begin() + c.size());

            // 处理奇数个候选者
            if(i < size){
                candidates.push_back(candidates.back());
            }

            continue;
        }

        // 发送当前轮的所有比较对
        std::vector<int> c = ask(a, b);

        // 更新查询次数和请求次数
        remaining_queries -= comparisons;
        remaining_requests -= 1;

        // 更新候选者列表为胜者
        candidates = c;

        // 如果当前轮有奇数个候选者,保留最后一个晋级
        if(i < size){
            candidates.push_back(candidates.back());
        }
    }

    // 如果最终有多个候选者,选择第一个作为结果
    if(candidates.empty()){
        return -1; // 无有效候选者
    } else {
        return candidates[0];
    }
}

Details

answer.code: In function ‘int richest(int, int, int)’:
answer.code:25:9: error: ‘size_t’ was not declared in this scope; did you mean ‘std::size_t’?
   25 |         size_t i = 0;
      |         ^~~~~~
      |         std::size_t
In file included from /usr/include/c++/13/bits/requires_hosted.h:31,
                 from /usr/include/c++/13/vector:60,
                 from richest.h:4,
                 from answer.code:1:
/usr/include/x86_64-linux-gnu/c++/13/bits/c++config.h:308:33: note: ‘std::size_t’ declared here
  308 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~
answer.code:26:15: error: expected ‘;’ before ‘size’
   26 |         size_t size = candidates.size();
      |               ^~~~~
      |               ;
answer.code:27:15: error: ‘i’ was not declared in this scope
   27 |         for(; i + 1 < size; i += 2){
      |               ^
answer.code:27:23: error: ‘size’ was not declared in this scope
   27 |         for(; i + 1 < size; i += 2){
      |                       ^~~~
answer.code:33:15: error: expected ‘;’ before ‘comparisons’
   33 |         size_t comparisons = a.size();
      |               ^~~~~~~~~~~~
      |               ;
answer.code:36:12: error: ‘comparisons’ was not declared in this scope
   36 |         if(comparisons > remaining_queries){
      |            ^~~~~~~~~~~
answer.code:38:19: error: expected ‘;’ before ‘batch_size’
   38 |             size_t batch_size = remaining_queries;
      |                   ^~~~~~~~~~~
      |                   ;
answer.code:39:16: error: ‘batch_size’ was not declared in this scope
   39 |             if(batch_size == 0){
      |                ^~~~~~~~~~
answer.code:44:61: error: ‘batch_size’ was not declared in this scope
   44 |             std::vector<int> a_batch(a.begin(), a.begin() + batch_size);
      |                                                             ^~~~~~~~~~
answer.code:53:23: error: expected ‘;’ before ‘j’
   53 |             for(size_t j = 0; j < c.size(); ++j){
      |                       ^~
      |                       ;
answer.code:53:31: error: ‘j’ was not declared in this scope
   53 |             for(size_t j = 0; j < c.size(); ++j){
      |                               ^
answer.code:58:23: error: expected ‘;’ before ‘j’
   58 |             for(size_t j = 0; j < c.size(); ++j){
      |                       ^~
      |                       ;
answer.code:58:31: error: ‘j’ was not declared in this scope
   58 |             for(size_t j = 0; j < c.size(); ++j){
      |                               ^
answer.code:66:16: error: ‘i’ was not declared in this scope
   66 |             if(i < size){
      |                ^
answer.code:66:20: error: ‘size’ was not declared in this scope
   66 |             if(i < size){
      |                    ^~~~
answer.code:77:30: error: ‘comparisons’ was not declared in this scope
   77 |         remaining_queries -= comparisons;
      |                              ^~~~~~~~~~~
answer.code:84:12: error: ‘i’ was not declared in this scope
   84 |         if(i < size){
      |            ^
answer.code:84:16: error: ‘size’ was not declared in this scope
   84 |         if(i < size){
      |                ^~~~