From 2bd6c37cc66eca599fbe5b6d80d209155a8fb229 Mon Sep 17 00:00:00 2001 From: jianghaiying Date: Tue, 23 Sep 2025 14:26:00 +0800 Subject: [PATCH] task2 --- .gitignore | 10 ++++++++++ .python-version | 1 + README.md | 0 main.py | 30 ++++++++++++++++++++++++++++++ pyproject.toml | 7 +++++++ 5 files changed, 48 insertions(+) create mode 100644 .gitignore create mode 100644 .python-version create mode 100644 README.md create mode 100644 main.py create mode 100644 pyproject.toml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..505a3b1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,10 @@ +# Python-generated files +__pycache__/ +*.py[oc] +build/ +dist/ +wheels/ +*.egg-info + +# Virtual environments +.venv diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..24ee5b1 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..a74cba1 --- /dev/null +++ b/main.py @@ -0,0 +1,30 @@ +import numpy as np +from scipy.stats import wasserstein_distance + +def calculate_emd(vector1, vector2): + vec1 = np.array(vector1) + vec2 = np.array(vector2) + + positions = np.arange(len(vec1)) + emd = wasserstein_distance(positions, positions, vec1, vec2) + + total_weight = np.sum(vec1) # 权重和 + emd = emd * total_weight + + return emd + +def main(): + # input_str = input().strip() + line1 = input("输入第一行:").strip() + line2 = input("输入第二行:").strip() + + vector1 = list(map(float, line1.split())) + vector2 = list(map(float, line2.split())) + + # 计算EMD距离 + emd_value = calculate_emd(vector1, vector2) + + print(int(round(emd_value))) + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f7bc57d --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,7 @@ +[project] +name = "poker-task2" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.13" +dependencies = []