中国石油大学天梯赛真题模拟第五场

L2-4 秀恩爱分得快 (25 分)

题目链接

 

也不知道是踩了什么坑,WA了两个小时还de不出来。WA了两个点

中国石油大学天梯赛真题模拟第五场
#include "bits/stdc++.h"

using namespace std;
const int maxn = 1100;
double ans[maxn][maxn];
int mp[maxn][maxn];
int sex[maxn];

int main() {
    freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    int from, flag;
    char s[10];
    for (int i = 0; i < m; i++) {
        cin >> mp[i][0];
        for (int j = 1; j <= mp[i][0]; j++) {
            cin >> s;
            if (s[0] == '-') from = 1, flag = -1;
            else from = 0, flag = 1;
            for (int k = from; s[k] != '\0'; k++) {
                mp[i][j] = mp[i][j] * 10 + s[k] - '0';
            }
            sex[mp[i][j]] = flag;
        }
    }
    int a, b;
    cin >> a >> b;
    if (a < 0) a *= -1;
    if (b < 0) b *= -1;
    double maxa = 0, maxb = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 1; j <= mp[i][0]; j++) {
            if (mp[i][j] == a) {
                for (int k = 1; k <= mp[i][0]; k++) {
                    if (sex[a] != sex[mp[i][k]]) {
                        ans[a][mp[i][k]] += 1.0 / mp[i][0];
                    }
                    maxa = max(maxa, ans[a][mp[i][k]]);
                }
            }
            if (mp[i][j] == b) {
                for (int k = 1; k <= mp[i][0]; k++) {
                    if (sex[b] != sex[mp[i][k]])
                        ans[b][mp[i][k]] += 1.0 / mp[i][0];
                    maxb = max(maxb, ans[b][mp[i][k]]);
                }
            }
        }
    }
    if (ans[a][b] == maxa && ans[b][a] == maxb) {
        cout << a * sex[a] << " " << b * sex[b] << endl;
    } else {
        for (int i = 0; i < n; i++) {
            if (sex[i] != sex[a] && ans[a][i] == maxa) {
                cout << a * sex[a] << " " << i * sex[i] << endl;
            }
        }
        for (int i = 0; i < n; i++) {
            if (sex[i] != sex[b] && ans[b][i] == maxb) {
                cout << b * sex[b] << " " << i * sex[i] << endl;
            }
        }

    }
    return 0;
}
WA

 

上一篇:Codeforces 757B — Bash's Big Day(简单数学)(易wa)


下一篇:UVA 4879 Old Fafhioned Typefetting(易WA细节题)