反正我会问豆包

20 条评论

  • @ 2025-12-4 16:39:12

    1+1=? 算了几百年也算不出来

    • @ 2025-12-4 16:36:29

      #include #include #include using namespace std;

      // 每个位置的分值权重 const int score[9][9] = { {6,6,6,6,6,6,6,6,6}, {6,7,7,7,7,7,7,7,6}, {6,7,8,8,8,8,8,7,6}, {6,7,8,9,9,9,8,7,6}, {6,7,8,9,10,9,8,7,6}, {6,7,8,9,9,9,8,7,6}, {6,7,8,8,8,8,8,7,6}, {6,7,7,7,7,7,7,7,6}, {6,6,6,6,6,6,6,6,6} };

      int grid[9][9]; // 数独网格 bool row[9][10] = {false}; // row[i][j]表示第i行是否有数字j bool col[9][10] = {false}; // col[i][j]表示第i列是否有数字j bool block[3][3][10] = {false}; // block[i][j][k]表示第(i,j)九宫格是否有数字k int max_sum = -1; // 最高总分 vector<pair<int, int>> empty_cells; // 空单元格列表

      // 计算当前网格的总分 int calculate_sum() { int sum = 0; for (int i = 0; i < 9; ++i) { for (int j = 0; j < 9; ++j) { sum += grid[i][j] * score[i][j]; } } return sum; }

      // 回溯填充空格,idx为当前处理的空单元格索引 void backtrack(int idx, int current_sum) { // 所有空格填充完成,更新最高分 if (idx == empty_cells.size()) { if (current_sum > max_sum) { max_sum = current_sum; } return; }

      int x = empty_cells[idx].first;
      int y = empty_cells[idx].second;
      
      // 剪枝:如果当前分数 + 剩余空格最大可能分数 <= 已找到的最高分,直接返回
      int remaining_max = 0;
      for (int i = idx; i < empty_cells.size(); ++i) {
          int nx = empty_cells[i].first;
          int ny = empty_cells[i].second;
          remaining_max += 9 * score[nx][ny]; // 剩余空格最大可能值为9
      }
      if (current_sum + remaining_max <= max_sum) {
          return;
      }
      
      // 尝试填入1-9
      for (int num = 9; num >= 1; --num) { // 优先尝试大数,更快找到高分解
          if (!row[x][num] && !col[y][num] && !block[x/3][y/3][num]) {
              // 标记数字已使用
              row[x][num] = col[y][num] = block[x/3][y/3][num] = true;
              grid[x][y] = num;
              // 递归处理下一个空格
              backtrack(idx + 1, current_sum + num * score[x][y]);
              // 回溯:恢复状态
              row[x][num] = col[y][num] = block[x/3][y/3][num] = false;
              grid[x][y] = 0;
          }
      }
      

      }

      int main() { // 输入数独 for (int i = 0; i < 9; ++i) { for (int j = 0; j < 9; ++j) { cin >> grid[i][j]; int num = grid[i][j]; if (num != 0) { // 标记已使用的数字 row[i][num] = true; col[j][num] = true; block[i/3][j/3][num] = true; } else { // 记录空单元格 empty_cells.emplace_back(i, j); } } }

      // 计算初始分数(已填数字的分数)
      int initial_sum = 0;
      for (int i = 0; i < 9; ++i) {
          for (int j = 0; j < 9; ++j) {
              if (grid[i][j] != 0) {
                  initial_sum += grid[i][j] * score[i][j];
              }
          }
      }
      
      // 回溯求解
      backtrack(0, initial_sum);
      
      // 输出结果
      cout << max_sum << endl;
      
      return 0;
      

      }

      • NOIPS2009D

        • 2365

          • @ 2025-11-29 15:44:32

            2201

          • @ 2025-11-29 15:42:09

            GESP三级202409 平衡序列 我也要

            • @ 2025-11-29 15:42:59

              #include using namespace std;

              int main() { int t; cin >> t; // 读取测试用例组数 while (t--) { int n; cin >> n; // 读取序列长度 int a[10005]; // 存储序列(数据范围n≤10000,数组开稍大避免越界) int total = 0;

                  // 读取序列并计算总和
                  for (int i = 0; i < n; ++i) {
                      cin >> a[i];
                      total += a[i];
                  }
                  
                  // 总和为奇数,直接不可能平衡
                  if (total % 2 != 0) {
                      cout << "No" << endl;
                      continue;
                  }
                  
                  int target = total / 2;  // 目标前缀和
                  int prefix = 0;
                  bool found = false;
                  
                  // 遍历计算前缀和,判断是否达到目标
                  for (int i = 0; i < n; ++i) {
                      prefix += a[i];
                      if (prefix == target) {
                          found = true;
                          break;
                      }
                      // 优化:前缀和超过目标后直接退出(因为元素都是正整数)
                      if (prefix > target) {
                          break;
                      }
                  }
                  
                  cout << (found ? "Yes" : "No") << endl;
              }
              return 0;
              

              }

            • 哈哈哈

          • GESP三级202409

            • 平衡序列

            • @ 2025-11-29 15:42:54

              me too

            • @ 2025-11-29 15:43:07

              #include using namespace std;

              int main() { int t; cin >> t; // 读取测试用例组数 while (t--) { int n; cin >> n; // 读取序列长度 int a[10005]; // 存储序列(数据范围n≤10000,数组开稍大避免越界) int total = 0;

                  // 读取序列并计算总和
                  for (int i = 0; i < n; ++i) {
                      cin >> a[i];
                      total += a[i];
                  }
                  
                  // 总和为奇数,直接不可能平衡
                  if (total % 2 != 0) {
                      cout << "No" << endl;
                      continue;
                  }
                  
                  int target = total / 2;  // 目标前缀和
                  int prefix = 0;
                  bool found = false;
                  
                  // 遍历计算前缀和,判断是否达到目标
                  for (int i = 0; i < n; ++i) {
                      prefix += a[i];
                      if (prefix == target) {
                          found = true;
                          break;
                      }
                      // 优化:前缀和超过目标后直接退出(因为元素都是正整数)
                      if (prefix > target) {
                          break;
                      }
                  }
                  
                  cout << (found ? "Yes" : "No") << endl;
              }
              return 0;
              

              }

          • @ 2025-11-27 18:21:00

            this

            代码里不要有注释,不要用vector数组,不要定义复杂的变量名

          • @ 2025-11-25 16:38:50

            何意味

            • @ 2025-11-25 16:38:28

              • @ 2025-11-24 20:00:07

                xwj001

              • @ 2025-11-23 17:28:36

                B1012

                • @ 2025-11-24 14:45:39

                  #include #include // 用于 std::fixed 和 std::setprecision

                  using namespace std;

                  int main() { double x, a, b, c, d; // 读取输入的 5 个实数 cin >> x >> a >> b >> c >> d;

                  // 计算多项式的值
                  double result = a * x * x * x + b * x * x + c * x + d;
                  
                  // 输出结果,保留小数点后 7 位
                  cout << fixed << setprecision(7) << result << endl;
                  
                  return 0;
                  

                  }

              • @ 2025-11-23 9:49:55

                hm1001

                • @ 2025-11-24 14:40:27

                  #include #include // 为了使用 std::fixed 和 std::setprecision using namespace std;

                  int main() { double distance; cin >> distance;

                  double cost;
                  
                  if (distance <= 2.5) {
                      // 情况 1:距离不超过 2.5 千米,只收起步价
                      cost = 10.0;
                  } else if (distance <= 15) {
                      // 情况 2:距离超过 2.5 千米,但不超过 15 千米
                      // 起步价 + 超出 2.5 千米部分的费用
                      cost = 10.0 + (distance - 2.5) * 2.5;
                  } else {
                      // 情况 3:距离超过 15 千米
                      // 起步价 + 2.5 到 15 千米部分的费用 + 超出 15 千米部分的费用
                      cost = 10.0 + (15 - 2.5) * 2.5 + (distance - 15) * 3.0;
                  }
                  
                  // 输出费用,保留一位小数(因为人民币通常精确到角)
                  cout << fixed << setprecision(1) << cost << endl;
                  
                  return 0;
                  

                  }

              • @ 2025-11-23 9:32:22

                b1132

                • @ 2025-11-24 14:43:45

                  #include #include

                  using namespace std;

                  int main() { int n; // 读取游戏次数 cin >> n;

                  // 循环处理每一轮游戏
                  for (int i = 0; i < n; ++i) {
                      string s1, s2;
                      // 读取两个玩家的选择
                      cin >> s1 >> s2;
                  
                      // 判断结果
                      if (s1 == s2) {
                          // 如果选择相同,则为平局
                          cout << "Tie" << endl;
                      } else if (
                          // Player1 赢的情况
                          (s1 == "Rock" && s2 == "Scissors") ||
                          (s1 == "Scissors" && s2 == "Paper") ||
                          (s1 == "Paper" && s2 == "Rock")
                      ) {
                          cout << "Player1" << endl;
                      } else {
                          // 其他情况则 Player2 赢
                          cout << "Player2" << endl;
                      }
                  }
                  
                  return 0;
                  

                  }

              • 1748

                • @ 2025-11-24 14:38:06

                  #include #include #include #include #include using namespace std;

                  const int INF = 0x3f3f3f3f; const int MAXN = 1005; // 最大顶点数

                  struct Edge { int to, weight; Edge(int t, int w) : to(t), weight(w) {} };

                  vector adj[MAXN]; // 邻接表 int dist[MAXN]; // 距离数组 int cnt[MAXN]; // 记录每个顶点入队次数 bool inQueue[MAXN]; // 是否在队列中

                  // SPFA 算法判断是否存在从起点可达的负环 bool spfa(int start, int n) { memset(dist, INF, sizeof(dist)); memset(cnt, 0, sizeof(cnt)); memset(inQueue, false, sizeof(inQueue));

                  queue<int> q;
                  dist[start] = 0;
                  q.push(start);
                  inQueue[start] = true;
                  cnt[start] = 1;
                  
                  while (!q.empty()) {
                      int u = q.front();
                      q.pop();
                      inQueue[u] = false;
                      
                      for (Edge &e : adj[u]) {
                          int v = e.to;
                          int w = e.weight;
                          
                          if (dist[v] > dist[u] + w) {
                              dist[v] = dist[u] + w;
                              
                              if (!inQueue[v]) {
                                  q.push(v);
                                  inQueue[v] = true;
                                  cnt[v]++;
                                  
                                  // 如果入队次数超过 n,说明存在负环
                                  if (cnt[v] > n) {
                                      return true;
                                  }
                              }
                          }
                      }
                  }
                  
                  return false;
                  

                  }

                  int main() { int T; cin >> T;

                  while (T--) {
                      int n, m;
                      cin >> n >> m;
                      
                      // 清空邻接表
                      for (int i = 1; i <= n; i++) {
                          adj[i].clear();
                      }
                      
                      while (m--) {
                          int u, v, w;
                          cin >> u >> v >> w;
                          
                          if (w >= 0) {
                              // 双向边
                              adj[u].emplace_back(v, w);
                              adj[v].emplace_back(u, w);
                          } else {
                              // 单向边
                              adj[u].emplace_back(v, w);
                          }
                      }
                      
                      // 判断从顶点 1 出发是否存在可达的负环
                      if (spfa(1, n)) {
                          cout << "YES" << endl;
                      } else {
                          cout << "NO" << endl;
                      }
                  }
                  
                  return 0;
                  

                  }

              • 1616

                • @ 2025-11-22 16:32:29

                  #include #include #include

                  using namespace std;

                  // 判断一个数是否为完全平方数 bool isPerfectSquare(int x) { if (x < 0) return false; int s = sqrt(x); return s * s == x; }

                  int main() { int n; cin >> n;

                  vector<int> nums(n);
                  for (int i = 0; i < n; i++) {
                      cin >> nums[i];
                  }
                  
                  int count = 0;
                  // 枚举所有 i < j 的组合
                  for (int i = 0; i < n; i++) {
                      for (int j = i + 1; j < n; j++) {
                          int sum = nums[i] + nums[j];
                          if (isPerfectSquare(sum)) {
                              count++;
                          }
                      }
                  }
                  
                  cout << count << endl;
                  
                  return 0;
                  

                  }

              • 1617

              • 1685

              • B220

                • @ 2025-11-22 15:32:34

                  #include #include

                  using namespace std;

                  // 统计单个数字中数字 2 出现的次数 int countTwo(int num) { int count = 0; // 将数字转换为字符串,方便遍历每个字符 string s = to_string(num); for (char c : s) { if (c == '2') { count++; } } return count; }

                  int main() { int L, R; cin >> L >> R;

                  int total = 0;
                  // 遍历 [L, R] 中的每个数字
                  for (int i = L; i <= R; i++) {
                      total += countTwo(i);
                  }
                  
                  cout << total << endl;
                  
                  return 0;
                  

                  }

                • @ 2025-11-22 15:33:39

                  亲测满分

              • 1