其他分享
首页 > 其他分享> > 中国石油大学天梯赛真题模拟第五场

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

作者:互联网

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

 

标签:WA,int,第五场,++,赛真题,flag,maxn,mp,石油大学
来源: https://www.cnblogs.com/albert-biu/p/10614848.html