HDU 2574.Hdu Girls' Day

xiaoxiao2021-02-28  4

题目:http://acm.hdu.edu.cn/showproblem.php?pid=2574

AC代码(C++):

#include <iostream> #include <queue> #include <vector> #include <set> #include <string> #include <algorithm> #include <string.h> #include <math.h> #define INF 0x3f3f3f3f #define eps 1e-8 typedef unsigned long long ull; typedef long long ll; using namespace std; struct GIRL { char name[25]; int uni; }; int n; GIRL girl[1005]; int main() { int t; cin >> t; while (t--) { cin >> n; int A; for (int i = 0; i < n; i++) { cin >> girl[i].name >> A; girl[i].uni = 0; for (int j = 2; j*j <= A;) { if (A%j == 0) { girl[i].uni++; while (A%j == 0) { A /= j; } } if (j == 2)j++; else j += 2; } if (A != 1) { girl[i].uni++; } } int MAX = 0; for (int i = 0; i < n; i++) { if (girl[i].uni > girl[MAX].uni)MAX = i; else if (girl[i].uni == girl[MAX].uni&&strcmp(girl[i].name, girl[MAX].name) < 0)MAX = i; } cout << girl[MAX].name << endl; } //system("pause"); } 总结: 整数的唯一分解.

转载请注明原文地址: https://www.6miu.com/read-1750333.html

最新回复(0)