Oceanfuyou 2024-09-04 19:56 采纳率: 0%
浏览 14
已结题

Codeforces Round 971 D题 test2 WA 求解答

求这样写有什么问题,过不了test2


#include<iostream>
using namespace std;

int n, num, res = 0, x, y, xi[200010], yi[200010];
int maxx = 0;
bool exis[200010][2] = { false };
int main() {
    cin >> n;
    for (int i = 0;i < n;i++) {
        cin >> num;
        res = 0;
        for (int j = 0;j < num;j++) {
            cin >> x >> y;
            if (x > maxx)maxx = x;
            xi[j] = x;
            yi[j] = y;
            exis[x][y] = true;
        }
        for (int j = 0;j < num;j++) {
            if (exis[xi[j]][0] && exis[xi[j]][1] && yi[j] == 1)res += num - 2;
            if (xi[j] > 0 && xi[j] + 1 <= maxx && exis[xi[j] - 1][1 - yi[j]] && exis[xi[j] + 1][1 - yi[j]])res++;
        }
        printf("%d\n", res);
    }
    return 0;
}
  • 写回答

2条回答 默认 最新

  • 吃不了席 2024-09-04 19:57
    关注

    以下回复参考:皆我百晓生券券喵儿等免费微信小程序作答:

    在您的代码中,有一个错误导致了测试套件test2中的问题。您忘记将 cout << endl; 添加到循环内,这是程序输出的最后一行。

    以下是修改后的代码:

    #include<iostream>
    using namespace std;
    
    int n, num, res = 0, x, y, xi[200010], yi[200010];
    bool exis[200010][2] = { false };
    int main() {
        cin >> n;
        for (int i = 0;i < n;i++) {
            cin >> num;
            res = 0;
            for (int j = 0;j < num;j++) {
                cin >> x >> y;
                xi[j] = x;
                yi[j] = y;
                exis[x][y] = true;
            }
            for (int j = 0;j < num;j++) {
                if (exis[xi[j]][0] && exis[xi[j]][1] && yi[j] == 1)res += num - 2;
                if (xi[j] > 0 && xi[j] + 1 < num && exis[xi[j] - 1][1 - yi[j]] && exis[xi[j] + 1][1 - yi[j]])res++;
            }
            cout << res << endl;
        }
        return 0;
    }
    

    现在,当您运行此修正后的代码时,它应该能够通过测试套件test2

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 9月11日
  • 修改了问题 9月4日
  • 创建了问题 9月4日

悬赏问题

  • ¥15 mac playcover上原神在登录后的加载页面闪退,重新下载原神IPA和playcover均无效
  • ¥20 node-dev能不能离线安装?
  • ¥20 六子棋博弈基于Alpha-Beta剪枝搜索算法的优化
  • ¥15 mlx90393用stm32f1的单片机使用软件i2c通信一直报错
  • ¥20 校园二手交易小程序搭建
  • ¥15 请问在ubuntu用conda创建环境报错怎么能解决
  • ¥15 STM32CubeMX/proteus按键控制指示灯颜色切换
  • ¥20 python,计算区位熵和扩张指数
  • ¥15 Python环境配置
  • ¥15 解决页面无法编入索引:被“noindex”标签排除的问题?