/ WOJ /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 2ms 532.0 KiB
#2 Wrong Answer 1ms 488.0 KiB
#3 Wrong Answer 1ms 328.0 KiB
#4 Wrong Answer 1ms 324.0 KiB
#5 Wrong Answer 1ms 324.0 KiB
#6 Wrong Answer 1ms 348.0 KiB
#7 Wrong Answer 1ms 508.0 KiB
#8 Wrong Answer 1ms 536.0 KiB
#9 Wrong Answer 1ms 480.0 KiB
#10 Wrong Answer 1ms 328.0 KiB

代码

#include <iostream>
#include <vector>
#include <unordered_map>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

// 求解方程ax + b = c的x,若无法求解或解为负返回 -1
int solveEquation(int a, int b, int c) {
    if (a == 0) {
        return (b == c)? 0 : -1;
    }
    if ((c - b) % a != 0) {
        return -1;
    }
    int x = (c - b) / a;
    return (x >= 0)? x : -1;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<vector<int>> equations(n, vector<int>(3));
        for (int i = 0; i < n; ++i) {
            cin >> equations[i][0] >> equations[i][1] >> equations[i][2];
        }

        gp_hash_table<int, int> solutionCount;
        // 遍历每个方程可能的参数组合
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 6; ++j) {  // 每个方程有6种参数组合方式
                int a, b, c;
                switch (j) {
                    case 0: a = equations[i][0]; b = equations[i][1]; c = equations[i][2]; break;
                    case 1: a = equations[i][0]; b = equations[i][2]; c = equations[i][1]; break;
                    case 2: a = equations[i][1]; b = equations[i][0]; c = equations[i][2]; break;
                    case 3: a = equations[i][1]; b = equations[i][2]; c = equations[i][0]; break;
                    case 4: a = equations[i][2]; b = equations[i][0]; c = equations[i][1]; break;
                    case 5: a = equations[i][2]; b = equations[i][1]; c = equations[i][0]; break;
                }
                int x = solveEquation(a, b, c);
                if (x != -1) {
                    solutionCount[x]++;
                }
            }
        }

        // 找出出现次数等于方程数量的解
        for (const auto& pair : solutionCount) {
            if (pair.second == n) {
                cout << pair.first << endl;
                break;
            }
        }
    }
    return 0;
}

信息

递交者
类型
递交
题目
P1000 云剪贴板
题目数据
下载
语言
C++
递交时间
2025-03-08 13:12:54
评测时间
2025-03-08 13:12:54
评测机
分数
0
总耗时
17ms
峰值内存
536.0 KiB