├── C++ └── GenerateTestData.cpp ├── README.md ├── java ├── Config.java └── GenerateTestData.java └── testData └── test_data.txt /C++/GenerateTestData.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int count_v = 10000; //顶点数 8 | int count_e = 40000; //边数 9 | 10 | map> mp; 11 | unordered_set st_temp; 12 | for (int i = 0; i < count_v; i++) 13 | mp.insert(pair>(i, st_temp)); 14 | 15 | for (int i = 0; i < count_e; i++) 16 | { 17 | int from = rand() % count_v; 18 | int to = rand() % count_v; 19 | while (from == to || mp[from].find(to) != mp[from].end()) 20 | { 21 | from = rand() % count_v; 22 | to = rand() % count_v; 23 | } 24 | mp[from].insert(to); 25 | } 26 | ofstream outfile("test_data_test.txt"); 27 | for (auto iter = mp.begin(); iter != mp.end(); ++iter) 28 | { 29 | for (auto iter1 = iter->second.begin(); iter1 != iter->second.end(); ++iter1) 30 | { 31 | outfile << iter->first << "," << *iter1 << ",100" << endl; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HWcode2020-TestData 2 | 3 | --- 4 | 5 | 华为codecraft2020模拟测试数据 6 | 7 | --- 8 | 9 | ## 指南 10 | 11 | ### 使用方法 12 | 13 | * /testData目录下为测试数据及其答案,部分测试数据由 @izhangrui 提供 14 | 15 | * /java目录下为测试数据生成源码,可通过Config接口配置账户总个数和转账总个数 16 | 17 | * /C++目录下cpp版数据生成程序由 @izhangrui 提供 18 | 19 | * 官方规则中循环数量不超过300W,推荐边个数设置为28W,顶点个数设置为2.6W 20 | 21 | ### 贡献者 22 | 23 | * @izhangrui 24 | 25 | ## 历史 26 | 27 | ### r0404 28 | 29 | * 应对官方更改规则,使用新的测试用例并替换原用例,测试输出为3512444,不保证正确 30 | 31 | ### r0403 32 | 33 | * 修改java版本顶点编号生成逻辑为完全随机 34 | 35 | * 增加cpp支持 36 | 37 | ### r0401 38 | 39 | * release 40 | 41 | 42 | -------------------------------------------------------------------------------- /java/Config.java: -------------------------------------------------------------------------------- 1 | public interface Config { 2 | String DATA_PATH = "java/test_data.txt"; 3 | int V_COUNT = 55000; 4 | int E_COUNT = 280000; 5 | int MAX_MONEY = 10000; 6 | long RANDOM_SEED = System.currentTimeMillis(); 7 | } 8 | -------------------------------------------------------------------------------- /java/GenerateTestData.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class GenerateTestData implements Config { 5 | private static Map> graph; 6 | private static int[] dict = new int[V_COUNT]; 7 | private static Random random = new Random(RANDOM_SEED); 8 | static { 9 | graph = new HashMap<>(); 10 | Set set = new HashSet<>(); 11 | for (int i = 0; i < V_COUNT; i++){ 12 | graph.put(i, new HashSet<>()); 13 | int v = random.nextInt(Integer.MAX_VALUE); 14 | while (set.contains(v)){ 15 | v = random.nextInt(Integer.MAX_VALUE); 16 | } 17 | dict[i] = v; 18 | } 19 | } 20 | 21 | public static void main(String[] args){ 22 | Random random = new Random(); 23 | for (int i = 0; i < E_COUNT; i++){ 24 | int from = random.nextInt(V_COUNT); 25 | int to = random.nextInt(V_COUNT); 26 | while (from == to || graph.get(from).contains(to)){ 27 | from = random.nextInt(V_COUNT); 28 | to = random.nextInt(V_COUNT); 29 | } 30 | graph.get(from).add(to); 31 | } 32 | write(graph); 33 | } 34 | 35 | private static void write(Map> graph){ 36 | File dest = new File(DATA_PATH); 37 | try(PrintWriter writer = new PrintWriter(new BufferedWriter(new FileWriter(dest)))){ 38 | for(Map.Entry> pointEntry : graph.entrySet()){ 39 | for (int to : pointEntry.getValue()){ 40 | writer.println(dict[pointEntry.getKey()] + "," + dict[to] + "," + random.nextInt(MAX_MONEY)); 41 | } 42 | } 43 | } 44 | catch (IOException e){ 45 | System.out.println("写入文件失败:" + e.getMessage()); 46 | throw new RuntimeException(e); 47 | } 48 | } 49 | } 50 | --------------------------------------------------------------------------------