├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── lib ├── .gitignore └── json │ ├── CMakeLists.txt │ ├── json │ ├── json-forwards.h │ └── json.h │ └── jsoncpp.cpp ├── src ├── BAF │ └── baf-choose.cpp ├── HCF-MoreKeys │ ├── morekey.cpp │ ├── portal-sample.txt │ └── result-sample.txt ├── HCF-RESWUEV1 │ └── reswue.cpp ├── HCF-SingleWork │ ├── act-sample.txt │ ├── act.cpp │ └── way-sample.txt ├── HCF │ ├── choose.cpp │ ├── portal-sample.txt │ └── result-sample.txt ├── LABEL ├── MultField │ ├── mult-choose.cpp │ ├── mult-portal-sample.txt │ └── mult-result-sample.txt ├── TriField │ ├── result-sample.txt │ └── tri-choose.cpp └── portals2json.user.js └── wiki ├── 01.jpg ├── 02.png ├── 03.png └── 04.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/cmake 2 | # Edit at https://www.gitignore.io/?templates=cmake 3 | 4 | ### CMake ### 5 | CMakeLists.txt.user 6 | CMakeCache.txt 7 | CMakeFiles 8 | CMakeScripts 9 | Testing 10 | Makefile 11 | cmake_install.cmake 12 | install_manifest.txt 13 | compile_commands.json 14 | CTestTestfile.cmake 15 | _deps 16 | 17 | ### CMake Patch ### 18 | # External projects 19 | *-prefix/ 20 | 21 | # End of https://www.gitignore.io/api/cmake 22 | 23 | *.exe 24 | *.txt 25 | !*-sample.txt 26 | 27 | .vscode 28 | build* 29 | release.* 30 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | project(Ingress-Field-Design) 4 | 5 | set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/release.${CMAKE_SYSTEM_NAME}.${CMAKE_SYSTEM_PROCESSOR}) 6 | 7 | set(CMAKE_CXX_STANDARD 14) 8 | set(CMAKE_CXX_FLAGS_DEBUG "-g -Wall") 9 | 10 | add_subdirectory(lib/json) 11 | 12 | add_executable(BAF src/BAF/baf-choose.cpp) 13 | target_link_libraries(BAF jsoncpp_lib) 14 | set_target_properties(BAF PROPERTIES OUTPUT_NAME baf-choose) 15 | install(TARGETS BAF 16 | DESTINATION BAF) 17 | 18 | add_executable(HCF src/HCF/choose.cpp) 19 | target_link_libraries(HCF jsoncpp_lib) 20 | set_target_properties(HCF PROPERTIES OUTPUT_NAME choose) 21 | install(TARGETS HCF 22 | DESTINATION HCF) 23 | install(FILES src/HCF/result-sample.txt src/HCF/portal-sample.txt 24 | DESTINATION HCF) 25 | 26 | add_executable(HCF-MoreKeys src/HCF-MoreKeys/morekey.cpp) 27 | target_link_libraries(HCF-MoreKeys jsoncpp_lib) 28 | set_target_properties(HCF-MoreKeys PROPERTIES OUTPUT_NAME morekey) 29 | install(TARGETS HCF-MoreKeys 30 | DESTINATION HCF-MoreKeys) 31 | install(FILES src/HCF-MoreKeys/result-sample.txt src/HCF-MoreKeys/portal-sample.txt 32 | DESTINATION HCF-MoreKeys) 33 | 34 | add_executable(HCF-RESWUEV1 src/HCF-RESWUEV1/reswue.cpp) 35 | target_link_libraries(HCF-RESWUEV1 jsoncpp_lib) 36 | set_target_properties(HCF-RESWUEV1 PROPERTIES OUTPUT_NAME reswue) 37 | install(TARGETS HCF-RESWUEV1 38 | DESTINATION HCF-RESWUEV1) 39 | 40 | add_executable(HCF-SingleWork src/HCF-SingleWork/act.cpp) 41 | target_link_libraries(HCF-SingleWork jsoncpp_lib) 42 | set_target_properties(HCF-SingleWork PROPERTIES OUTPUT_NAME act) 43 | install(TARGETS HCF-SingleWork 44 | DESTINATION HCF-SingleWork) 45 | install(FILES src/HCF-SingleWork/act-sample.txt src/HCF-SingleWork/way-sample.txt 46 | DESTINATION HCF-SingleWork) 47 | 48 | add_executable(MultField src/MultField/mult-choose.cpp) 49 | target_link_libraries(MultField jsoncpp_lib) 50 | set_target_properties(MultField PROPERTIES OUTPUT_NAME mult-choose) 51 | install(TARGETS MultField 52 | DESTINATION MultField) 53 | install(FILES src/MultField/mult-result-sample.txt src/MultField/mult-portal-sample.txt 54 | DESTINATION MultField) 55 | 56 | add_executable(TriField src/TriField/tri-choose.cpp) 57 | target_link_libraries(TriField jsoncpp_lib) 58 | set_target_properties(TriField PROPERTIES OUTPUT_NAME tri-choose) 59 | install(TARGETS TriField 60 | DESTINATION TriField) 61 | install(FILES src/TriField/result-sample.txt 62 | DESTINATION TriField) 63 | 64 | install(FILES src/portals2json.user.js src/LABEL 65 | DESTINATION .) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Konano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ingress-Field-Design 2 | 3 | ## How to compiler? 4 | 5 | ```bash 6 | mkdir build 7 | cd build 8 | cmake .. 9 | make 10 | make install 11 | ``` 12 | 13 | In Windows, you need to convert `.cpp` and `.txt` from UTF-8 to GBK. 14 | 15 | 41 | 42 | ## How to use it? 43 | 44 | [English](https://github.com/Konano/Ingress-Field-Design/wiki/Instructions-for-use) 45 | 46 | [中文](https://github.com/Konano/Ingress-Field-Design/wiki/%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E) 47 | 48 | ## Refactoring…… 49 | 50 | - [x] BAF 51 | - [x] HCF 52 | - [ ] HCF-MoreKeys 53 | - [ ] HCF-RESWUEV1 54 | - [ ] HCF-SingleWork 55 | - [x] MultField 56 | - [ ] TriField -------------------------------------------------------------------------------- /lib/.gitignore: -------------------------------------------------------------------------------- 1 | *.a -------------------------------------------------------------------------------- /lib/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(jsoncpp_lib jsoncpp.cpp) 2 | target_include_directories(jsoncpp_lib INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) -------------------------------------------------------------------------------- /lib/json/json/json-forwards.h: -------------------------------------------------------------------------------- 1 | /// Json-cpp amalgamated forward header (http://jsoncpp.sourceforge.net/). 2 | /// It is intended to be used with #include "json/json-forwards.h" 3 | /// This header provides forward declaration for all JsonCpp types. 4 | 5 | // ////////////////////////////////////////////////////////////////////// 6 | // Beginning of content of file: LICENSE 7 | // ////////////////////////////////////////////////////////////////////// 8 | 9 | /* 10 | The JsonCpp library's source code, including accompanying documentation, 11 | tests and demonstration applications, are licensed under the following 12 | conditions... 13 | 14 | Baptiste Lepilleur and The JsonCpp Authors explicitly disclaim copyright in all 15 | jurisdictions which recognize such a disclaimer. In such jurisdictions, 16 | this software is released into the Public Domain. 17 | 18 | In jurisdictions which do not recognize Public Domain property (e.g. Germany as of 19 | 2010), this software is Copyright (c) 2007-2010 by Baptiste Lepilleur and 20 | The JsonCpp Authors, and is released under the terms of the MIT License (see below). 21 | 22 | In jurisdictions which recognize Public Domain property, the user of this 23 | software may choose to accept it either as 1) Public Domain, 2) under the 24 | conditions of the MIT License (see below), or 3) under the terms of dual 25 | Public Domain/MIT License conditions described here, as they choose. 26 | 27 | The MIT License is about as close to Public Domain as a license can get, and is 28 | described in clear, concise terms at: 29 | 30 | http://en.wikipedia.org/wiki/MIT_License 31 | 32 | The full text of the MIT License follows: 33 | 34 | ======================================================================== 35 | Copyright (c) 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 36 | 37 | Permission is hereby granted, free of charge, to any person 38 | obtaining a copy of this software and associated documentation 39 | files (the "Software"), to deal in the Software without 40 | restriction, including without limitation the rights to use, copy, 41 | modify, merge, publish, distribute, sublicense, and/or sell copies 42 | of the Software, and to permit persons to whom the Software is 43 | furnished to do so, subject to the following conditions: 44 | 45 | The above copyright notice and this permission notice shall be 46 | included in all copies or substantial portions of the Software. 47 | 48 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 49 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 50 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 51 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 52 | BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 53 | ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 54 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 55 | SOFTWARE. 56 | ======================================================================== 57 | (END LICENSE TEXT) 58 | 59 | The MIT license is compatible with both the GPL and commercial 60 | software, affording one all of the rights of Public Domain with the 61 | minor nuisance of being required to keep the above copyright notice 62 | and license text in the source code. Note also that by accepting the 63 | Public Domain "license" you can re-license your copy using whatever 64 | license you like. 65 | 66 | */ 67 | 68 | // ////////////////////////////////////////////////////////////////////// 69 | // End of content of file: LICENSE 70 | // ////////////////////////////////////////////////////////////////////// 71 | 72 | 73 | 74 | 75 | 76 | #ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED 77 | # define JSON_FORWARD_AMALGAMATED_H_INCLUDED 78 | /// If defined, indicates that the source file is amalgamated 79 | /// to prevent private header inclusion. 80 | #define JSON_IS_AMALGAMATION 81 | 82 | // ////////////////////////////////////////////////////////////////////// 83 | // Beginning of content of file: include/json/config.h 84 | // ////////////////////////////////////////////////////////////////////// 85 | 86 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 87 | // Distributed under MIT license, or public domain if desired and 88 | // recognized in your jurisdiction. 89 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 90 | 91 | #ifndef JSON_CONFIG_H_INCLUDED 92 | #define JSON_CONFIG_H_INCLUDED 93 | #include 94 | #include 95 | #include 96 | #include 97 | #include 98 | #include 99 | #include 100 | #include 101 | 102 | /// If defined, indicates that json library is embedded in CppTL library. 103 | //# define JSON_IN_CPPTL 1 104 | 105 | /// If defined, indicates that json may leverage CppTL library 106 | //# define JSON_USE_CPPTL 1 107 | /// If defined, indicates that cpptl vector based map should be used instead of 108 | /// std::map 109 | /// as Value container. 110 | //# define JSON_USE_CPPTL_SMALLMAP 1 111 | 112 | // If non-zero, the library uses exceptions to report bad input instead of C 113 | // assertion macros. The default is to use exceptions. 114 | #ifndef JSON_USE_EXCEPTION 115 | #define JSON_USE_EXCEPTION 1 116 | #endif 117 | 118 | // Temporary, tracked for removal with issue #982. 119 | #ifndef JSON_USE_NULLREF 120 | #define JSON_USE_NULLREF 1 121 | #endif 122 | 123 | /// If defined, indicates that the source file is amalgamated 124 | /// to prevent private header inclusion. 125 | /// Remarks: it is automatically defined in the generated amalgamated header. 126 | // #define JSON_IS_AMALGAMATION 127 | 128 | #ifdef JSON_IN_CPPTL 129 | #include 130 | #ifndef JSON_USE_CPPTL 131 | #define JSON_USE_CPPTL 1 132 | #endif 133 | #endif 134 | 135 | #ifdef JSON_IN_CPPTL 136 | #define JSON_API CPPTL_API 137 | #elif defined(JSON_DLL_BUILD) 138 | #if defined(_MSC_VER) || defined(__MINGW32__) 139 | #define JSON_API __declspec(dllexport) 140 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 141 | #elif defined(__GNUC__) || defined(__clang__) 142 | #define JSON_API __attribute__((visibility("default"))) 143 | #endif // if defined(_MSC_VER) 144 | #elif defined(JSON_DLL) 145 | #if defined(_MSC_VER) || defined(__MINGW32__) 146 | #define JSON_API __declspec(dllimport) 147 | #define JSONCPP_DISABLE_DLL_INTERFACE_WARNING 148 | #endif // if defined(_MSC_VER) 149 | #endif // ifdef JSON_IN_CPPTL 150 | #if !defined(JSON_API) 151 | #define JSON_API 152 | #endif 153 | 154 | #if defined(_MSC_VER) && _MSC_VER < 1800 155 | #error \ 156 | "ERROR: Visual Studio 12 (2013) with _MSC_VER=1800 is the oldest supported compiler with sufficient C++11 capabilities" 157 | #endif 158 | 159 | #if defined(_MSC_VER) && _MSC_VER < 1900 160 | // As recommended at 161 | // https://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010 162 | extern JSON_API int msvc_pre1900_c99_snprintf(char* outBuf, size_t size, 163 | const char* format, ...); 164 | #define jsoncpp_snprintf msvc_pre1900_c99_snprintf 165 | #else 166 | #define jsoncpp_snprintf std::snprintf 167 | #endif 168 | 169 | // If JSON_NO_INT64 is defined, then Json only support C++ "int" type for 170 | // integer 171 | // Storages, and 64 bits integer support is disabled. 172 | // #define JSON_NO_INT64 1 173 | 174 | // JSONCPP_OVERRIDE is maintained for backwards compatibility of external tools. 175 | // C++11 should be used directly in JSONCPP. 176 | #define JSONCPP_OVERRIDE override 177 | 178 | #if __cplusplus >= 201103L 179 | #define JSONCPP_NOEXCEPT noexcept 180 | #define JSONCPP_OP_EXPLICIT explicit 181 | #elif defined(_MSC_VER) && _MSC_VER < 1900 182 | #define JSONCPP_NOEXCEPT throw() 183 | #define JSONCPP_OP_EXPLICIT explicit 184 | #elif defined(_MSC_VER) && _MSC_VER >= 1900 185 | #define JSONCPP_NOEXCEPT noexcept 186 | #define JSONCPP_OP_EXPLICIT explicit 187 | #else 188 | #define JSONCPP_NOEXCEPT throw() 189 | #define JSONCPP_OP_EXPLICIT 190 | #endif 191 | 192 | #ifdef __clang__ 193 | #if __has_extension(attribute_deprecated_with_message) 194 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) 195 | #endif 196 | #elif defined(__GNUC__) // not clang (gcc comes later since clang emulates gcc) 197 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)) 198 | #define JSONCPP_DEPRECATED(message) __attribute__((deprecated(message))) 199 | #elif (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 200 | #define JSONCPP_DEPRECATED(message) __attribute__((__deprecated__)) 201 | #endif // GNUC version 202 | #elif defined(_MSC_VER) // MSVC (after clang because clang on Windows emulates 203 | // MSVC) 204 | #define JSONCPP_DEPRECATED(message) __declspec(deprecated(message)) 205 | #endif // __clang__ || __GNUC__ || _MSC_VER 206 | 207 | #if !defined(JSONCPP_DEPRECATED) 208 | #define JSONCPP_DEPRECATED(message) 209 | #endif // if !defined(JSONCPP_DEPRECATED) 210 | 211 | #if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ >= 6)) 212 | #define JSON_USE_INT64_DOUBLE_CONVERSION 1 213 | #endif 214 | 215 | #if !defined(JSON_IS_AMALGAMATION) 216 | 217 | #include "allocator.h" 218 | #include "version.h" 219 | 220 | #endif // if !defined(JSON_IS_AMALGAMATION) 221 | 222 | namespace Json { 223 | typedef int Int; 224 | typedef unsigned int UInt; 225 | #if defined(JSON_NO_INT64) 226 | typedef int LargestInt; 227 | typedef unsigned int LargestUInt; 228 | #undef JSON_HAS_INT64 229 | #else // if defined(JSON_NO_INT64) 230 | // For Microsoft Visual use specific types as long long is not supported 231 | #if defined(_MSC_VER) // Microsoft Visual Studio 232 | typedef __int64 Int64; 233 | typedef unsigned __int64 UInt64; 234 | #else // if defined(_MSC_VER) // Other platforms, use long long 235 | typedef int64_t Int64; 236 | typedef uint64_t UInt64; 237 | #endif // if defined(_MSC_VER) 238 | typedef Int64 LargestInt; 239 | typedef UInt64 LargestUInt; 240 | #define JSON_HAS_INT64 241 | #endif // if defined(JSON_NO_INT64) 242 | 243 | template 244 | using Allocator = 245 | typename std::conditional, 246 | std::allocator>::type; 247 | using String = std::basic_string, Allocator>; 248 | using IStringStream = 249 | std::basic_istringstream; 251 | using OStringStream = 252 | std::basic_ostringstream; 254 | using IStream = std::istream; 255 | using OStream = std::ostream; 256 | } // namespace Json 257 | 258 | // Legacy names (formerly macros). 259 | using JSONCPP_STRING = Json::String; 260 | using JSONCPP_ISTRINGSTREAM = Json::IStringStream; 261 | using JSONCPP_OSTRINGSTREAM = Json::OStringStream; 262 | using JSONCPP_ISTREAM = Json::IStream; 263 | using JSONCPP_OSTREAM = Json::OStream; 264 | 265 | #endif // JSON_CONFIG_H_INCLUDED 266 | 267 | // ////////////////////////////////////////////////////////////////////// 268 | // End of content of file: include/json/config.h 269 | // ////////////////////////////////////////////////////////////////////// 270 | 271 | 272 | 273 | 274 | 275 | 276 | // ////////////////////////////////////////////////////////////////////// 277 | // Beginning of content of file: include/json/forwards.h 278 | // ////////////////////////////////////////////////////////////////////// 279 | 280 | // Copyright 2007-2010 Baptiste Lepilleur and The JsonCpp Authors 281 | // Distributed under MIT license, or public domain if desired and 282 | // recognized in your jurisdiction. 283 | // See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE 284 | 285 | #ifndef JSON_FORWARDS_H_INCLUDED 286 | #define JSON_FORWARDS_H_INCLUDED 287 | 288 | #if !defined(JSON_IS_AMALGAMATION) 289 | #include "config.h" 290 | #endif // if !defined(JSON_IS_AMALGAMATION) 291 | 292 | namespace Json { 293 | 294 | // writer.h 295 | class StreamWriter; 296 | class StreamWriterBuilder; 297 | class Writer; 298 | class FastWriter; 299 | class StyledWriter; 300 | class StyledStreamWriter; 301 | 302 | // reader.h 303 | class Reader; 304 | class CharReader; 305 | class CharReaderBuilder; 306 | 307 | // json_features.h 308 | class Features; 309 | 310 | // value.h 311 | typedef unsigned int ArrayIndex; 312 | class StaticString; 313 | class Path; 314 | class PathArgument; 315 | class Value; 316 | class ValueIteratorBase; 317 | class ValueIterator; 318 | class ValueConstIterator; 319 | 320 | } // namespace Json 321 | 322 | #endif // JSON_FORWARDS_H_INCLUDED 323 | 324 | // ////////////////////////////////////////////////////////////////////// 325 | // End of content of file: include/json/forwards.h 326 | // ////////////////////////////////////////////////////////////////////// 327 | 328 | 329 | 330 | 331 | 332 | #endif //ifndef JSON_FORWARD_AMALGAMATED_H_INCLUDED 333 | -------------------------------------------------------------------------------- /src/BAF/baf-choose.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | #define pi acos(-1) 18 | #define maxPortal 1000 19 | 20 | char tmp_char; 21 | 22 | struct Portal 23 | { 24 | double lat, lng, x, y, z, S; 25 | string guid, latlng, label; 26 | Portal() : S(0) {} 27 | Portal(double x, double y, double z) : x(x), y(y), z(z), S(0) {} 28 | void to_xyz() { 29 | istringstream iss(latlng); 30 | iss >> lat >> tmp_char >> lng; 31 | x = cos(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 32 | y = sin(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 33 | z = sin(lng / 180.0 * pi); 34 | } 35 | bool operator==(const Portal &a) const { return guid == a.guid; } 36 | bool operator<(const Portal &a) const { return S < a.S; } 37 | } P[maxPortal]; 38 | 39 | inline Portal spin(const Portal &a, const Portal &b) { 40 | return Portal( 41 | (b.y * (a.x * b.y - a.y * b.x) - b.z * (a.z * b.x - a.x * b.z)), 42 | (b.z * (a.y * b.z - a.z * b.y) - b.x * (a.x * b.y - a.y * b.x)), 43 | (b.x * (a.z * b.x - a.x * b.z) - b.y * (a.y * b.z - a.z * b.y)) 44 | ); 45 | } 46 | 47 | inline double _cos(const Portal &a, const Portal &b) { 48 | return (a.x * b.x + a.y * b.y + a.z * b.z) 49 | / sqrt(a.x * a.x + a.y * a.y + a.z * a.z) 50 | / sqrt(b.x * b.x + b.y * b.y + b.z * b.z); 51 | } 52 | 53 | inline double angle(const Portal &a, const Portal &b, const Portal &c) { 54 | return acos(_cos(spin(a, b), spin(c, b))); 55 | } 56 | 57 | inline double area(const Portal &a, const Portal &b, const Portal &c) { 58 | return angle(a,b,c) + angle(b,c,a) + angle(c,a,b) - pi; 59 | } 60 | 61 | inline Portal normal(const Portal &a, const Portal &b) 62 | { 63 | return Portal( 64 | a.y * b.z - a.z * b.y, 65 | a.z * b.x - a.x * b.z, 66 | a.x * b.y - a.y * b.x 67 | ); 68 | } 69 | inline double dot(const Portal &a, const Portal &b) { return a.x * b.x + a.y * b.y + a.z * b.z;} 70 | inline bool isLeft(const Portal &a, const Portal &b, const Portal &c) { return dot(c, normal(a, b))>0;} 71 | 72 | inline bool inField(const Portal &a, const Portal &b, const Portal &c, const Portal &d) 73 | { 74 | if (d == a || d == b || d == c) return false; 75 | if (!isLeft(a, b, c)) 76 | return isLeft(a, c, d) && isLeft(c, b, d) && isLeft(b, a, d); 77 | else 78 | return isLeft(a, b, d) && isLeft(b, c, d) && isLeft(c, a, d); 79 | } 80 | 81 | int num = 0; 82 | 83 | inline void import(const char *localFileName) { 84 | string str, chunk; 85 | 86 | try { 87 | ifstream fin(localFileName); 88 | if (fin) { 89 | while (getline(fin, chunk) && chunk != "") str += chunk; 90 | } else throw ""; 91 | } catch (...) { 92 | puts("Please copy bookmarks into here:"); 93 | while (getline(cin, chunk) && chunk != "") str += chunk; 94 | } 95 | 96 | Json::Reader reader; 97 | Json::Value input; 98 | Json::Value::Members arrayMember; 99 | reader.parse(str, input); 100 | 101 | num = input["portals"]["idOthers"]["bkmrk"].getMemberNames().size(); 102 | 103 | printf("Portal nums: %d\n", num); 104 | 105 | if (num > maxPortal) { 106 | printf("Only support no more than %d portals.\n", maxPortal); 107 | getchar(); 108 | exit(0); 109 | } 110 | 111 | num = 0; 112 | 113 | arrayMember = input["portals"]["idA"]["bkmrk"].getMemberNames(); 114 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) { 115 | P[num].guid = input["portals"]["idA"]["bkmrk"][*iter]["guid"].asString(); 116 | P[num].latlng = input["portals"]["idA"]["bkmrk"][*iter]["latlng"].asString(); 117 | P[num].label = input["portals"]["idA"]["bkmrk"][*iter]["label"].asString(); 118 | P[num].to_xyz(); 119 | num += 1; 120 | } 121 | } 122 | 123 | Json::Value bookmarks, drawnitems; 124 | int bm_num = 0, dr_num = 0; 125 | 126 | inline void addPortal(const Portal &a) 127 | { 128 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["guid"] = a.guid; 129 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["latlng"] = a.latlng; 130 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["label"] = a.label; 131 | bm_num++; 132 | } 133 | 134 | inline void addLink(const Portal &a, const Portal &b) 135 | { 136 | drawnitems[dr_num]["latLngs"][0]["lat"] = to_string(a.lat); 137 | drawnitems[dr_num]["latLngs"][0]["lng"] = to_string(a.lng); 138 | drawnitems[dr_num]["latLngs"][1]["lat"] = to_string(b.lat); 139 | drawnitems[dr_num]["latLngs"][1]["lng"] = to_string(b.lng); 140 | drawnitems[dr_num]["color"] = "#0099FF"; 141 | drawnitems[dr_num]["type"] = "polyline"; 142 | dr_num++; 143 | } 144 | 145 | int layer[maxPortal], nxt[maxPortal], maxLayer = 0; 146 | 147 | int main() { 148 | import("portal.txt"); 149 | 150 | for (int i = 2; i < num; i++) P[i].S = area(P[0], P[1], P[i]); 151 | sort(P+2, P+num); 152 | 153 | for (int i = 2; i < num; i++) { 154 | layer[i] = 1, nxt[i] = 0; 155 | for (int j = 2; j < i; j++) { 156 | if (inField(P[0], P[1], P[i], P[j]) && layer[i] < layer[j] + 1) 157 | layer[i] = layer[j] + 1, nxt[i]=j; 158 | } 159 | if (!maxLayer || layer[maxLayer] < layer[i]) maxLayer = i; 160 | } 161 | 162 | addLink(P[0], P[1]); addPortal(P[0]); addPortal(P[1]); 163 | while (maxLayer) addLink(P[maxLayer], P[0]), addLink(P[maxLayer], P[1]), addPortal(P[maxLayer]), maxLayer = nxt[maxLayer]; 164 | 165 | freopen("baf-result.txt", "w", stdout); 166 | 167 | Json::FastWriter writer; 168 | puts("Bookmarks JSON:"); cout << writer.write(bookmarks) << endl; 169 | puts("DrawTools JSON:"); cout << writer.write(drawnitems) << endl; 170 | 171 | fclose(stdout); 172 | 173 | return 0; 174 | } 175 | -------------------------------------------------------------------------------- /src/HCF-MoreKeys/morekey.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define rep(i, l, r) for(int i=l; i<=r; i++) 20 | #define dow(i, l, r) for(int i=l; i>=r; i--) 21 | #define clr(x, c) memset(x, c, sizeof(x)) 22 | #define pi acos(-1) 23 | #define travel(i) for(PortalLevelList *p=PlistFirst[i]; p; p=p->next) // 遍历第 i 个 List 24 | 25 | using namespace std; 26 | 27 | #define maxTotal 1000 28 | #define maxs 166167001 29 | 30 | struct Portal // 定义 Portal 结构体,x0,y0 是经纬度坐标,x,y,z 是三维坐标(半径为 1 的球面上),guid,latlng,label 是 JSON 信息 31 | { 32 | double x0, y0, x, y, z; 33 | string guid, latlng, label; 34 | bool MoreKeys; 35 | } P[maxTotal+1], tmpP[2]; // P[] 储存 Portal 信息,tmpP[] 是记录临时三维向量 36 | 37 | bool cmpXY(Portal a, Portal b){return a.x0b) swap(a,b); 56 | if (b>c) swap(b,c); 57 | if (a>b) swap(a,b); 58 | } 59 | // 将三个数从小到大排序 60 | 61 | inline int GetFL(int a, int b, int c) {SWAP(a,b,c); return Field_ID[a][b]+c;} 62 | // 给三个 Portal 的编号求其对应的 Field 的编号 63 | 64 | inline void GetPortal(int FieldLabel, int &a, int &b, int &c) 65 | { 66 | a=1; while (a0;} 110 | // 判断 c 是否在 a→b 左侧 111 | 112 | inline bool inField(int a, int b, int c, int d) 113 | { 114 | if (d==a || d==b || d==c) return false; 115 | if (!Left(a,b,c)) swap(b,c); 116 | return Left(a,b,d) && Left(b,c,d) && Left(c,a,d); 117 | } 118 | // 判断 d 是否在 a-b-c 形成的 Field 内 119 | 120 | inline void ChangetoPosition(int a) 121 | { 122 | istringstream iss(P[a].latlng); 123 | char tmp; 124 | iss >> P[a].x0 >> tmp >> P[a].y0; 125 | P[a].x=cos(P[a].x0/180.0*pi)*cos(P[a].y0/180.0*pi); 126 | P[a].y=sin(P[a].x0/180.0*pi)*cos(P[a].y0/180.0*pi); 127 | P[a].z=sin(P[a].y0/180.0*pi); 128 | } 129 | // 把经纬度坐标转成三维坐标 130 | 131 | inline void ReadInput(const char *localFileName) // 读入 JSON 132 | { 133 | string str, chunk; 134 | 135 | if (localFileName) 136 | { 137 | ifstream fin(localFileName); 138 | if (fin) 139 | while (getline(fin, chunk) && chunk != "") 140 | str += chunk; 141 | else 142 | while (getline(cin, chunk) && chunk != "") 143 | str += chunk; 144 | } 145 | else 146 | while (getline(cin, chunk) && chunk != "") str += chunk; 147 | 148 | Json::Reader reader; 149 | Json::Value input; 150 | reader.parse(str, input); 151 | 152 | Json::Value::Members arrayMember = input["portals"]["idMoreKeys"]["bkmrk"].getMemberNames(); 153 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) 154 | { 155 | n++; 156 | P[n].guid = input["portals"]["idMoreKeys"]["bkmrk"][*iter]["guid"].asString(); 157 | P[n].latlng = input["portals"]["idMoreKeys"]["bkmrk"][*iter]["latlng"].asString(); 158 | P[n].label = input["portals"]["idMoreKeys"]["bkmrk"][*iter]["label"].asString(); 159 | P[n].MoreKeys = true; 160 | ChangetoPosition(n); 161 | } 162 | 163 | arrayMember = input["portals"]["idOthers"]["bkmrk"].getMemberNames(); 164 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) 165 | { 166 | n++; 167 | P[n].guid = input["portals"]["idOthers"]["bkmrk"][*iter]["guid"].asString(); 168 | P[n].latlng = input["portals"]["idOthers"]["bkmrk"][*iter]["latlng"].asString(); 169 | P[n].label = input["portals"]["idOthers"]["bkmrk"][*iter]["label"].asString(); 170 | P[n].MoreKeys = false; 171 | ChangetoPosition(n); // 把经纬度坐标转成三维坐标 172 | } 173 | } 174 | 175 | 176 | 177 | 178 | 179 | 180 | inline int min3(int a, int b, int c){return (a<=b&&a<=c)?a:(b<=c?b:c);} 181 | inline int min(int a, int b){return a=b&&a>=c)?a:(b>=c?b:c);} 183 | 184 | inline void Max(int &a, int b){if (b>a) a=b;} 185 | 186 | char Level[maxs]; // 记录每个 Field 的最大层数 187 | short int NextPortal[maxs]; // 记录每个 Field 在达到最大层数时的内点 188 | int Count[9]; // Count[i] 表示有多少个 Field 其最大层数为 i 189 | int Lmx[maxTotal+1][maxTotal+1]; // Lmx[a][b] 表示向量 a→b 左边所形成的 Field 的最大层数 190 | 191 | 192 | 193 | 194 | 195 | 196 | clock_t gap; // 记录时间 197 | 198 | Json::Value bm, dt, ini_bm, null_dt; // JSON 信息载体 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | int QLevel; // 询问层数 207 | 208 | struct xyz{int x,y,z;} pos[maxTotal+1]; // xyz 是一个自设的参数 209 | bool operator < (xyz a, xyz b){return a.x M0; // 编号映射到 xyz 参数 211 | map M1; // xyz 参数映射到编号 212 | 213 | inline xyz Ave(xyz a, xyz b, xyz c){return (xyz){(a.x+b.x+c.x)/3, (a.y+b.y+c.y)/3, (a.z+b.z+c.z)/3};} 214 | // 由 Field 上三点的 xyz 得到内点的 xyz 215 | 216 | inline void GetOpinion() 217 | { 218 | M0["A1"]=(xyz){(int)5e8,0,0}, M0["A2"]=(xyz){0,(int)5e8,0}, M0["A3"]=(xyz){0,0,(int)5e8}; // 设置三个顶点的 xyz 参数 219 | M1[(xyz){(int)5e8,0,0}]="A1", M1[(xyz){0,(int)5e8,0}]="A2", M1[(xyz){0,0,(int)5e8}]="A3"; 220 | 221 | string tmp1="A", tmp2="Lv 0"; 222 | rep(i, 1, QLevel) 223 | { 224 | tmp1[0]='A'+i-1, tmp2[3]='0'+i; 225 | ini_bm["portals"][tmp1]["label"]=tmp2; 226 | ini_bm["portals"][tmp1]["state"]=0; 227 | } 228 | ini_bm["portals"]["A"]["bkmrk"]["A1"]["guid"]=""; 229 | ini_bm["portals"]["A"]["bkmrk"]["A2"]["guid"]=""; 230 | ini_bm["portals"]["A"]["bkmrk"]["A3"]["guid"]=""; 231 | 232 | // LABEL 每一行有四个字符串,“A B C D” 表示以编号为 A,B,C 形成的 Field 的内点的编号为 D 233 | 234 | ifstream fin("../LABEL"); 235 | int tmp, num=0; fin >> tmp; for(int i=1, a=1; i> a >> b >> c >> d; 241 | M0[a]=Ave(M0[b],M0[c],M0[d]), M1[M0[a]]=a; 242 | if (a[0]-'A'+1<=QLevel) tmp1[0]=a[0], ini_bm["portals"][tmp1]["bkmrk"][a]["guid"]=""; 243 | } 244 | } 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | int OPtot; // JSON 内 Line 的数量 254 | 255 | inline string D_toString(double a) 256 | { 257 | char buffer[20]; 258 | sprintf(buffer, "%f", a); 259 | return buffer; 260 | } 261 | 262 | inline string I_toString(int a) 263 | { 264 | char buffer[20]; 265 | sprintf(buffer, "%d", a); 266 | return buffer; 267 | } 268 | 269 | inline void AddLine(int a, int b, int lv) 270 | { 271 | if (lv == 1) dt[OPtot]["color"] = "#0000ff"; 272 | if (lv == 2) dt[OPtot]["color"] = "#2222ff"; 273 | if (lv == 3) dt[OPtot]["color"] = "#4444ff"; 274 | if (lv == 4) dt[OPtot]["color"] = "#6666ff"; 275 | if (lv == 5) dt[OPtot]["color"] = "#8888ff"; 276 | if (lv == 6) dt[OPtot]["color"] = "#aaaaff"; 277 | if (lv == 7) dt[OPtot]["color"] = "#ccccff"; 278 | 279 | dt[OPtot]["latLngs"][0]["lat"] = D_toString(P[a].x0); 280 | dt[OPtot]["latLngs"][0]["lng"] = D_toString(P[a].y0); 281 | dt[OPtot]["latLngs"][1]["lat"] = D_toString(P[b].x0); 282 | dt[OPtot]["latLngs"][1]["lng"] = D_toString(P[b].y0); 283 | 284 | dt[OPtot]["type"] = "polyline"; 285 | 286 | OPtot++; 287 | } 288 | 289 | inline void AddPortal(int a, int lv) 290 | { 291 | string tmp="A"; tmp[0]+=lv-1; 292 | bm["portals"][tmp]["bkmrk"][M1[pos[a]]]["guid"] = P[a].guid; 293 | bm["portals"][tmp]["bkmrk"][M1[pos[a]]]["latlng"] = P[a].latlng; 294 | bm["portals"][tmp]["bkmrk"][M1[pos[a]]]["label"] = P[a].label; 295 | } 296 | 297 | void OutputPlan(int a, int b, int c, int lv) 298 | { 299 | if (lv == QLevel) return; 300 | SWAP(a,b,c); 301 | if (lv == 1) 302 | { 303 | AddLine(a,b,lv), AddLine(b,c,lv), AddLine(c,a,lv); 304 | pos[a]=(xyz){(int)5e8,0,0}, AddPortal(a,lv); // 由 xyz 参数查询到当前点所对应的编号 305 | pos[b]=(xyz){0,(int)5e8,0}, AddPortal(b,lv); 306 | pos[c]=(xyz){0,0,(int)5e8}, AddPortal(c,lv); 307 | } 308 | int x=GetFL(a,b,c), d=NextPortal[x]; pos[d]=Ave(pos[a],pos[b],pos[c]); 309 | AddPortal(d,++lv); 310 | AddLine(a,d,lv), AddLine(b,d,lv), AddLine(c,d,lv); 311 | OutputPlan(a,b,d,lv); // 递归输出方案 312 | OutputPlan(b,c,d,lv); 313 | OutputPlan(c,a,d,lv); 314 | } 315 | 316 | inline void OutputPlan(int FieldLabel) // 输出方案到 JSON 317 | { 318 | int a, b, c; GetPortal(FieldLabel,a,b,c); 319 | dt=null_dt; bm=ini_bm; OPtot=0; OutputPlan(a,b,c,1); 320 | 321 | Json::FastWriter writer; 322 | puts("Bookmarks JSON:"); cout << writer.write(bm) << endl; 323 | puts("DrawTools JSON:"); cout << writer.write(dt) << endl; 324 | } 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | #define OPRandomSize 1000000 337 | int OPRandom[OPRandomSize]; 338 | int MoreKeys[maxTotal], Mn; 339 | int noMoreKeys[maxTotal], Nn; 340 | #define minField 10 341 | #define maxField 10 342 | #define ranField 30 343 | 344 | inline void OutputResult() 345 | { 346 | freopen("result.txt", "w", stdout); 347 | 348 | priority_queueqmin, qmax; int tot, FieldLabel; 349 | 350 | 351 | 352 | printf("无 MoreKeys Portal 限制:\n\n"); 353 | tot=0; 354 | rep(i, 1, n) rep(j, i+1, n) rep(k, j+1, n) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) 355 | { 356 | if ((int)qmin.size()==minField) qmin.pop(); 357 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 358 | if ((int)qmax.size()==maxField) qmax.pop(); 359 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 360 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 361 | } 362 | // 输出最小的前 minField 个方案 363 | while (!qmin.empty()) printf("面积最小:#%d\n\n", (int)qmin.size()), OutputPlan(qmin.top().x), qmin.pop(); 364 | // 输出最大的前 maxField 个方案 365 | while (!qmax.empty()) printf("面积最大:#%d\n\n", (int)qmax.size()), OutputPlan(qmax.top().x), qmax.pop(); 366 | // 随机输出 ranField 个方案 367 | random_shuffle(OPRandom, OPRandom+tot); 368 | rep(i, 1, min(tot,ranField)) printf("Random #%d\n\n", i), OutputPlan(OPRandom[i-1]); 369 | 370 | 371 | 372 | rep(i, 1, n) if (P[i].MoreKeys) MoreKeys[++Mn]=i; else noMoreKeys[++Nn]=i; 373 | 374 | #define nMK(i, ii, l) for(int ii=l,i=noMoreKeys[l]; ii<=Nn; i=noMoreKeys[++ii]) 375 | #define MK(i, ii, l) for(int ii=l,i=MoreKeys[l]; ii<=Mn; i=MoreKeys[++ii]) 376 | 377 | 378 | 379 | printf("1 个 MoreKey Portal 在顶点或中点上:\n\n"); 380 | tot=0; 381 | MK(i, ii, 1) nMK(j, jj, 1) nMK(k, kk, jj+1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) nMK(h, hh, 1) 382 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 383 | Level[GetFL(i,j,h)]>=QLevel-1 && 384 | Level[GetFL(i,h,k)]>=QLevel-1 && 385 | Level[GetFL(h,j,k)]>=QLevel-1) 386 | { 387 | if ((int)qmin.size()==minField) qmin.pop(); 388 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 389 | if ((int)qmax.size()==maxField) qmax.pop(); 390 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 391 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 392 | } 393 | nMK(i, ii, 1) nMK(j, jj, ii+1) nMK(k, kk, jj+1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) MK(h, hh, 1) 394 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 395 | Level[GetFL(i,j,h)]>=QLevel-1 && 396 | Level[GetFL(i,h,k)]>=QLevel-1 && 397 | Level[GetFL(h,j,k)]>=QLevel-1) 398 | { 399 | if ((int)qmin.size()==minField) qmin.pop(); 400 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 401 | if ((int)qmax.size()==maxField) qmax.pop(); 402 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 403 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 404 | } 405 | // 输出最小的前 minField 个方案 406 | while (!qmin.empty()) printf("面积最小:#%d\n\n", (int)qmin.size()), OutputPlan(qmin.top().x), qmin.pop(); 407 | // 输出最大的前 maxField 个方案 408 | while (!qmax.empty()) printf("面积最大:#%d\n\n", (int)qmax.size()), OutputPlan(qmax.top().x), qmax.pop(); 409 | // 随机输出 ranField 个方案 410 | random_shuffle(OPRandom, OPRandom+tot); 411 | rep(i, 1, min(tot,ranField)) printf("Random #%d\n\n", i), OutputPlan(OPRandom[i-1]); 412 | 413 | 414 | 415 | printf("2 个 MoreKey Portal 在顶点或中点上:\n\n"); 416 | tot=0; 417 | MK(i, ii, 1) MK(j, jj, ii+1) nMK(k, kk, 1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) nMK(h, hh, 1) 418 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 419 | Level[GetFL(i,j,h)]>=QLevel-1 && 420 | Level[GetFL(i,h,k)]>=QLevel-1 && 421 | Level[GetFL(h,j,k)]>=QLevel-1) 422 | { 423 | if ((int)qmin.size()==minField) qmin.pop(); 424 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 425 | if ((int)qmax.size()==maxField) qmax.pop(); 426 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 427 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 428 | } 429 | MK(i, ii, 1) nMK(j, jj, 1) nMK(k, kk, jj+1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) MK(h, hh, 1) 430 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 431 | Level[GetFL(i,j,h)]>=QLevel-1 && 432 | Level[GetFL(i,h,k)]>=QLevel-1 && 433 | Level[GetFL(h,j,k)]>=QLevel-1) 434 | { 435 | if ((int)qmin.size()==minField) qmin.pop(); 436 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 437 | if ((int)qmax.size()==maxField) qmax.pop(); 438 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 439 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 440 | } 441 | // 输出最小的前 minField 个方案 442 | while (!qmin.empty()) printf("面积最小:#%d\n\n", (int)qmin.size()), OutputPlan(qmin.top().x), qmin.pop(); 443 | // 输出最大的前 maxField 个方案 444 | while (!qmax.empty()) printf("面积最大:#%d\n\n", (int)qmax.size()), OutputPlan(qmax.top().x), qmax.pop(); 445 | // 随机输出 ranField 个方案 446 | random_shuffle(OPRandom, OPRandom+tot); 447 | rep(i, 1, min(tot,ranField)) printf("Random #%d\n\n", i), OutputPlan(OPRandom[i-1]); 448 | 449 | 450 | 451 | printf("3 个 MoreKey Portal 在顶点或中点上:\n\n"); 452 | tot=0; 453 | MK(i, ii, 1) MK(j, jj, ii+1) MK(k, kk, jj+1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) nMK(h, hh, 1) 454 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 455 | Level[GetFL(i,j,h)]>=QLevel-1 && 456 | Level[GetFL(i,h,k)]>=QLevel-1 && 457 | Level[GetFL(h,j,k)]>=QLevel-1) 458 | { 459 | if ((int)qmin.size()==minField) qmin.pop(); 460 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 461 | if ((int)qmax.size()==maxField) qmax.pop(); 462 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 463 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 464 | } 465 | MK(i, ii, 1) MK(j, jj, ii+1) nMK(k, kk, 1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) MK(h, hh, 1) 466 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 467 | Level[GetFL(i,j,h)]>=QLevel-1 && 468 | Level[GetFL(i,h,k)]>=QLevel-1 && 469 | Level[GetFL(h,j,k)]>=QLevel-1) 470 | { 471 | if ((int)qmin.size()==minField) qmin.pop(); 472 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 473 | if ((int)qmax.size()==maxField) qmax.pop(); 474 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 475 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 476 | } 477 | // 输出最小的前 minField 个方案 478 | while (!qmin.empty()) printf("面积最小:#%d\n\n", (int)qmin.size()), OutputPlan(qmin.top().x), qmin.pop(); 479 | // 输出最大的前 maxField 个方案 480 | while (!qmax.empty()) printf("面积最大:#%d\n\n", (int)qmax.size()), OutputPlan(qmax.top().x), qmax.pop(); 481 | // 随机输出 ranField 个方案 482 | random_shuffle(OPRandom, OPRandom+tot); 483 | rep(i, 1, min(tot,ranField)) printf("Random #%d\n\n", i), OutputPlan(OPRandom[i-1]); 484 | 485 | 486 | 487 | printf("4 个 MoreKey Portal 在顶点或中点上:\n\n"); 488 | tot=0; 489 | MK(i, ii, 1) MK(j, jj, ii+1) MK(k, kk, jj+1) if (Level[FieldLabel=GetFL(i,j,k)]>=QLevel) MK(h, hh, 1) 490 | if (h!=i && h!=j && h!=k && inField(i,j,k,h) && 491 | Level[GetFL(i,j,h)]>=QLevel-1 && 492 | Level[GetFL(i,h,k)]>=QLevel-1 && 493 | Level[GetFL(h,j,k)]>=QLevel-1) 494 | { 495 | if ((int)qmin.size()==minField) qmin.pop(); 496 | qmin.push((Field){FieldLabel,Area(i,j,k)}); 497 | if ((int)qmax.size()==maxField) qmax.pop(); 498 | qmax.push((Field){FieldLabel,-Area(i,j,k)}); 499 | if (tot<=OPRandomSize) OPRandom[tot++]=FieldLabel; 500 | } 501 | // 输出最小的前 minField 个方案 502 | while (!qmin.empty()) printf("面积最小:#%d\n\n", (int)qmin.size()), OutputPlan(qmin.top().x), qmin.pop(); 503 | // 输出最大的前 maxField 个方案 504 | while (!qmax.empty()) printf("面积最大:#%d\n\n", (int)qmax.size()), OutputPlan(qmax.top().x), qmax.pop(); 505 | // 随机输出 ranField 个方案 506 | random_shuffle(OPRandom, OPRandom+tot); 507 | rep(i, 1, min(tot,ranField)) printf("Random #%d\n\n", i), OutputPlan(OPRandom[i-1]); 508 | 509 | 510 | 511 | // 重名预警 512 | printf("需要注意的重名 Po:\n"); 513 | rep(i, 1, n) rep(j, i+1, n) if (P[i].label == P[j].label) {cout << P[i].label << endl; break;} 514 | 515 | fclose(stdout); 516 | } 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | int main() 530 | { 531 | system("cls"); 532 | 533 | cout << "请将导出的 Bookmark 储存为 portal.txt 并放置于同目录下" << endl; 534 | getchar(); 535 | 536 | ReadInput("portal.txt"); srand(time(NULL)); 537 | 538 | cout << "总点数:" << n << endl; 539 | cout << "倒数第二个 Portal:" << P[n-1].label << endl; 540 | cout << "若与读入数据不吻合,则请检查下是否操作有误(或者是触发了尚未修复的 Portal 名称 Bug)" << endl; 541 | getchar(); 542 | 543 | if (n>maxTotal) 544 | { 545 | cout << "Portal 数量超过了 " << maxTotal << " 的上限,请删减。" << endl; 546 | getchar(); return 0; 547 | } 548 | 549 | sort(P+1, P+1+n, cmpXY); // 按经纬坐标排序 550 | 551 | int tot=0; rep(i, 1, n-2) rep(j, i+1, n-1) tot+=n-j, Field_ID[i][j]=tot-n; 552 | // 枚举左端点和中间端点,tot 记录 Field 总数,Field_ID 是为了方便计算每个 Field 所对应的编号(详细见 GetFL 函数) 553 | 554 | int now=0, totL, totR; // now 表示当前已经处理完了多少个 Field 555 | rep(c, 3, n) dow(a, c-2, 1) // 从左往右枚举右端点,从右往左枚举左端点 556 | { 557 | totL=totR=0; 558 | rep(b, a+1, c-1) if (Left(a,c,b)) qL[++totL]=(Field){b,Area(a,b,c)}; else qR[++totR]=(Field){b,Area(a,c,b)}; 559 | // 枚举中间端点,qL[] 为向量 a→c 左边的 Portal(总数为 totL),qR[] 为向量 a→c 右边的 Portal(总数为 totR) 560 | if (totL) 561 | { 562 | sort(qL+1, qL+1+totL); // 按面积从小到大排序 563 | clr(PlistFirst,0); PlistEnd=Plist; // List 初始化 564 | rep(i, 1, totL) 565 | { 566 | int b=qL[i].x, FieldLabel=GetFL(a,b,c), mxLevel=max(Lmx[c][b],Lmx[b][a]); // mxLevel 是由向量 c→b 和 b→a 左边所形成的 Field 的最大层数所决定的 Level 上限 567 | char &Lv=Level[FieldLabel]; Lv=1; // Lv 为当前 Field 的 Level 568 | dow(o, mxLevel, 1) travel(o) if (Lv>o) break; else if (inField(a,b,c,p->x)) // 从高到低枚举内层 Field 等级并遍历 List 569 | { 570 | int tmp=min3(o,Level[GetFL(a,b,p->x)],Level[GetFL(b,c,p->x)])+1; // 求内点为 p->x 时当前 Field 所能达到的最大层数 571 | if (tmp>Lv) Lv=tmp, NextPortal[FieldLabel]=p->x; 572 | } 573 | 574 | int tmp=min(Lv,max(Lmx[a][b],Lmx[b][c])); // 判断下当 b 作为内点 a-c 做边的时候最多能多少层 575 | PlistEnd->x=b, PlistEnd->next=PlistFirst[tmp], PlistFirst[tmp]=PlistEnd++; // 将 b 加入到 List[tmp] 576 | 577 | Max(Lmx[a][c],Lv); Max(Lmx[c][b],Lv); Max(Lmx[b][a],Lv); // 更新 Lmx 数组 578 | 579 | Count[(int)Lv]++; now++; 580 | if ((double)(clock()-gap)/CLOCKS_PER_SEC>=0.1) 581 | system("cls"), printf("%.6lf%%\n", 100.0*now/tot), gap=clock(); // 每隔 0.1s 显示一次百分比进度 582 | } 583 | } 584 | if (totR) // 注释同上 585 | { 586 | sort(qR+1, qR+1+totR); 587 | clr(PlistFirst,0); PlistEnd=Plist; 588 | rep(i, 1, totR) 589 | { 590 | int b=qR[i].x, FieldLabel=GetFL(a,b,c), mxLevel=max(Lmx[a][b],Lmx[b][c]); 591 | char &Lv=Level[FieldLabel]; Lv=1; 592 | dow(o, mxLevel, 1) travel(o) if (Lv>o) break; else if (inField(a,b,c,p->x)) 593 | { 594 | int tmp=min3(o,Level[GetFL(a,b,p->x)],Level[GetFL(b,c,p->x)])+1; 595 | if (tmp>Lv) Lv=tmp, NextPortal[FieldLabel]=p->x; 596 | } 597 | 598 | int tmp=min3(Lv,Lmx[c][b],Lmx[b][a]); 599 | PlistEnd->x=b, PlistEnd->next=PlistFirst[tmp], PlistFirst[tmp]=PlistEnd++; 600 | 601 | Max(Lmx[a][b],Lv); Max(Lmx[b][c],Lv); Max(Lmx[c][a],Lv); 602 | 603 | Count[(int)Lv]++; now++; 604 | if ((double)(clock()-gap)/CLOCKS_PER_SEC>=0.1) 605 | system("cls"), printf("%.6lf%%\n", 100.0*now/tot), gap=clock(); 606 | } 607 | } 608 | } 609 | 610 | system("cls"); 611 | rep(i, 3, 7) printf("%d 重竹笋解: %d 个\n", i, Count[i]); 612 | puts(""); puts(""); 613 | printf("请问要来份多少重的竹笋?(3-7)\n"); 614 | 615 | QLevel=3; scanf("%d", &QLevel); 616 | puts("有关信息正在输出到result.txt,祝你好运>.<"); 617 | GetOpinion(); 618 | OutputResult(); 619 | 620 | return 0; 621 | } 622 | -------------------------------------------------------------------------------- /src/HCF-MoreKeys/portal-sample.txt: -------------------------------------------------------------------------------- 1 | {"maps":{"idOthers":{"label":"Others","state":1,"bkmrk":{}}},"portals":{"idMoreKeys":{"label":"MoreKeys","state":1,"bkmrk":{"id1495894525260050":{"guid":"fb42ae0c7a4b4ac5b4c1d56fed714a05.16","latlng":"23.334517,116.675998","label":"Stone"},"id1495894525992131":{"guid":"0c551a1ba00346459eb6a9cdf6a1fe5a.11","latlng":"23.335977,116.676696","label":"金山中学大门"},"id1495894526392282":{"guid":"b98e7d867df24d06b954221b0122c5ce.16","latlng":"23.369273,116.706253","label":"裂开的狮子"},"id1495894527176499":{"guid":"c91162d510ad435b96d34283aeb7da76.16","latlng":"23.433004,116.738147","label":"外砂站(同三高速/汕汾高速)"}}},"idOthers":{"label":"Others","state":1,"bkmrk":{"id1495894527476510":{"guid":"11333ba5d4244acdaae6701c6b754bff.16","latlng":"23.359681,116.711976","label":"吉"},"id1495894527772650":{"guid":"6a427584b49a4d89ad571c1a9a2a071f.16","latlng":"23.374765,116.739457","label":"大印象石象"},"id1495894528043733":{"guid":"51058ee3a3d14818ac8bd6e0749aaca5.16","latlng":"23.393093,116.70238","label":"金禧花园"},"id1495894528393861":{"guid":"21fdde5230a54708b90542019ac62e4e.16","latlng":"23.356281,116.690662","label":"Lion Guard Of Chaofeng Hotel"},"id149589452871499":{"guid":"90f4c5d48dac404bb8b3cdf4606cbe75.16","latlng":"23.364266,116.743151","label":"阳光海岸"},"id14958945290021070":{"guid":"1d71fdc2269840d68a137fa69f099f2c.16","latlng":"23.335452,116.676076","label":"塔山胜景"},"id14958945293431152":{"guid":"d9d811c5a2eb4b81a414ddf2bf95dbd4.16","latlng":"23.368722,116.704081","label":"脑袋进水"},"id14958945310751498":{"guid":"600ea6d4acdd4a6c95043d7511958b10.16","latlng":"23.399858,116.711218","label":"亭"},"id14958945317451538":{"guid":"8dd46fd1aa83406d85f9a16324e2ca88.16","latlng":"23.402525,116.712872","label":"舞女"},"id14958945319781680":{"guid":"7fdd01d08ada40dcb65e21e9d1f9fa1e.16","latlng":"23.369818,116.706988","label":"帝景苑游乐园"},"id14958945325241782":{"guid":"a9ca2bba48e449d0ac1015fb73929f62.16","latlng":"23.364831,116.738553","label":"蜈蚣"},"id14958945327841899":{"guid":"995567b06edc4567ae5b018e13fdcf09.16","latlng":"23.415872,116.629799","label":"商碑"},"id14958945330331963":{"guid":"a0de307600d54459a06a10fa6b8bca8f.16","latlng":"23.365026,116.730814","label":"星洲公园"},"id14958945346032154":{"guid":"cdd1185177fc4de3a890d71230015b2b.16","latlng":"23.364458,116.733985","label":"蛋蛋"},"id14958945348812240":{"guid":"683964d50fe54b0bb905c28b8f7e9aa5.16","latlng":"23.409194,116.717481","label":"黄金万两"},"id14958945354062322":{"guid":"1f962dc3a9984de5bacfdec15c5d6e35.16","latlng":"23.372187,116.735592","label":"众神古庙和大榕树"},"id14958945357212430":{"guid":"0c9c6fbe732d4261bcc88e6de4cc9d52.16","latlng":"23.36191,116.708637","label":"Lion Sculpture"},"id14958945402752640":{"guid":"6819a4ce88874d37855cb986a725a247.16","latlng":"23.405344,116.719239","label":"创美药业"},"id14958945408832762":{"guid":"fd1fdba42b6145ec86f2e860b158c8ca.16","latlng":"23.351153,116.762068","label":"柏佳半岛钟楼"},"id14958945432183050":{"guid":"e20356b0cc084dc38fdbd40445452846.16","latlng":"23.369472,116.676847","label":"衔着木棍的狮子"},"id14958945434793130":{"guid":"001c79a5c93c496dbae0fb4ff160db1e.16","latlng":"23.346586,116.755846","label":"方特欢乐世界"},"id14958945437513231":{"guid":"b44dba00086b4e57ab63cd475cbbc15b.16","latlng":"23.419995,116.628592","label":"大菊花"},"id1495894544553334":{"guid":"cc0a3fdfe84c4ab28767e579f9b1a30c.16","latlng":"23.361863,116.736293","label":"广场的乒乓桌"},"id14958945448803457":{"guid":"4906ad03274e4ac2a3c0ebe681aa9f95.16","latlng":"23.420075,116.628096","label":"大刺猬"},"id1495894545771353":{"guid":"94e3c9d278964a11bc0843155651604c.16","latlng":"23.36288,116.733315","label":"hellokitty"},"id14958945460193669":{"guid":"465e4e06c02b4c6fb6a44a2b48c36684.16","latlng":"23.359876,116.73552","label":"湖中亭"},"id14958945463283748":{"guid":"3db3a7dfb66d4e17a1e5a79ff14f8efe.16","latlng":"23.419544,116.626517","label":"花洒"},"id14958945466503835":{"guid":"0323106290c94985bd18a7d46c0332fc.16","latlng":"23.367942,116.704055","label":"中华世纪坛"},"id14958945479203998":{"guid":"11ac2c24ae834273be4781dcb61353e7.16","latlng":"23.36092,116.735603","label":"推背"},"id1495894548194405":{"guid":"38b35028503246a1b1d9800fe6a1065d.16","latlng":"23.353631,116.691179","label":"两坨球状大腿"},"id14958945484684126":{"guid":"ad8cdd2a6a854078a30b325b18d7f3a1.16","latlng":"23.372959,116.69835","label":"陵園麒麟壁"},"id14958945489664245":{"guid":"698476a8d2c741f9b8b6ea84dffae308.16","latlng":"23.361407,116.735979","label":"星湖潮乐社"},"id1495894549276434":{"guid":"d663187d8ada4390bbe1adb6bda7a63b.16","latlng":"23.358818,116.702343","label":"滑梯"},"id14958945496444454":{"guid":"0f7788c1500949ffa5505b7e78eccdda.16","latlng":"23.353605,116.692397","label":"欢乐小姑娘"},"id14958945511204650":{"guid":"8809c24f215a419a93ebeeb78e2d19c6.16","latlng":"23.353483,116.692588","label":"大娃娃"},"id14958945513954719":{"guid":"0f2d5d2575ac4cda8cf7118fb3525145.11","latlng":"23.359963,116.705929","label":"汕头协华大厦"},"id14958945555804875":{"guid":"aab8fbb6ddd84d948d4ef887e0cc3812.16","latlng":"23.336512,116.689359","label":"Pagoda"},"id14958945558904967":{"guid":"e238e0e12fa948419fd6f50e636d92b2.16","latlng":"23.336388,116.689696","label":"石狮子"},"id14958945561645068":{"guid":"e5f9fbfe2e494d7ea3b9f621fc6277fb.16","latlng":"23.336534,116.688745","label":"Place of Worship"},"id14958945564595141":{"guid":"c98546b872bc4b418a8c400615cae7b4.16","latlng":"23.336762,116.688735","label":"Looking Back to the Entrance Hall"},"id14958945567135221":{"guid":"35b8b8b63b314a4f92107a2deac2daec.16","latlng":"23.336624,116.690028","label":"Pig Monk"},"id14958945573145329":{"guid":"ce38aa4feeb344f0baa802002cd364db.16","latlng":"23.336945,116.68891","label":"Guardians of the World"},"id14958945577085449":{"guid":"4158d244df86400e9c33ccaa03fadbe3.16","latlng":"23.336388,116.690172","label":"Guanyin Fountain"},"id14958945586515575":{"guid":"92b67f3e276f4031a5db5aa033a51667.16","latlng":"23.368622,116.69964","label":"水池…"},"id14958945589305672":{"guid":"c68e1884028a4491bdc3752ee4ef2ed5.16","latlng":"23.36628,116.73969","label":"仿古驿站"},"id14958945591935792":{"guid":"1d17de27a58a4a4f8d21bcea8e196f3a.16","latlng":"23.378852,116.676096","label":"踩着球的麒麟"},"id14958945594905845":{"guid":"20cd7860d82742adb1ad2250fafc397e.16","latlng":"23.375478,116.704974","label":"小区景观"},"id14958945597545978":{"guid":"6be60c6a9c8a4215a38c54eb6f4509c3.16","latlng":"23.369794,116.7007","label":"保龄球"},"id14958945600236071":{"guid":"290fcf8d82f548038be7cfc0c47ff73a.16","latlng":"23.372927,116.696944","label":"石象子"},"id14958945602796149":{"guid":"0a4e426fecba435485334275027fe3fe.16","latlng":"23.369315,116.701892","label":"超聲儀器研究所"},"id14958945605386275":{"guid":"8207668ee6414bf9ad389c045a0ceb24.16","latlng":"23.367017,116.696273","label":"步行街正门"},"id14958945608086318":{"guid":"39c17a51b0bb4cb1aa81187b435e90db.16","latlng":"23.372767,116.702186","label":"精灵Q密"},"id14958945614266444":{"guid":"5992cf034df14ede96913de7dbcf125e.16","latlng":"23.373851,116.704606","label":"奇葩的东西"},"id14958945618136564":{"guid":"213c2fd0aef540b2a7a3646ee6d6af5e.16","latlng":"23.369355,116.696275","label":"交行靠里面的石狮子"},"id1495894562106665":{"guid":"1988223f58d441f5bdb6f230f2673ed0.16","latlng":"23.365575,116.738776","label":"蘑菇亭"},"id1495894562424673":{"guid":"f352113d23f149499c65cdf74a9901f6.16","latlng":"23.367525,116.740374","label":"白亭北"},"id14958945635866877":{"guid":"22f0b0eba02c4d248bd5e12fba8063f7.16","latlng":"23.405841,116.673075","label":"金隔狮"},"id14958945644096996":{"guid":"e8eac33cb56a480fb4dfc13e79032481.16","latlng":"23.369103,116.697586","label":"欢乐的狮子"},"id1495894565288705":{"guid":"fe5ae9cc5a724cdc88ba64e2f9d83892.16","latlng":"23.366082,116.739091","label":"mushroom booth"},"id14958945670187249":{"guid":"db352010793d4f33b905a8068117ea20.16","latlng":"23.369039,116.699493","label":"黑狮子"},"id14958945673097358":{"guid":"f9cb68c4333e480b8824b891e66b5709.16","latlng":"23.406063,116.70558","label":"关帝古庙"},"id14958945675767442":{"guid":"84c7b86efb3448cbb560dd624bc813c1.16","latlng":"23.404252,116.70348","label":"辛氏泗祖祠"},"id14958945678577511":{"guid":"70818246d8244b63adc12b0d98c75550.16","latlng":"23.399889,116.701411","label":"宝塔"},"id14958945681217655":{"guid":"b4e4e06426774ef898c831d0f933cefc.16","latlng":"23.401316,116.702524","label":"辛氏祖祠"},"id14958945683657719":{"guid":"8c25fe753554408f827fe956b771d681.16","latlng":"23.400318,116.701223","label":"浮隴三山國王古廟"},"id14958945686037824":{"guid":"15107060ca5d41e286e9bd78c5f9e1d0.16","latlng":"23.41536,116.717366","label":"纪氏大宗祠"},"id14958945698897927":{"guid":"3d36b2da812640769ca0ad8f5b26f608.16","latlng":"23.402056,116.702343","label":"福德祠"},"id14958945701498091":{"guid":"29a77e121e734ba8930abee194c2a792.16","latlng":"23.411804,116.713775","label":"佛教圣地"},"id14958945706818239":{"guid":"0e68e6836ee84409973fc42ed9c2cfe8.16","latlng":"23.402638,116.677262","label":"麒麟园挡风"},"id14958945709358340":{"guid":"05551ea6f6b24d4092bd41864284fd0c.16","latlng":"23.402818,116.677082","label":"豹子石雕"},"id14958945716258491":{"guid":"a3827240953b40af905593070211f7b1.16","latlng":"23.40347,116.677021","label":"麒麟丸"},"id14958945722468529":{"guid":"5ce07bbc2e5343309c1ed6acfc7a586b.16","latlng":"23.398687,116.675818","label":"太安堂"},"id14958945727888726":{"guid":"76719ddb1a054f89980e91b4860fb367.16","latlng":"23.421131,116.625643","label":"石鸡"},"id14958945748518980":{"guid":"a0f3e0e0da0f41e1ad15d1ba9f956f05.16","latlng":"23.417356,116.625455","label":"花园路里的兔子"},"id14958945761499082":{"guid":"2708b932692744a1920e1d150f3ce0fe.16","latlng":"23.414175,116.71676","label":"壁画"},"id14958945765549134":{"guid":"42eda34c759445d48ce8c460dae714d2.16","latlng":"23.417905,116.627035","label":"足球场"},"id14958945781909262":{"guid":"9d5886521cf84a419ea8c64049a3e326.16","latlng":"23.420538,116.626028","label":"满江红"},"id14958945784699353":{"guid":"3ba241ee12934c37a5391f124feb6794.16","latlng":"23.410299,116.712586","label":"骑豚小孩"},"id14958945787709463":{"guid":"9787d67e9851482c9c41516eb1e789bf.16","latlng":"23.417771,116.625274","label":"汕头的站"},"id14958945790429598":{"guid":"f05025da8c954ff8a1aed3da53f6c5da.16","latlng":"23.417769,116.623365","label":"汕头地震台体应变观测井"},"id14958945793139689":{"guid":"87f62295b7f34fba936c9d0b4f7dc9e6.16","latlng":"23.421373,116.625779","label":"铁云"},"id1495894579894989":{"guid":"03c74210882c427e9676941c48c7ce90.16","latlng":"23.418309,116.625462","label":"水库下的石林"},"id14958945805449929":{"guid":"e9bdfc1a360141d7beb2b3bda4cc3045.16","latlng":"23.417567,116.627538","label":"汕大体育公园"}}}}} -------------------------------------------------------------------------------- /src/HCF-RESWUEV1/reswue.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define rep(i, l, r) for(int i=l; i<=r; i++) 21 | #define dow(i, l, r) for(int i=l; i>=r; i--) 22 | #define clr(x, c) memset(x, c, sizeof(x)) 23 | #define all(a) a.begin(), a.end() 24 | #define pb push_back 25 | 26 | using namespace std; 27 | 28 | struct node 29 | { 30 | double x, y; 31 | string guid, latlng, label; 32 | } P[500]; 33 | 34 | inline string toString(int a, int b) 35 | { 36 | char buffer[6]; 37 | sprintf(buffer, "%c%d", 'A'+a-1, b); 38 | return buffer; 39 | } 40 | 41 | vectorv[500]; 42 | inline void Add(int a, int b){v[a].pb(b); v[b].pb(a);} 43 | 44 | int n, Lv[500]; 45 | bool InBook[500]; 46 | map M0; 47 | map M1; 48 | 49 | inline void GetOpinion() 50 | { 51 | M0[++n]="A1", M1["A1"]=n, Lv[n]=1; 52 | M0[++n]="A2", M1["A2"]=n, Lv[n]=1; 53 | M0[++n]="A3", M1["A3"]=n, Lv[n]=1; 54 | Add(1,2); Add(2,3); Add(1,3); 55 | 56 | ifstream fin("../LABEL"); 57 | int tmp, num=0; fin >> tmp; for(int i=1, a=1; i> a >> b >> c >> d; 63 | M0[++n]=a, M1[a]=n, Lv[n]=max(max(Lv[M1[b]],Lv[M1[c]]),Lv[M1[d]])+1; 64 | Add(n,M1[b]); 65 | Add(n,M1[c]); 66 | Add(n,M1[d]); 67 | } 68 | } 69 | 70 | inline void ChangetoPosition(int a) 71 | { 72 | istringstream iss(P[a].latlng); 73 | char tmp; 74 | iss >> P[a].x >> tmp >> P[a].y; 75 | } 76 | 77 | inline void ReadBookmark(const char *localFileName) // 读入JSON 78 | { 79 | string str, chunk; 80 | 81 | if (localFileName) 82 | { 83 | ifstream fin(localFileName); 84 | if (fin) 85 | while (getline(fin, chunk) && chunk != "") 86 | str += chunk; 87 | else 88 | while (getline(cin, chunk) && chunk != "") 89 | str += chunk; 90 | } 91 | else 92 | while (getline(cin, chunk) && chunk != "") str += chunk; 93 | 94 | Json::Reader reader; 95 | Json::Value input; 96 | reader.parse(str, input); 97 | 98 | Json::Value::Members arrayMember1 = input["portals"].getMemberNames(); 99 | for(Json::Value::Members::iterator iter1 = arrayMember1.begin(); iter1 != arrayMember1.end(); ++iter1) 100 | { 101 | Json::Value::Members arrayMember = input["portals"][*iter1]["bkmrk"].getMemberNames(); 102 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) 103 | { 104 | P[M1[*iter]].guid = input["portals"][*iter1]["bkmrk"][*iter]["latlng"].asString(); 105 | P[M1[*iter]].latlng = input["portals"][*iter1]["bkmrk"][*iter]["latlng"].asString(); 106 | P[M1[*iter]].label = input["portals"][*iter1]["bkmrk"][*iter]["label"].asString(); 107 | ChangetoPosition(M1[*iter]); 108 | InBook[M1[*iter]]=true; 109 | } 110 | } 111 | } 112 | 113 | inline string LayerName(int x) 114 | { 115 | if (x==0) return "main"; 116 | if (x==1) return "groupa"; 117 | if (x==2) return "groupb"; 118 | if (x==3) return "groupc"; 119 | if (x==4) return "groupd"; 120 | if (x==5) return "groupe"; 121 | if (x==6) return "groupf"; 122 | return ""; 123 | } 124 | 125 | inline int Step(int a, int b) 126 | { 127 | if (Lv[a]==5 && Lv[b]==6) return 1; 128 | 129 | if (Lv[a]==4 && Lv[b]==5) return 1; 130 | if (Lv[a]==4 && Lv[b]==6) return 1; 131 | if (Lv[a]==4 && Lv[b]==2) return 1; 132 | 133 | if (Lv[a]==3 && Lv[b]==4) return 2; 134 | if (Lv[a]==3 && Lv[b]==5) return 2; 135 | if (Lv[a]==3 && Lv[b]==6) return 2; 136 | if (Lv[a]==3 && Lv[b]==2) return 2; 137 | 138 | if (Lv[a]==2 && Lv[b]==5) return 3; 139 | if (Lv[a]==2 && Lv[b]==6) return 3; 140 | 141 | if (Lv[a]==1 && Lv[b]==1 && (a+1==b || a-2==b)) return 4; 142 | if (Lv[a]==1 && Lv[b]==2) return 4; 143 | if (Lv[a]==1 && Lv[b]==3) return 4; 144 | if (Lv[a]==1 && Lv[b]==4) return 4; 145 | if (Lv[a]==1 && Lv[b]==5) return 4; 146 | if (Lv[a]==1 && Lv[b]==6) return 4; 147 | return -1; 148 | } 149 | 150 | inline string D_toString(double a) 151 | { 152 | char buffer[20]; 153 | sprintf(buffer, "%f", a); 154 | return buffer; 155 | } 156 | 157 | inline string I_toString(int a) 158 | { 159 | char buffer[20]; 160 | sprintf(buffer, "%d", a); 161 | return buffer; 162 | } 163 | 164 | Json::Value dt[19], wue; // JSON 信息载体 165 | int pt_num, lk_num, dt_num=4, dtn[19]; 166 | 167 | inline void AddLine(int o, int a, int b) 168 | { 169 | dt[o][dtn[o]]["color"] = "#0000ff"; 170 | 171 | dt[o][dtn[o]]["latLngs"][0]["lat"] = D_toString(P[a].x); 172 | dt[o][dtn[o]]["latLngs"][0]["lng"] = D_toString(P[a].y); 173 | dt[o][dtn[o]]["latLngs"][1]["lat"] = D_toString(P[b].x); 174 | dt[o][dtn[o]]["latLngs"][1]["lng"] = D_toString(P[b].y); 175 | 176 | dt[o][dtn[o]]["type"] = "polyline"; 177 | 178 | dtn[o]++; 179 | } 180 | 181 | inline void OutputRESWUE() 182 | { 183 | rep(x, 1, n) if (InBook[x]) 184 | { 185 | wue["Portals"][pt_num]["id"] = I_toString(x); 186 | wue["Portals"][pt_num]["guid"] = P[x].guid; 187 | wue["Portals"][pt_num]["type"] = LayerName(Lv[x]); 188 | wue["Portals"][pt_num]["nodeName"] = P[x].label; 189 | wue["Portals"][pt_num]["lat"] = D_toString(P[x].x); 190 | wue["Portals"][pt_num]["lng"] = D_toString(P[x].y); 191 | pt_num++; 192 | } 193 | rep(x, 1, n) if (InBook[x]) rep(i, 0, (int)v[x].size()-1) 194 | if (InBook[v[x][i]] && Step(x,v[x][i])>=0) 195 | { 196 | wue["Links"][lk_num]["id"] = I_toString(lk_num+1); 197 | wue["Links"][lk_num]["portal1"] = I_toString(x); 198 | wue["Links"][lk_num]["portal2"] = I_toString(v[x][i]); 199 | wue["Links"][lk_num]["portal1Guid"] = P[x].guid; 200 | wue["Links"][lk_num]["portal2Guid"] = P[v[x][i]].guid; 201 | wue["Links"][lk_num]["portal1Lat"] = D_toString(P[x].x); 202 | wue["Links"][lk_num]["portal1Lng"] = D_toString(P[x].y); 203 | wue["Links"][lk_num]["portal2Lat"] = D_toString(P[v[x][i]].x); 204 | wue["Links"][lk_num]["portal2Lng"] = D_toString(P[v[x][i]].y); 205 | wue["Links"][lk_num]["type"] = LayerName(Step(x,v[x][i])); 206 | lk_num++; 207 | 208 | rep(o, Step(x,v[x][i]), dt_num) AddLine(o, x, v[x][i]); 209 | } 210 | 211 | freopen("reswue.txt", "w", stdout); 212 | 213 | Json::FastWriter writer; 214 | cout << writer.write(wue) << endl; 215 | rep(i, 1, dt_num) cout << writer.write(dt[i]) << endl; 216 | 217 | fclose(stdout); 218 | } 219 | 220 | int main() 221 | { 222 | GetOpinion(); 223 | ReadBookmark("bookmark.txt"); 224 | OutputRESWUE(); 225 | return 0; 226 | } 227 | -------------------------------------------------------------------------------- /src/HCF-SingleWork/act-sample.txt: -------------------------------------------------------------------------------- 1 | A1 美少女 23.353565,116.691958 2 | A2 小区健身 23.353751,116.698035 3 | A3 轮渡剧场 23.353838,116.681584 4 | B1 小松鼠 23.353711,116.688892 5 | C1 圆台 23.353669,116.690762 6 | D1 欢乐小姑娘 23.353605,116.692397 7 | D2 倒立小孩 23.3537,116.690356 8 | D3 两坨球状大腿 23.353631,116.691179 9 | C2 雷管保险丝 23.353763,116.688387 10 | D4 大红中国结 23.353786,116.691033 11 | D5 石结构 23.353745,116.687642 12 | D6 跨球小孩 23.353749,116.689957 13 | C3 海边休憩廊道 23.353699,116.689134 14 | D7 海边廊道 23.353652,116.689479 15 | D8 胖子 23.353673,116.689686 16 | D9 骆驼 23.353779,116.68489 17 | 18 | A2 小区健身 9 0 19 | D1 欢乐小姑娘 2 1 A2 20 | A1 美少女 7 2 A2 D1 21 | D3 两坨球状大腿 2 1 A1 22 | D4 大红中国结 2 1 A2 23 | C1 圆台 2 4 A1 A2 D1 D3 24 | D2 倒立小孩 1 2 A2 C1 25 | D6 跨球小孩 2 1 A2 26 | D8 胖子 2 1 A1 27 | D7 海边廊道 2 1 A1 28 | C3 海边休憩廊道 3 3 A1 D7 D8 29 | B1 小松鼠 4 8 A1 A2 C1 D2 D3 D6 C3 D8 30 | C2 雷管保险丝 2 4 A2 B1 D4 D6 31 | D5 石结构 1 2 B1 C2 32 | D9 骆驼 1 2 B1 C3 33 | A3 轮渡剧场 0 9 A1 A2 B1 C2 D4 D5 C3 D7 D9 34 | 35 | -------------------------------------------------------------------------------- /src/HCF-SingleWork/act.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | #define rep(i, l, r) for(int i=l; i<=r; i++) 21 | #define dow(i, l, r) for(int i=l; i>=r; i--) 22 | #define clr(x, c) memset(x, c, sizeof(x)) 23 | #define all(a) a.begin(), a.end() 24 | #define pb push_back 25 | 26 | using namespace std; 27 | 28 | struct node 29 | { 30 | double x, y; 31 | string latlng, label; 32 | } P[500]; 33 | 34 | inline string toString(int a, int b) 35 | { 36 | char buffer[6]; 37 | sprintf(buffer, "%c%d", 'A'+a-1, b); 38 | return buffer; 39 | } 40 | 41 | vectorv[500]; 42 | inline void Add(int a, int b){v[a].pb(b); v[b].pb(a);} 43 | 44 | int F[500][3], n; 45 | bool vis[500], InBook[500]; 46 | map M0; 47 | map M1; 48 | 49 | inline void getOpinion() 50 | { 51 | M0[++n]="A1", M1["A1"]=n; 52 | M0[++n]="A2", M1["A2"]=n; 53 | M0[++n]="A3", M1["A3"]=n; 54 | Add(1,2); Add(2,3); Add(1,3); 55 | 56 | ifstream fin("../LABEL"); 57 | int tmp, num=0; fin >> tmp; for(int i=1, a=1; i> a >> b >> c >> d; 63 | M0[++n]=a, M1[a]=n; 64 | Add(n,F[n][0]=M1[b]); 65 | Add(n,F[n][1]=M1[c]); 66 | Add(n,F[n][2]=M1[d]); 67 | } 68 | } 69 | 70 | 71 | inline void ChangetoPosition(int a) 72 | { 73 | istringstream iss(P[a].latlng); 74 | char tmp; 75 | iss >> P[a].x >> tmp >> P[a].y; 76 | } 77 | 78 | inline void importBookmarks(const char *localFileName) // 读入JSON 79 | { 80 | string str, chunk; 81 | 82 | if (localFileName) 83 | { 84 | ifstream fin(localFileName); 85 | if (fin) 86 | while (getline(fin, chunk) && chunk != "") 87 | str += chunk; 88 | else 89 | while (getline(cin, chunk) && chunk != "") 90 | str += chunk; 91 | } 92 | else 93 | while (getline(cin, chunk) && chunk != "") str += chunk; 94 | 95 | Json::Reader reader; 96 | Json::Value input; 97 | reader.parse(str, input); 98 | 99 | Json::Value::Members arrayMember1 = input["portals"].getMemberNames(); 100 | for(Json::Value::Members::iterator iter1 = arrayMember1.begin(); iter1 != arrayMember1.end(); ++iter1) 101 | { 102 | Json::Value::Members arrayMember = input["portals"][*iter1]["bkmrk"].getMemberNames(); 103 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) 104 | { 105 | P[M1[*iter]].latlng = input["portals"][*iter1]["bkmrk"][*iter]["latlng"].asString(); 106 | P[M1[*iter]].label = input["portals"][*iter1]["bkmrk"][*iter]["label"].asString(); 107 | ChangetoPosition(M1[*iter]); 108 | InBook[M1[*iter]]=true; 109 | } 110 | } 111 | } 112 | 113 | inline int FindLB(double x, double y) 114 | { 115 | rep(i, 1, n) if (fabs(x-P[i].x)<1e-7 && fabs(y-P[i].y)<1e-7) return i; 116 | return 0; 117 | } 118 | 119 | inline void importWay(const char *localFileName) // 读入JSON 120 | { 121 | string str, chunk; 122 | 123 | if (localFileName) 124 | { 125 | ifstream fin(localFileName); 126 | if (fin) 127 | while (getline(fin, chunk) && chunk != "") 128 | str += chunk; 129 | else 130 | while (getline(cin, chunk) && chunk != "") 131 | str += chunk; 132 | } 133 | else 134 | while (getline(cin, chunk) && chunk != "") str += chunk; 135 | 136 | Json::Reader reader; 137 | Json::Value input; 138 | reader.parse(str, input); 139 | 140 | freopen("act.txt", "w", stdout); 141 | 142 | rep(i, 1, n) if (InBook[i]) cout << M0[i] << '\t' << P[i].label << '\t' << P[i].latlng << endl; 143 | cout << "\n\tPortal\tKeys\tOutLinks\n"; 144 | 145 | int L=input[0]["latLngs"].size(); rep(o, 1, L) 146 | { 147 | int x=FindLB(input[0]["latLngs"][o-1]["lat"].asDouble(),input[0]["latLngs"][o-1]["lng"].asDouble()); 148 | if (!x) 149 | { 150 | cout << endl << "路线出现问题,需要修改!!!!!!!!!!!!" << endl; 151 | cout << "坐标:" << setiosflags(ios::fixed) << setprecision(6) << input[0]["latLngs"][o-1]["lat"].asDouble() << ',' << input[0]["latLngs"][o-1]["lng"].asDouble() << endl; 152 | cout << "未在 Bookmark 中找到此点。" << endl; 153 | fclose(stdout); return; 154 | } 155 | if (vis[x]) 156 | { 157 | cout << endl << "路线出现问题,需要修改!!!!!!!!!!!!" << endl; 158 | cout << "<" << P[x].label << "> 重复经过两次!" << endl; 159 | fclose(stdout); return; 160 | } 161 | 162 | int key=0, out=0; 163 | rep(i, 0, (int)v[x].size()-1) if (!InBook[v[x][i]]) 164 | v[x][i--]=v[x][(int)v[x].size()-1], v[x].pop_back(); 165 | else if (!vis[v[x][i]]) key++; else out++; 166 | 167 | cout << M0[x] << '\t' << P[x].label << '\t' << key << '\t' << out << '\t'; 168 | 169 | sort(all(v[x])); bool fg=false; 170 | rep(i, 0, (int)v[x].size()-1) if (InBook[v[x][i]] && vis[v[x][i]]) 171 | { 172 | if (fg) cout << endl << '\t' << '\t' << '\t' << '\t'; 173 | cout << P[v[x][i]].label; 174 | fg=true; 175 | } 176 | cout << endl; 177 | 178 | if (vis[F[x][0]] && vis[F[x][1]] && vis[F[x][2]]) 179 | { 180 | cout << endl << "啊路线出现问题,需要修改!!!!!!!!!!!!" << endl; 181 | cout << "<" << P[x].label << "> 必须比 <" << P[F[x][0]].label << ">,<" << P[F[x][1]].label << ">,<" << P[F[x][2]].label << "> 三个中的任意一个先经过" << endl; 182 | fclose(stdout); return; 183 | } 184 | vis[x]=1; 185 | } 186 | 187 | rep(i, 1, n) if (InBook[i] && !vis[i]) 188 | { 189 | cout << endl << "啊路线出现问题,需要修改!!!!!!!!!!!!" << endl; 190 | cout << "<" << P[i].label << "> 未经过!" << endl; 191 | fclose(stdout); return; 192 | } 193 | 194 | fclose(stdout); 195 | } 196 | 197 | int main() 198 | { 199 | getOpinion(); 200 | importBookmarks("bookmark.txt"); 201 | importWay("way.txt"); 202 | return 0; 203 | } 204 | -------------------------------------------------------------------------------- /src/HCF-SingleWork/way-sample.txt: -------------------------------------------------------------------------------- 1 | [{"type":"polyline","latLngs":[{"lat":23.353751,"lng":116.698035},{"lat":23.353605,"lng":116.692397},{"lat":23.353565,"lng":116.691958},{"lat":23.353631,"lng":116.691179},{"lat":23.353786,"lng":116.691033},{"lat":23.353669,"lng":116.690762},{"lat":23.3537,"lng":116.690356},{"lat":23.353749,"lng":116.689957},{"lat":23.353673,"lng":116.689686},{"lat":23.353652,"lng":116.689479},{"lat":23.353699,"lng":116.689134},{"lat":23.353711,"lng":116.688892},{"lat":23.353763,"lng":116.688387},{"lat":23.353745,"lng":116.687642},{"lat":23.353779,"lng":116.68489},{"lat":23.353838,"lng":116.681584}],"color":"#a24ac3"}] -------------------------------------------------------------------------------- /src/HCF/choose.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | using namespace std; 18 | 19 | #define pi acos(-1) 20 | #define maxPortal 1000 21 | #define maxField 166167001 22 | 23 | char tmp_char; 24 | 25 | int num = 0; 26 | 27 | inline int min3(const int a, const int b, const int c) { return (a <= b && a <= c) ? a : (b <= c ? b : c); } 28 | 29 | #define foreach(i) for(List *p = pl_head[i]; p; p = p->next) 30 | struct List{int x; List *next;} pl[maxPortal], *pl_head[9], *pl_end = pl; 31 | 32 | struct xyz { 33 | int x, y, z; 34 | xyz() {} 35 | xyz(int x, int y, int z) : x(x), y(y), z(z) {} 36 | bool operator < (const xyz &a) const { return x < a.x || (x == a.x && y < a.y) || (x == a.x && y == a.y && z < a.z); } 37 | xyz operator + (const xyz &a) const { return xyz(x + a.x, y + a.y, z + a.z); } 38 | xyz operator - (const xyz &a) const { return xyz(x - a.x, y - a.y, z - a.z); } 39 | xyz operator / (const double a) const { return xyz(x / a, y / a, z / a); } 40 | }; 41 | 42 | struct Portal 43 | { 44 | double lat, lng, x, y, z, S; 45 | string guid, latlng, label; 46 | xyz pos; 47 | Portal() : pos(0,0,0) {} 48 | Portal(double x, double y, double z) : x(x), y(y), z(z), pos(0,0,0) {} 49 | void to_xyz() { 50 | istringstream iss(latlng); 51 | iss >> lat >> tmp_char >> lng; 52 | x = cos(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 53 | y = sin(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 54 | z = sin(lng / 180.0 * pi); 55 | } 56 | bool operator == (const Portal &a) const { return guid == a.guid; } 57 | bool operator < (const Portal &a) const { return lat < a.lat || (lat == a.lat && lng < a.lng); } 58 | } P[maxPortal]; 59 | 60 | struct Field { 61 | int x; 62 | double S; 63 | Field() {} 64 | Field(int x, double S) : x(x), S(S) {} 65 | bool operator < (const Field &a) const { return S < a.S; } 66 | } qL[maxPortal], qR[maxPortal]; 67 | 68 | // Field_ID 是为了方便计算每个 Field 所对应的编号(详细见 GetFL 函数) 69 | int fieldID[maxPortal+1][maxPortal+1]; 70 | 71 | inline void swap3(int &a, int &b, int &c) { 72 | if (a > b) swap(a, b); 73 | if (b > c) swap(b, c); 74 | if (a > b) swap(a, b); 75 | } 76 | inline int portal2field(int a, int b, int c) { swap3(a, b, c); return fieldID[a][b] + c; } 77 | inline void field2portal(int f_id, int &a, int &b, int &c) { 78 | a = 0; 79 | while (a+1 < num-2 && fieldID[a+1][a+2] + a + 3 <= f_id) a++; 80 | b = a + 1; 81 | while (b+1 < num-1 && fieldID[a][b+1] + b + 2 <= f_id) b++; 82 | c = f_id - fieldID[a][b]; 83 | } 84 | 85 | inline Portal spin(const Portal &a, const Portal &b) { 86 | return Portal( 87 | (b.y * (a.x * b.y - a.y * b.x) - b.z * (a.z * b.x - a.x * b.z)), 88 | (b.z * (a.y * b.z - a.z * b.y) - b.x * (a.x * b.y - a.y * b.x)), 89 | (b.x * (a.z * b.x - a.x * b.z) - b.y * (a.y * b.z - a.z * b.y)) 90 | ); 91 | } 92 | 93 | inline double _cos(const Portal &a, const Portal &b) { 94 | return (a.x * b.x + a.y * b.y + a.z * b.z) 95 | / sqrt(a.x * a.x + a.y * a.y + a.z * a.z) 96 | / sqrt(b.x * b.x + b.y * b.y + b.z * b.z); 97 | } 98 | 99 | inline double angle(const Portal &a, const Portal &b, const Portal &c) { 100 | return acos(_cos(spin(a, b), spin(c, b))); 101 | } 102 | 103 | inline double area(const Portal &a, const Portal &b, const Portal &c) { 104 | return angle(a,b,c) + angle(b,c,a) + angle(c,a,b) - pi; 105 | } 106 | 107 | inline Portal normal(const Portal &a, const Portal &b) 108 | { 109 | return Portal( 110 | a.y * b.z - a.z * b.y, 111 | a.z * b.x - a.x * b.z, 112 | a.x * b.y - a.y * b.x 113 | ); 114 | } 115 | inline double dot(const Portal &a, const Portal &b) { return a.x * b.x + a.y * b.y + a.z * b.z;} 116 | inline bool isLeft(const Portal &a, const Portal &b, const Portal &c) { return dot(c, normal(a, b))>0;} 117 | 118 | inline bool inField(const Portal &a, const Portal &b, const Portal &c, const Portal &d) 119 | { 120 | if (d == a || d == b || d == c) return false; 121 | if (!isLeft(a, b, c)) 122 | return isLeft(a, c, d) && isLeft(c, b, d) && isLeft(b, a, d); 123 | else 124 | return isLeft(a, b, d) && isLeft(b, c, d) && isLeft(c, a, d); 125 | } 126 | 127 | inline void import(const char *localFileName) { 128 | string str, chunk; 129 | 130 | try { 131 | ifstream fin(localFileName); 132 | if (fin) { 133 | while (getline(fin, chunk) && chunk != "") str += chunk; 134 | } else throw ""; 135 | } catch (...) { 136 | puts("Please copy bookmarks into here:"); 137 | while (getline(cin, chunk) && chunk != "") str += chunk; 138 | } 139 | 140 | Json::Reader reader; 141 | Json::Value input; 142 | Json::Value::Members arrayMember; 143 | reader.parse(str, input); 144 | 145 | num = input["portals"]["idOthers"]["bkmrk"].getMemberNames().size(); 146 | 147 | printf("Portal nums: %d\n", num); 148 | 149 | if (num > maxPortal) { 150 | printf("Only support no more than %d portals.\n", maxPortal); 151 | getchar(); 152 | exit(0); 153 | } 154 | 155 | num = 0; 156 | 157 | arrayMember = input["portals"]["idOthers"]["bkmrk"].getMemberNames(); 158 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) { 159 | P[num].guid = input["portals"]["idOthers"]["bkmrk"][*iter]["guid"].asString(); 160 | P[num].latlng = input["portals"]["idOthers"]["bkmrk"][*iter]["latlng"].asString(); 161 | P[num].label = input["portals"]["idOthers"]["bkmrk"][*iter]["label"].asString(); 162 | P[num].to_xyz(); 163 | num += 1; 164 | } 165 | } 166 | 167 | char layer[maxField]; // 记录每个 Field 的最大层数 168 | 169 | short int nextPortal[maxField]; // 记录每个 Field 在达到最大层数时的内点 170 | int layerCount[8]; // layerCount[i] 表示有多少个 Field 其最大层数为 i 171 | int mxLayer[maxPortal+1][maxPortal+1]; // mxLayer[a][b] 表示向量 a→b 左边所形成的 Field 的最大层数 172 | 173 | clock_t gap; // 记录时间 174 | 175 | int needLayer; // 询问层数 176 | 177 | Json::Value bookmarks, drawnitems, bookmarks_INIT, drawnitems_NULL; 178 | int dr_num = 0; 179 | 180 | map l2p; // 编号映射到 xyz 参数 181 | map p2l; // xyz 参数映射到编号 182 | 183 | inline void getLabel() { 184 | 185 | // 设置三个顶点的 xyz 参数 186 | l2p["A1"] = xyz(5e8, 0, 0); 187 | l2p["A2"] = xyz(0, 5e8, 0); 188 | l2p["A3"] = xyz(0, 0, 5e8); 189 | p2l[xyz(5e8, 0, 0)] = "A1"; 190 | p2l[xyz(0, 5e8, 0)] = "A2"; 191 | p2l[xyz(0, 0, 5e8)] = "A3"; 192 | 193 | string str1 = "A", str2 = "Lv 0"; 194 | for (int i = 1; i <= needLayer; i++) { 195 | str1[0] = 'A' + i-1; 196 | str2[3] = '0' + i; 197 | bookmarks_INIT["portals"][str1]["label"] = str2; 198 | bookmarks_INIT["portals"][str1]["state"] = 0; 199 | } 200 | bookmarks_INIT["portals"]["A"]["bkmrk"]["A1"]["guid"] = ""; 201 | bookmarks_INIT["portals"]["A"]["bkmrk"]["A2"]["guid"] = ""; 202 | bookmarks_INIT["portals"]["A"]["bkmrk"]["A3"]["guid"] = ""; 203 | 204 | // LABEL 每一行有四个字符串,“A B C D” 表示以编号为 A,B,C 形成的 Field 的内点的编号为 D 205 | ifstream fin("../LABEL"); 206 | int maxLayer = 0, f_num = 0; 207 | fin >> maxLayer; 208 | for(int i = 1, j = 1; i < maxLayer; i++, j *= 3) f_num += j; 209 | 210 | string a, b, c, d; 211 | for (int i = 1; i <= f_num; i++) { 212 | fin >> a >> b >> c >> d; 213 | l2p[a] = (l2p[b] + l2p[c] + l2p[d]) / 3; 214 | p2l[l2p[a]] = a; 215 | if (a[0] - 'A' + 1 <= needLayer) { 216 | str1[0] = a[0]; 217 | bookmarks_INIT["portals"][str1]["bkmrk"][a]["guid"] = ""; 218 | } 219 | } 220 | } 221 | 222 | inline void addPortal(const Portal &a, const int level) 223 | { 224 | string groupName = "A"; 225 | groupName[0] += level - 1; 226 | bookmarks["portals"][groupName]["bkmrk"][p2l[a.pos]]["guid"] = a.guid; 227 | bookmarks["portals"][groupName]["bkmrk"][p2l[a.pos]]["latlng"] = a.latlng; 228 | bookmarks["portals"][groupName]["bkmrk"][p2l[a.pos]]["label"] = a.label; 229 | } 230 | 231 | inline void addLink(const Portal &a, const Portal &b, const int level) 232 | { 233 | switch (level) { 234 | case 1: drawnitems[dr_num]["color"] = "#0000ff"; break; 235 | case 2: drawnitems[dr_num]["color"] = "#2222ff"; break; 236 | case 3: drawnitems[dr_num]["color"] = "#4444ff"; break; 237 | case 4: drawnitems[dr_num]["color"] = "#6666ff"; break; 238 | case 5: drawnitems[dr_num]["color"] = "#8888ff"; break; 239 | case 6: drawnitems[dr_num]["color"] = "#aaaaff"; break; 240 | case 7: drawnitems[dr_num]["color"] = "#ccccff"; break; 241 | } 242 | 243 | drawnitems[dr_num]["latLngs"][0]["lat"] = to_string(a.lat); 244 | drawnitems[dr_num]["latLngs"][0]["lng"] = to_string(a.lng); 245 | drawnitems[dr_num]["latLngs"][1]["lat"] = to_string(b.lat); 246 | drawnitems[dr_num]["latLngs"][1]["lng"] = to_string(b.lng); 247 | drawnitems[dr_num]["type"] = "polyline"; 248 | dr_num++; 249 | } 250 | 251 | void outputSolution(int a, int b, int c, int level) { 252 | if (level == needLayer) return; 253 | swap3(a, b, c); 254 | if (level == 1) { 255 | addLink(P[a], P[b], level); 256 | addLink(P[b], P[c], level); 257 | addLink(P[c], P[a], level); 258 | P[a].pos = xyz(5e8, 0, 0), addPortal(P[a], level); // 由 xyz 参数查询到当前点所对应的编号 259 | P[b].pos = xyz(0, 5e8, 0), addPortal(P[b], level); 260 | P[c].pos = xyz(0, 0, 5e8), addPortal(P[c], level); 261 | } 262 | int x = portal2field(a, b, c); 263 | int d = nextPortal[x]; 264 | P[d].pos = (P[a].pos + P[b].pos + P[c].pos) / 3; 265 | addPortal(P[d], ++level); 266 | addLink(P[a], P[d], level); 267 | addLink(P[b], P[d], level); 268 | addLink(P[c], P[d], level); 269 | 270 | // 递归输出方案 271 | outputSolution(a, b, d, level); 272 | outputSolution(b, c, d, level); 273 | outputSolution(c, a, d, level); 274 | } 275 | 276 | // 输出方案到 JSON 277 | inline void outputSolution(int f_id) { 278 | int a, b, c; 279 | field2portal(f_id, a, b, c); 280 | drawnitems = drawnitems_NULL; 281 | bookmarks = bookmarks_INIT; 282 | dr_num = 0; 283 | outputSolution(a, b, c, 1); 284 | 285 | Json::FastWriter writer; 286 | puts("Bookmarks JSON:"); cout << writer.write(bookmarks) << endl; 287 | puts("DrawTools JSON:"); cout << writer.write(drawnitems) << endl; 288 | } 289 | 290 | #define maxRandomChoose 1000000 291 | int rChoose[maxRandomChoose]; 292 | #define minFieldChoose 10 293 | #define maxFieldChoose 10 294 | #define ranFieldChoose 30 295 | 296 | inline void outputResult() { 297 | freopen("result.txt", "w", stdout); 298 | 299 | priority_queue q; 300 | int q_tot, r_tot, f_id; 301 | 302 | // 输出最小的前 minFieldChoose 个方案 303 | q_tot = 0, r_tot = 0; 304 | for (int i = 0; i < num; i++) for (int j = i+1; j < num; j++) for (int k = j+1; k < num; k++) { 305 | if (layer[f_id = portal2field(i, j, k)] >= needLayer) { 306 | if (q_tot == minFieldChoose) { 307 | q.pop(), q_tot--; 308 | } 309 | q.push(Field(f_id, area(P[i], P[j], P[k]))); q_tot++; 310 | 311 | if (r_tot < maxRandomChoose) rChoose[r_tot++] = f_id; 312 | } 313 | } 314 | while (q_tot) { 315 | printf("minimum area: #%d\n\n", q_tot); 316 | outputSolution(q.top().x); 317 | q.pop(); q_tot--; 318 | } 319 | 320 | // 输出最大的前 maxFieldChoose 个方案 321 | q_tot = 0, r_tot = 0; 322 | for (int i = 0; i < num; i++) for (int j = i+1; j < num; j++) for (int k = j+1; k < num; k++) { 323 | if (layer[f_id = portal2field(i, j, k)] >= needLayer) { 324 | if (q_tot == minFieldChoose) { 325 | q.pop(), q_tot--; 326 | } 327 | q.push(Field(f_id, -area(P[i], P[j], P[k]))); q_tot++; 328 | 329 | if (r_tot < maxRandomChoose) rChoose[r_tot++] = f_id; 330 | } 331 | } 332 | while (q_tot) { 333 | printf("maximum area: #%d\n\n", q_tot); 334 | outputSolution(q.top().x); 335 | q.pop(); q_tot--; 336 | } 337 | 338 | // 随机输出 ranFieldChoose 个方案 339 | random_shuffle(rChoose, rChoose + r_tot); 340 | for (int i = 0; i < min(r_tot, ranFieldChoose); i++) { 341 | printf("random op: #%d\n\n", i+1); 342 | outputSolution(rChoose[i]); 343 | } 344 | 345 | // 重名预警 346 | printf("duplication of Portal name:\n"); 347 | for (int i = 0; i < num; i++) for (int j = i+1; j < num; j++) if (P[i].label == P[j].label) { 348 | cout << P[i].label << endl; 349 | break; 350 | } 351 | 352 | fclose(stdout); 353 | } 354 | 355 | int main() { 356 | srand(time(NULL)); 357 | 358 | cout << "请将导出的 Bookmark 储存为 portal.txt 并放置于同目录下" << endl; 359 | getchar(); 360 | import("portal.txt"); 361 | 362 | // 按经纬坐标排序 363 | sort(P, P + num); 364 | 365 | // 枚举左端点和中间端点,f_tot 记录 Field 总数,fieldID 是为了方便计算每个 Field 所对应的编号(详细见 portal2field 函数) 366 | int f_tot = 0; 367 | for (int i = 0; i < num-2; i++) for (int j = i+1; j < num-1; j++) { 368 | f_tot += num-j; 369 | fieldID[i][j] = f_tot - num; 370 | } 371 | 372 | int f_now = 0, totL, totR; // f_now 表示当前已经处理完了多少个 Field 373 | // 从左往右枚举右端点,从右往左枚举左端点 374 | for (int c = 2; c < num; c++) for (int a = c-2; a >= 0; a--) { 375 | totL = totR = 0; 376 | 377 | // 枚举中间端点,qL[] 为向量 a→c 左边的 Portal(总数为 totL),qR[] 为向量 a→c 右边的 Portal(总数为 totR) 378 | for (int b = a+1; b <= c-1; b++) { 379 | if (isLeft(P[a], P[c], P[b])) { 380 | qL[totL++] = Field(b, area(P[a], P[b], P[c])); 381 | } else { 382 | qR[totR++] = Field(b, area(P[a], P[c], P[b])); 383 | } 384 | } 385 | 386 | if (totL) { 387 | sort(qL, qL + totL); 388 | memset(pl_head, 0, sizeof(pl_head)); 389 | pl_end = pl; 390 | for (int i = 0; i < totL; i++) { 391 | int b = qL[i].x; 392 | int f_id = portal2field(a, b, c); 393 | // int mxLayer = ; 394 | // char &Lv = layer[f_id]; 395 | layer[f_id] = 1; 396 | 397 | // 从高到低枚举内层 Field 等级并遍历 List 398 | for(int o = max(mxLayer[c][b], mxLayer[b][a]); o >= 1; o--) { 399 | foreach(o) { 400 | if (layer[f_id] > o) break; else if (inField(P[a], P[b], P[c], P[p->x])) { 401 | int tmp = min3(o, layer[portal2field(a, b, p->x)], layer[portal2field(b, c, p->x)]) + 1; 402 | if (tmp > layer[f_id]) { 403 | layer[f_id] = tmp; 404 | nextPortal[f_id] = p->x; 405 | } 406 | } 407 | } 408 | } 409 | 410 | // 判断下当 b 作为内点 a-c 做边的时候最多能多少层 411 | int tmp = min3((int)layer[f_id], mxLayer[a][b], mxLayer[b][c]); 412 | 413 | // 将 b 加入到 List[tmp] 414 | pl_end->x = b; 415 | pl_end->next = pl_head[tmp]; 416 | pl_head[tmp] = pl_end++; 417 | 418 | // 更新 Lmx 数组 419 | if (mxLayer[a][c] < layer[f_id]) mxLayer[a][c] = layer[f_id]; 420 | if (mxLayer[c][b] < layer[f_id]) mxLayer[c][b] = layer[f_id]; 421 | if (mxLayer[b][a] < layer[f_id]) mxLayer[b][a] = layer[f_id]; 422 | 423 | layerCount[(int)layer[f_id]]++; 424 | f_now++; 425 | 426 | // 每隔 0.1s 显示一次百分比进度 427 | if ((double)(clock() - gap) / CLOCKS_PER_SEC >= 0.1) { 428 | printf("%.6lf%%\n", 100.0 * f_now / f_tot); 429 | gap = clock(); 430 | } 431 | } 432 | } 433 | 434 | if (totR) { 435 | sort(qR, qR + totR); 436 | memset(pl_head, 0, sizeof(pl_head)); 437 | pl_end = pl; 438 | for (int i = 0; i < totR; i++) { 439 | int b = qR[i].x; 440 | int f_id = portal2field(a, b, c); 441 | // int mxLayer = ; 442 | // char &Lv = layer[f_id]; 443 | layer[f_id] = 1; 444 | 445 | // 从高到低枚举内层 Field 等级并遍历 List 446 | for(int o = max(mxLayer[a][b], mxLayer[b][c]); o >= 1; o--) { 447 | foreach(o) { 448 | if (layer[f_id] > o) break; else if (inField(P[a], P[b], P[c], P[p->x])) { 449 | int tmp = min3(o, layer[portal2field(a, b, p->x)], layer[portal2field(b, c, p->x)]) + 1; 450 | if (tmp > layer[f_id]) { 451 | layer[f_id] = tmp; 452 | nextPortal[f_id] = p->x; 453 | } 454 | } 455 | } 456 | } 457 | 458 | // 判断下当 b 作为内点 a-c 做边的时候最多能多少层 459 | int tmp = min3((int)layer[f_id], mxLayer[c][b], mxLayer[b][a]); 460 | 461 | // 将 b 加入到 List[tmp] 462 | pl_end->x = b; 463 | pl_end->next = pl_head[tmp]; 464 | pl_head[tmp] = pl_end++; 465 | 466 | // 更新 Lmx 数组 467 | if (mxLayer[a][b] < layer[f_id]) mxLayer[a][b] = layer[f_id]; 468 | if (mxLayer[b][c] < layer[f_id]) mxLayer[b][c] = layer[f_id]; 469 | if (mxLayer[c][a] < layer[f_id]) mxLayer[c][a] = layer[f_id]; 470 | 471 | layerCount[(int)layer[f_id]]++; 472 | f_now++; 473 | 474 | // 每隔 0.1s 显示一次百分比进度 475 | if ((double)(clock() - gap) / CLOCKS_PER_SEC >= 0.1) { 476 | printf("%.6lf%%\n", 100.0 * f_now / f_tot); 477 | gap = clock(); 478 | } 479 | } 480 | } 481 | } 482 | 483 | for (int i = 3; i <= 7; i++) printf("%d Layers: %d Solutions\n", i, layerCount[i]); 484 | needLayer = 0; 485 | while (needLayer < 3 || needLayer > 7) { 486 | puts("What kind of solutions do you need? (3-7)\n"); 487 | scanf("%d", &needLayer); 488 | } 489 | 490 | puts("Wait for a moment, and then you can see the results in `result.txt`, good luck >.<"); 491 | getLabel(); 492 | outputResult(); 493 | 494 | return 0; 495 | } 496 | -------------------------------------------------------------------------------- /src/LABEL: -------------------------------------------------------------------------------- 1 | 7 2 | B1 A1 A2 A3 3 | C1 A1 A2 B1 4 | C2 A2 A3 B1 5 | C3 A3 A1 B1 6 | D1 A1 A2 C1 7 | D2 A2 B1 C1 8 | D3 B1 A1 C1 9 | D4 A2 A3 C2 10 | D5 A3 B1 C2 11 | D6 B1 A2 C2 12 | D7 A3 A1 C3 13 | D8 A1 B1 C3 14 | D9 B1 A3 C3 15 | E1 A1 A2 D1 16 | E2 A2 C1 D1 17 | E3 C1 A1 D1 18 | E4 A2 B1 D2 19 | E5 B1 C1 D2 20 | E6 C1 A2 D2 21 | E7 B1 A1 D3 22 | E8 A1 C1 D3 23 | E9 C1 B1 D3 24 | E10 A2 A3 D4 25 | E11 A3 C2 D4 26 | E12 C2 A2 D4 27 | E13 A3 B1 D5 28 | E14 B1 C2 D5 29 | E15 C2 A3 D5 30 | E16 B1 A2 D6 31 | E17 A2 C2 D6 32 | E18 C2 B1 D6 33 | E19 A3 A1 D7 34 | E20 A1 C3 D7 35 | E21 C3 A3 D7 36 | E22 A1 B1 D8 37 | E23 B1 C3 D8 38 | E24 C3 A1 D8 39 | E25 B1 A3 D9 40 | E26 A3 C3 D9 41 | E27 C3 B1 D9 42 | F1 A1 A2 E1 43 | F2 A2 D1 E1 44 | F3 D1 A1 E1 45 | F4 A2 C1 E2 46 | F5 C1 D1 E2 47 | F6 D1 A2 E2 48 | F7 C1 A1 E3 49 | F8 A1 D1 E3 50 | F9 D1 C1 E3 51 | F10 A2 B1 E4 52 | F11 B1 D2 E4 53 | F12 D2 A2 E4 54 | F13 B1 C1 E5 55 | F14 C1 D2 E5 56 | F15 D2 B1 E5 57 | F16 C1 A2 E6 58 | F17 A2 D2 E6 59 | F18 D2 C1 E6 60 | F19 B1 A1 E7 61 | F20 A1 D3 E7 62 | F21 D3 B1 E7 63 | F22 A1 C1 E8 64 | F23 C1 D3 E8 65 | F24 D3 A1 E8 66 | F25 C1 B1 E9 67 | F26 B1 D3 E9 68 | F27 D3 C1 E9 69 | F28 A2 A3 E10 70 | F29 A3 D4 E10 71 | F30 D4 A2 E10 72 | F31 A3 C2 E11 73 | F32 C2 D4 E11 74 | F33 D4 A3 E11 75 | F34 C2 A2 E12 76 | F35 A2 D4 E12 77 | F36 D4 C2 E12 78 | F37 A3 B1 E13 79 | F38 B1 D5 E13 80 | F39 D5 A3 E13 81 | F40 B1 C2 E14 82 | F41 C2 D5 E14 83 | F42 D5 B1 E14 84 | F43 C2 A3 E15 85 | F44 A3 D5 E15 86 | F45 D5 C2 E15 87 | F46 B1 A2 E16 88 | F47 A2 D6 E16 89 | F48 D6 B1 E16 90 | F49 A2 C2 E17 91 | F50 C2 D6 E17 92 | F51 D6 A2 E17 93 | F52 C2 B1 E18 94 | F53 B1 D6 E18 95 | F54 D6 C2 E18 96 | F55 A3 A1 E19 97 | F56 A1 D7 E19 98 | F57 D7 A3 E19 99 | F58 A1 C3 E20 100 | F59 C3 D7 E20 101 | F60 D7 A1 E20 102 | F61 C3 A3 E21 103 | F62 A3 D7 E21 104 | F63 D7 C3 E21 105 | F64 A1 B1 E22 106 | F65 B1 D8 E22 107 | F66 D8 A1 E22 108 | F67 B1 C3 E23 109 | F68 C3 D8 E23 110 | F69 D8 B1 E23 111 | F70 C3 A1 E24 112 | F71 A1 D8 E24 113 | F72 D8 C3 E24 114 | F73 B1 A3 E25 115 | F74 A3 D9 E25 116 | F75 D9 B1 E25 117 | F76 A3 C3 E26 118 | F77 C3 D9 E26 119 | F78 D9 A3 E26 120 | F79 C3 B1 E27 121 | F80 B1 D9 E27 122 | F81 D9 C3 E27 123 | G1 A1 A2 F1 124 | G2 A2 E1 F1 125 | G3 E1 A1 F1 126 | G4 A2 D1 F2 127 | G5 D1 E1 F2 128 | G6 E1 A2 F2 129 | G7 D1 A1 F3 130 | G8 A1 E1 F3 131 | G9 E1 D1 F3 132 | G10 A2 C1 F4 133 | G11 C1 E2 F4 134 | G12 E2 A2 F4 135 | G13 C1 D1 F5 136 | G14 D1 E2 F5 137 | G15 E2 C1 F5 138 | G16 D1 A2 F6 139 | G17 A2 E2 F6 140 | G18 E2 D1 F6 141 | G19 C1 A1 F7 142 | G20 A1 E3 F7 143 | G21 E3 C1 F7 144 | G22 A1 D1 F8 145 | G23 D1 E3 F8 146 | G24 E3 A1 F8 147 | G25 D1 C1 F9 148 | G26 C1 E3 F9 149 | G27 E3 D1 F9 150 | G28 A2 B1 F10 151 | G29 B1 E4 F10 152 | G30 E4 A2 F10 153 | G31 B1 D2 F11 154 | G32 D2 E4 F11 155 | G33 E4 B1 F11 156 | G34 D2 A2 F12 157 | G35 A2 E4 F12 158 | G36 E4 D2 F12 159 | G37 B1 C1 F13 160 | G38 C1 E5 F13 161 | G39 E5 B1 F13 162 | G40 C1 D2 F14 163 | G41 D2 E5 F14 164 | G42 E5 C1 F14 165 | G43 D2 B1 F15 166 | G44 B1 E5 F15 167 | G45 E5 D2 F15 168 | G46 C1 A2 F16 169 | G47 A2 E6 F16 170 | G48 E6 C1 F16 171 | G49 A2 D2 F17 172 | G50 D2 E6 F17 173 | G51 E6 A2 F17 174 | G52 D2 C1 F18 175 | G53 C1 E6 F18 176 | G54 E6 D2 F18 177 | G55 B1 A1 F19 178 | G56 A1 E7 F19 179 | G57 E7 B1 F19 180 | G58 A1 D3 F20 181 | G59 D3 E7 F20 182 | G60 E7 A1 F20 183 | G61 D3 B1 F21 184 | G62 B1 E7 F21 185 | G63 E7 D3 F21 186 | G64 A1 C1 F22 187 | G65 C1 E8 F22 188 | G66 E8 A1 F22 189 | G67 C1 D3 F23 190 | G68 D3 E8 F23 191 | G69 E8 C1 F23 192 | G70 D3 A1 F24 193 | G71 A1 E8 F24 194 | G72 E8 D3 F24 195 | G73 C1 B1 F25 196 | G74 B1 E9 F25 197 | G75 E9 C1 F25 198 | G76 B1 D3 F26 199 | G77 D3 E9 F26 200 | G78 E9 B1 F26 201 | G79 D3 C1 F27 202 | G80 C1 E9 F27 203 | G81 E9 D3 F27 204 | G82 A2 A3 F28 205 | G83 A3 E10 F28 206 | G84 E10 A2 F28 207 | G85 A3 D4 F29 208 | G86 D4 E10 F29 209 | G87 E10 A3 F29 210 | G88 D4 A2 F30 211 | G89 A2 E10 F30 212 | G90 E10 D4 F30 213 | G91 A3 C2 F31 214 | G92 C2 E11 F31 215 | G93 E11 A3 F31 216 | G94 C2 D4 F32 217 | G95 D4 E11 F32 218 | G96 E11 C2 F32 219 | G97 D4 A3 F33 220 | G98 A3 E11 F33 221 | G99 E11 D4 F33 222 | G100 C2 A2 F34 223 | G101 A2 E12 F34 224 | G102 E12 C2 F34 225 | G103 A2 D4 F35 226 | G104 D4 E12 F35 227 | G105 E12 A2 F35 228 | G106 D4 C2 F36 229 | G107 C2 E12 F36 230 | G108 E12 D4 F36 231 | G109 A3 B1 F37 232 | G110 B1 E13 F37 233 | G111 E13 A3 F37 234 | G112 B1 D5 F38 235 | G113 D5 E13 F38 236 | G114 E13 B1 F38 237 | G115 D5 A3 F39 238 | G116 A3 E13 F39 239 | G117 E13 D5 F39 240 | G118 B1 C2 F40 241 | G119 C2 E14 F40 242 | G120 E14 B1 F40 243 | G121 C2 D5 F41 244 | G122 D5 E14 F41 245 | G123 E14 C2 F41 246 | G124 D5 B1 F42 247 | G125 B1 E14 F42 248 | G126 E14 D5 F42 249 | G127 C2 A3 F43 250 | G128 A3 E15 F43 251 | G129 E15 C2 F43 252 | G130 A3 D5 F44 253 | G131 D5 E15 F44 254 | G132 E15 A3 F44 255 | G133 D5 C2 F45 256 | G134 C2 E15 F45 257 | G135 E15 D5 F45 258 | G136 B1 A2 F46 259 | G137 A2 E16 F46 260 | G138 E16 B1 F46 261 | G139 A2 D6 F47 262 | G140 D6 E16 F47 263 | G141 E16 A2 F47 264 | G142 D6 B1 F48 265 | G143 B1 E16 F48 266 | G144 E16 D6 F48 267 | G145 A2 C2 F49 268 | G146 C2 E17 F49 269 | G147 E17 A2 F49 270 | G148 C2 D6 F50 271 | G149 D6 E17 F50 272 | G150 E17 C2 F50 273 | G151 D6 A2 F51 274 | G152 A2 E17 F51 275 | G153 E17 D6 F51 276 | G154 C2 B1 F52 277 | G155 B1 E18 F52 278 | G156 E18 C2 F52 279 | G157 B1 D6 F53 280 | G158 D6 E18 F53 281 | G159 E18 B1 F53 282 | G160 D6 C2 F54 283 | G161 C2 E18 F54 284 | G162 E18 D6 F54 285 | G163 A3 A1 F55 286 | G164 A1 E19 F55 287 | G165 E19 A3 F55 288 | G166 A1 D7 F56 289 | G167 D7 E19 F56 290 | G168 E19 A1 F56 291 | G169 D7 A3 F57 292 | G170 A3 E19 F57 293 | G171 E19 D7 F57 294 | G172 A1 C3 F58 295 | G173 C3 E20 F58 296 | G174 E20 A1 F58 297 | G175 C3 D7 F59 298 | G176 D7 E20 F59 299 | G177 E20 C3 F59 300 | G178 D7 A1 F60 301 | G179 A1 E20 F60 302 | G180 E20 D7 F60 303 | G181 C3 A3 F61 304 | G182 A3 E21 F61 305 | G183 E21 C3 F61 306 | G184 A3 D7 F62 307 | G185 D7 E21 F62 308 | G186 E21 A3 F62 309 | G187 D7 C3 F63 310 | G188 C3 E21 F63 311 | G189 E21 D7 F63 312 | G190 A1 B1 F64 313 | G191 B1 E22 F64 314 | G192 E22 A1 F64 315 | G193 B1 D8 F65 316 | G194 D8 E22 F65 317 | G195 E22 B1 F65 318 | G196 D8 A1 F66 319 | G197 A1 E22 F66 320 | G198 E22 D8 F66 321 | G199 B1 C3 F67 322 | G200 C3 E23 F67 323 | G201 E23 B1 F67 324 | G202 C3 D8 F68 325 | G203 D8 E23 F68 326 | G204 E23 C3 F68 327 | G205 D8 B1 F69 328 | G206 B1 E23 F69 329 | G207 E23 D8 F69 330 | G208 C3 A1 F70 331 | G209 A1 E24 F70 332 | G210 E24 C3 F70 333 | G211 A1 D8 F71 334 | G212 D8 E24 F71 335 | G213 E24 A1 F71 336 | G214 D8 C3 F72 337 | G215 C3 E24 F72 338 | G216 E24 D8 F72 339 | G217 B1 A3 F73 340 | G218 A3 E25 F73 341 | G219 E25 B1 F73 342 | G220 A3 D9 F74 343 | G221 D9 E25 F74 344 | G222 E25 A3 F74 345 | G223 D9 B1 F75 346 | G224 B1 E25 F75 347 | G225 E25 D9 F75 348 | G226 A3 C3 F76 349 | G227 C3 E26 F76 350 | G228 E26 A3 F76 351 | G229 C3 D9 F77 352 | G230 D9 E26 F77 353 | G231 E26 C3 F77 354 | G232 D9 A3 F78 355 | G233 A3 E26 F78 356 | G234 E26 D9 F78 357 | G235 C3 B1 F79 358 | G236 B1 E27 F79 359 | G237 E27 C3 F79 360 | G238 B1 D9 F80 361 | G239 D9 E27 F80 362 | G240 E27 B1 F80 363 | G241 D9 C3 F81 364 | G242 C3 E27 F81 365 | G243 E27 D9 F81 366 | -------------------------------------------------------------------------------- /src/MultField/mult-choose.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | 17 | #define pi acos(-1) 18 | #define maxPortal 1000 19 | 20 | char tmp_char; 21 | 22 | struct Portal 23 | { 24 | double lat, lng, x, y, z, S; 25 | string guid, latlng, label; 26 | Portal() : S(0) {} 27 | Portal(double x, double y, double z) : x(x), y(y), z(z), S(0) {} 28 | void to_xyz() { 29 | istringstream iss(latlng); 30 | iss >> lat >> tmp_char >> lng; 31 | x = cos(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 32 | y = sin(lat / 180.0 * pi) * cos(lng / 180.0 * pi); 33 | z = sin(lng / 180.0 * pi); 34 | } 35 | bool operator==(const Portal &a) const { return guid == a.guid; } 36 | } PortalA[maxPortal], PortalB[maxPortal], PortalC[maxPortal]; 37 | 38 | inline Portal spin(const Portal &a, const Portal &b) { 39 | return Portal( 40 | (b.y * (a.x * b.y - a.y * b.x) - b.z * (a.z * b.x - a.x * b.z)), 41 | (b.z * (a.y * b.z - a.z * b.y) - b.x * (a.x * b.y - a.y * b.x)), 42 | (b.x * (a.z * b.x - a.x * b.z) - b.y * (a.y * b.z - a.z * b.y)) 43 | ); 44 | } 45 | 46 | inline double _cos(const Portal &a, const Portal &b) { 47 | return (a.x * b.x + a.y * b.y + a.z * b.z) 48 | / sqrt(a.x * a.x + a.y * a.y + a.z * a.z) 49 | / sqrt(b.x * b.x + b.y * b.y + b.z * b.z); 50 | } 51 | 52 | inline double angle(const Portal &a, const Portal &b, const Portal &c) { 53 | return acos(_cos(spin(a, b), spin(c, b))); 54 | } 55 | 56 | inline double area(const Portal &a, const Portal &b, const Portal &c) { 57 | return angle(a,b,c) + angle(b,c,a) + angle(c,a,b) - pi; 58 | } 59 | 60 | inline Portal normal(const Portal &a, const Portal &b) 61 | { 62 | return Portal( 63 | a.y * b.z - a.z * b.y, 64 | a.z * b.x - a.x * b.z, 65 | a.x * b.y - a.y * b.x 66 | ); 67 | } 68 | inline double dot(const Portal &a, const Portal &b) { return a.x * b.x + a.y * b.y + a.z * b.z;} 69 | inline bool isLeft(const Portal &a, const Portal &b, const Portal &c) { return dot(c, normal(a, b))>0;} 70 | 71 | inline bool inField(const Portal &a, const Portal &b, const Portal &c, const Portal &d) 72 | { 73 | if (d == a || d == b || d == c) return false; 74 | if (!isLeft(a, b, c)) 75 | return isLeft(a, c, d) && isLeft(c, b, d) && isLeft(b, a, d); 76 | else 77 | return isLeft(a, b, d) && isLeft(b, c, d) && isLeft(c, a, d); 78 | } 79 | 80 | int num = 0, A_num = 0, B_num = 0, C_num = 0; 81 | 82 | inline void import(const char *localFileName) { 83 | string str, chunk; 84 | 85 | try { 86 | ifstream fin(localFileName); 87 | if (fin) { 88 | while (getline(fin, chunk) && chunk != "") str += chunk; 89 | } else throw ""; 90 | } catch (...) { 91 | puts("Please copy bookmarks into here:"); 92 | while (getline(cin, chunk) && chunk != "") str += chunk; 93 | } 94 | 95 | Json::Reader reader; 96 | Json::Value input; 97 | Json::Value::Members arrayMember; 98 | reader.parse(str, input); 99 | 100 | num = 0; 101 | num += input["portals"]["idA"]["bkmrk"].getMemberNames().size(); 102 | num += input["portals"]["idB"]["bkmrk"].getMemberNames().size(); 103 | num += input["portals"]["idOthers"]["bkmrk"].getMemberNames().size(); 104 | 105 | printf("Portal nums: %d\n", num); 106 | 107 | if (num > maxPortal) { 108 | printf("Only support no more than %d portals.\n", maxPortal); 109 | getchar(); 110 | exit(0); 111 | } 112 | 113 | arrayMember = input["portals"]["idA"]["bkmrk"].getMemberNames(); 114 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) { 115 | PortalA[A_num].guid = input["portals"]["idA"]["bkmrk"][*iter]["guid"].asString(); 116 | PortalA[A_num].latlng = input["portals"]["idA"]["bkmrk"][*iter]["latlng"].asString(); 117 | PortalA[A_num].label = input["portals"]["idA"]["bkmrk"][*iter]["label"].asString(); 118 | PortalA[A_num].to_xyz(); 119 | A_num += 1; 120 | } 121 | if (A_num == 0) { 122 | puts("Folder A should not be null."); 123 | getchar(); 124 | exit(0); 125 | } 126 | 127 | arrayMember = input["portals"]["idB"]["bkmrk"].getMemberNames(); 128 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) { 129 | PortalB[B_num].guid = input["portals"]["idB"]["bkmrk"][*iter]["guid"].asString(); 130 | PortalB[B_num].latlng = input["portals"]["idB"]["bkmrk"][*iter]["latlng"].asString(); 131 | PortalB[B_num].label = input["portals"]["idB"]["bkmrk"][*iter]["label"].asString(); 132 | PortalB[B_num].to_xyz(); 133 | B_num += 1; 134 | } 135 | if (B_num == 0) { 136 | puts("Folder B should not be null."); 137 | getchar(); 138 | exit(0); 139 | } 140 | 141 | arrayMember = input["portals"]["idOthers"]["bkmrk"].getMemberNames(); 142 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) { 143 | PortalC[C_num].guid = input["portals"]["idOthers"]["bkmrk"][*iter]["guid"].asString(); 144 | PortalC[C_num].latlng = input["portals"]["idOthers"]["bkmrk"][*iter]["latlng"].asString(); 145 | PortalC[C_num].label = input["portals"]["idOthers"]["bkmrk"][*iter]["label"].asString(); 146 | PortalC[C_num].to_xyz(); 147 | C_num += 1; 148 | } 149 | } 150 | 151 | Json::Value bookmarks, drawnitems; 152 | int bm_num = 0, dr_num = 0; 153 | 154 | inline void addPortal(const Portal &a) 155 | { 156 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["guid"] = a.guid; 157 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["latlng"] = a.latlng; 158 | bookmarks["portals"]["idOthers"]["bkmrk"][to_string(bm_num)]["label"] = a.label; 159 | bm_num++; 160 | } 161 | 162 | inline void addLink(const Portal &a, const Portal &b) 163 | { 164 | drawnitems[dr_num]["latLngs"][0]["lat"] = to_string(a.lat); 165 | drawnitems[dr_num]["latLngs"][0]["lng"] = to_string(a.lng); 166 | drawnitems[dr_num]["latLngs"][1]["lat"] = to_string(b.lat); 167 | drawnitems[dr_num]["latLngs"][1]["lng"] = to_string(b.lng); 168 | drawnitems[dr_num]["color"] = "#0099FF"; 169 | drawnitems[dr_num]["type"] = "polyline"; 170 | dr_num++; 171 | } 172 | 173 | vector > q; 174 | 175 | int layer[maxPortal], nxt[maxPortal], maxLayer = 0; 176 | 177 | int main() { 178 | import("portal.txt"); 179 | 180 | addLink(PortalA[0], PortalB[0]); 181 | 182 | q.clear(); 183 | for (int i = 0; i < C_num; i++) { 184 | if (isLeft(PortalA[0], PortalB[0], PortalC[i])) { 185 | q.push_back(pair(area(PortalA[0], PortalB[0], PortalC[i]), i)); 186 | } 187 | } 188 | sort(q.begin(), q.end()); 189 | maxLayer = 1; 190 | for (int i = 0; i < C_num; i++) layer[i] = 0; 191 | for (int i = 0; i < (int)q.size(); i++) { 192 | layer[q[i].second] = 1; 193 | for (int j = 0; j < i; j++) if (layer[q[i].second] < layer[q[j].second] + 1) { 194 | for (int ia = 0; ia < A_num; ia++) 195 | for (int ib = 0; ib < A_num; ib++) 196 | if (!inField(PortalA[ia], PortalB[ib], PortalC[q[i].second], PortalC[q[j].second])) goto brk1; 197 | layer[q[i].second] = layer[q[j].second] + 1; 198 | nxt[q[i].second] = q[j].second; 199 | brk1:; 200 | } 201 | maxLayer = max(maxLayer, layer[q[i].second]); 202 | } 203 | for (int i = 0; i < C_num; i++) if (layer[i] == maxLayer) 204 | { 205 | addPortal(PortalC[i]); 206 | addLink(PortalA[0], PortalC[i]); 207 | addLink(PortalB[0], PortalC[i]); 208 | while (layer[i] != 1) { 209 | addLink(PortalC[i], PortalC[nxt[i]]); 210 | i = nxt[i]; 211 | addPortal(PortalC[i]); 212 | addLink(PortalA[0], PortalC[i]); 213 | addLink(PortalB[0], PortalC[i]); 214 | } 215 | break; 216 | } 217 | 218 | q.clear(); 219 | for (int i = 0; i < C_num; i++) { 220 | if (isLeft(PortalB[0], PortalA[0], PortalC[i])) { 221 | q.push_back(pair(area(PortalA[0], PortalB[0], PortalC[i]), i)); 222 | } 223 | } 224 | sort(q.begin(), q.end()); 225 | maxLayer = 1; 226 | for (int i = 0; i < C_num; i++) layer[i] = 0; 227 | for (int i = 0; i < (int)q.size(); i++) { 228 | layer[q[i].second] = 1; 229 | for (int j = 0; j < i; j++) if (layer[q[i].second] < layer[q[j].second] + 1) { 230 | for (int ia = 0; ia < A_num; ia++) 231 | for (int ib = 0; ib < A_num; ib++) 232 | if (!inField(PortalA[ia], PortalB[ib], PortalC[q[i].second], PortalC[q[j].second])) goto brk2; 233 | layer[q[i].second] = layer[q[j].second] + 1; 234 | nxt[q[i].second] = q[j].second; 235 | brk2:; 236 | } 237 | maxLayer = max(maxLayer, layer[q[i].second]); 238 | } 239 | for (int i = 0; i < C_num; i++) if (layer[i] == maxLayer) 240 | { 241 | addPortal(PortalC[i]); 242 | addLink(PortalA[0], PortalC[i]); 243 | addLink(PortalB[0], PortalC[i]); 244 | while (layer[i] != 1) { 245 | addLink(PortalC[i], PortalC[nxt[i]]); 246 | i = nxt[i]; 247 | addPortal(PortalC[i]); 248 | addLink(PortalA[0], PortalC[i]); 249 | addLink(PortalB[0], PortalC[i]); 250 | } 251 | break; 252 | } 253 | 254 | freopen("mult-result.txt", "w", stdout); 255 | 256 | Json::FastWriter writer; 257 | puts("Bookmarks JSON:"); cout << writer.write(bookmarks) << endl; 258 | puts("DrawTools JSON:"); cout << writer.write(drawnitems) << endl; 259 | 260 | fclose(stdout); 261 | 262 | return 0; 263 | } 264 | -------------------------------------------------------------------------------- /src/MultField/mult-portal-sample.txt: -------------------------------------------------------------------------------- 1 | {"maps":{"idOthers":{"label":"Others","state":1,"bkmrk":{}}},"portals":{"idA":{"label":"A","state":1,"bkmrk":{"id158152833661613495":{"guid":"b0001ee608cd4acf85a602ffc0f0c7c7.12","latlng":"39.907292,116.391451","label":"天安門"}}},"idB":{"label":"B","state":1,"bkmrk":{"id158152834156713547":{"guid":"444c732a28f84bdb8a064b3c001b6270.16","latlng":"39.908806,116.391283","label":"午門"},"id15815283543591385":{"guid":"475d107fcc2543cd9ad7261d1cf38af0.12","latlng":"39.910704,116.390889","label":"Beijing Forbidden City China X"}}},"idOthers":{"label":"Others","state":1,"bkmrk":{"id158152834665313659":{"guid":"8a19fe8daf4446c9b29c8e23f6b2968b.16","latlng":"39.908307,116.392352","label":"太庙街门"},"id158152835163513725":{"guid":"b0080aac74154befbc28e77e2fa36a7d.16","latlng":"39.908355,116.392741","label":"太庙石墩阵列"},"id158152835936713957":{"guid":"5a67fcc6758b4cc3bd0e8ef2cc65168a.16","latlng":"39.908117,116.390133","label":"青雲片"},"id158152836253614027":{"guid":"bad4d7e99476494e84e066681e3fc947.12","latlng":"39.908214,116.389438","label":"Sun Yasien Status"}}}}} -------------------------------------------------------------------------------- /src/MultField/mult-result-sample.txt: -------------------------------------------------------------------------------- 1 | Bookmarks JSON: 2 | {"portals":{"idOthers":{"bkmrk":{"0":{"guid":"bad4d7e99476494e84e066681e3fc947.12","label":"Sun Yasien Status","latlng":"39.908214,116.389438"},"1":{"guid":"5a67fcc6758b4cc3bd0e8ef2cc65168a.16","label":"青雲片","latlng":"39.908117,116.390133"},"2":{"guid":"b0080aac74154befbc28e77e2fa36a7d.16","label":"太庙石墩阵列","latlng":"39.908355,116.392741"},"3":{"guid":"8a19fe8daf4446c9b29c8e23f6b2968b.16","label":"太庙街门","latlng":"39.908307,116.392352"}}}}} 3 | 4 | DrawTools JSON: 5 | [{"color":"#0099FF","latLngs":[{"lat":"39.907292","lng":"116.391451"},{"lat":"39.908806","lng":"116.391283"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.907292","lng":"116.391451"},{"lat":"39.908214","lng":"116.389438"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908806","lng":"116.391283"},{"lat":"39.908214","lng":"116.389438"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908214","lng":"116.389438"},{"lat":"39.908117","lng":"116.390133"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.907292","lng":"116.391451"},{"lat":"39.908117","lng":"116.390133"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908806","lng":"116.391283"},{"lat":"39.908117","lng":"116.390133"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.907292","lng":"116.391451"},{"lat":"39.908355","lng":"116.392741"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908806","lng":"116.391283"},{"lat":"39.908355","lng":"116.392741"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908355","lng":"116.392741"},{"lat":"39.908307","lng":"116.392352"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.907292","lng":"116.391451"},{"lat":"39.908307","lng":"116.392352"}],"type":"polyline"},{"color":"#0099FF","latLngs":[{"lat":"39.908806","lng":"116.391283"},{"lat":"39.908307","lng":"116.392352"}],"type":"polyline"}] 6 | 7 | -------------------------------------------------------------------------------- /src/TriField/tri-choose.cpp: -------------------------------------------------------------------------------- 1 | #if defined(__GNUC__) 2 | #pragma GCC diagnostic push 3 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 4 | #elif defined(_MSC_VER) 5 | #pragma warning(disable : 4996) 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define rep(i, l, r) for(int i=l; i<=r; i++) 18 | #define dow(i, l, r) for(int i=l; i>=r; i--) 19 | #define clr(x, c) memset(x, c, sizeof(x)) 20 | #define all(x) (x).begin,(x).end 21 | #define pb push_back 22 | #define pi acos(-1) 23 | 24 | using namespace std; 25 | 26 | typedef pair Pdi; 27 | 28 | #define maxn 409 29 | #define maxs 64000009 30 | 31 | #define CHOOSE 0 32 | 33 | struct node 34 | { 35 | double x, y; 36 | string guid, latlng, label; 37 | } P[1009]; 38 | 39 | int n, tot, Total, lv[maxs], nx[maxs]; 40 | 41 | clock_t gap; 42 | 43 | Json::Value bm, dt; 44 | 45 | inline int min(int a, int b){return a0 && Dir(b,c,d)*Dir(c,a,d)>0; 55 | } 56 | 57 | inline int GetPID(int a, int b, int c){return ((a-1)*n+b-1)*n+c-1;} 58 | 59 | inline void ChangetoPosition(int a) 60 | { 61 | istringstream iss(P[a].latlng); 62 | char tmp; 63 | iss >> P[a].x >> tmp >> P[a].y; 64 | } 65 | 66 | inline void ReadInput(const char *localFileName) // 读入JSON 67 | { 68 | string str, chunk; 69 | 70 | if (localFileName) 71 | { 72 | ifstream fin(localFileName); 73 | if (fin) 74 | while (getline(fin, chunk) && chunk != "") 75 | str += chunk; 76 | else 77 | while (getline(cin, chunk) && chunk != "") 78 | str += chunk; 79 | } 80 | else 81 | while (getline(cin, chunk) && chunk != "") str += chunk; 82 | 83 | Json::Reader reader; 84 | Json::Value input; 85 | reader.parse(str, input); 86 | 87 | Json::Value::Members arrayMember = input["portals"]["idOthers"]["bkmrk"].getMemberNames(); 88 | for(Json::Value::Members::iterator iter = arrayMember.begin(); iter != arrayMember.end(); ++iter) 89 | { 90 | n++; 91 | P[n].guid = input["portals"]["idOthers"]["bkmrk"][*iter]["guid"].asString(); 92 | P[n].latlng = input["portals"]["idOthers"]["bkmrk"][*iter]["latlng"].asString(); 93 | P[n].label = input["portals"]["idOthers"]["bkmrk"][*iter]["label"].asString(); 94 | ChangetoPosition(n); 95 | } 96 | } 97 | 98 | int FieldLevel(int a, int b, int c) 99 | { 100 | int x=GetPID(a,b,c), tmp; 101 | if (lv[x]) return lv[x]; 102 | tot++; lv[x]=0; 103 | rep(i, 1, n) if (i!=a && i!=b && i!=c && inField(a,b,c,i) && (tmp=FieldLevel(b,c,i))>lv[x]) 104 | lv[x]=tmp, nx[x]=i; 105 | if ((double)(clock()-gap)/CLOCKS_PER_SEC>=0.1) 106 | system("cls"), printf("%.6lf%%", 100.0*tot/Total), gap=clock(); 107 | return ++lv[x]; 108 | } 109 | 110 | inline string D_toString(double a) 111 | { 112 | char buffer[20]; 113 | sprintf(buffer, "%f", a); 114 | return buffer; 115 | } 116 | 117 | inline string I_toString(int a) 118 | { 119 | char buffer[20]; 120 | sprintf(buffer, "%d", a); 121 | return buffer; 122 | } 123 | 124 | /* inline void AddField(int a, int b, int c) 125 | { 126 | dt[tot]["color"] = "#0099FF"; 127 | 128 | dt[tot]["latLngs"][0]["lat"] = D_toString(P[a].x); 129 | dt[tot]["latLngs"][0]["lng"] = D_toString(P[a].y); 130 | dt[tot]["latLngs"][1]["lat"] = D_toString(P[b].x); 131 | dt[tot]["latLngs"][1]["lng"] = D_toString(P[b].y); 132 | dt[tot]["latLngs"][2]["lat"] = D_toString(P[c].x); 133 | dt[tot]["latLngs"][2]["lng"] = D_toString(P[c].y); 134 | 135 | dt[tot]["type"] = "polygon"; 136 | 137 | tot++; 138 | } */ 139 | 140 | inline void AddField(int a, int b, int c) 141 | { 142 | dt[tot]["color"] = "#0099FF"; 143 | 144 | dt[tot]["latLngs"][0]["lat"] = D_toString(P[a].x); 145 | dt[tot]["latLngs"][0]["lng"] = D_toString(P[a].y); 146 | dt[tot]["latLngs"][1]["lat"] = D_toString(P[b].x); 147 | dt[tot]["latLngs"][1]["lng"] = D_toString(P[b].y); 148 | dt[tot]["latLngs"][2]["lat"] = D_toString(P[c].x); 149 | dt[tot]["latLngs"][2]["lng"] = D_toString(P[c].y); 150 | dt[tot]["latLngs"][3]["lat"] = D_toString(P[a].x); 151 | dt[tot]["latLngs"][3]["lng"] = D_toString(P[a].y); 152 | 153 | dt[tot]["type"] = "polyline"; 154 | 155 | tot++; 156 | } 157 | 158 | inline void AddPortal(int a, int dir) 159 | { 160 | string tmp="A", tmp2=I_toString(rand()*rand()); tmp[0]+=dir; 161 | bm["portals"][tmp]["bkmrk"][tmp2]["guid"] = P[a].guid; 162 | bm["portals"][tmp]["bkmrk"][tmp2]["latlng"] = P[a].latlng; 163 | bm["portals"][tmp]["bkmrk"][tmp2]["label"] = P[a].label; 164 | } 165 | 166 | void OutputPlan(int a, int b, int c, int dir) 167 | { 168 | int x=GetPID(a,b,c); 169 | 170 | AddPortal(a,dir), AddField(a,b,c); 171 | 172 | if (lv[x]==1) 173 | AddPortal(b,(dir+1)%3), AddPortal(c,(dir+2)%3); 174 | else 175 | OutputPlan(b,c,nx[x],(dir+1)%3); 176 | } 177 | 178 | inline void OutputResult(int a, int b, int c) 179 | { 180 | freopen("tri-result.txt", "w", stdout); 181 | 182 | string tmp1="A", tmp2="Group 0"; 183 | rep(i, 1, 3) 184 | { 185 | tmp1[0]='A'+i-1, tmp2[6]='0'+i; 186 | bm["portals"][tmp1]["label"]=tmp2; 187 | bm["portals"][tmp1]["state"]=0; 188 | } 189 | 190 | tot=0; OutputPlan(a,b,c,0); 191 | 192 | Json::FastWriter writer; 193 | puts("Bookmarks JSON:"); cout << writer.write(bm) << endl; 194 | puts("DrawTools JSON:"); cout << writer.write(dt) << endl; 195 | 196 | printf("可能搞混的重复 Po 名:\n"); 197 | rep(i, 1, n) rep(j, i+1, n) if (P[i].label == P[j].label) cout << P[i].label << endl; 198 | 199 | fclose(stdout); 200 | } 201 | 202 | int main() 203 | { 204 | ReadInput("portal.txt"); srand(time(NULL)); 205 | 206 | Total=n*(n-1)*(n-2); 207 | 208 | printf("总点数:%d\n倒数第二个 Portal:", n); cout << P[n-1].label << endl; 209 | getchar(); system("cls"); 210 | 211 | if (n>400) 212 | { 213 | puts("点数过多,请删减。"); 214 | getchar(); return 0; 215 | } 216 | 217 | int Pa, Pb, Pc, mx=0; 218 | 219 | gap=clock(); tot=0; 220 | rep(i, 1, n) rep(j, 1, n) if (i!=j) rep(k, 1, n) if (k!=i && k!=j) if (mx} Assoiciative array of portal information keyed by the portal's guid. 53 | * @external "window.portals" 54 | * @see {@link https://iitc.me/ Ingress Intel Total Conversion} 55 | */ 56 | /** 57 | * The map data render class which handles rendering into Leaflet the JSON data from the servers. Needed to access 58 | * `window.Render.prototype.bringPortalsToFront`. 59 | * @external "window.Render" 60 | * @see {@link https://iitc.me/ Ingress Intel Total Conversion} 61 | */ 62 | /** 63 | * The "show list of portals" plugin object, properties, and methods. 64 | * @external "window.plugin.portalslist" 65 | * @see {@link http://leafletjs.com/ "show list of portals"} plugin source code for further information. 66 | */ 67 | 68 | /** 69 | * Required Plugins helper. 70 | * @module {function} "window.helper.requiredPlugins" 71 | */ 72 | ;(function () { 73 | "use strict"; 74 | /** 75 | * Information about a plugin. The `pluginKey` is the property name of the 76 | * plugin in the `window.plugin` associative array. The `name` value is used 77 | * in messaging about the plugins (e.g., if it is missing). 78 | * @typedef PluginMetaData 79 | * @type {Object} 80 | * @property {String} pluginKey The property name of the plugin in 81 | * `window.plugin`. 82 | * @property {String} name A title or short name of the plugin. 83 | * @example 84 | * { 85 | * pluginKey: "drawTools", 86 | * name: "draw tools" 87 | * } 88 | */ 89 | // Aggregate helpers in the window.helper object 90 | if (typeof window.helper !== "object") { 91 | window.helper = {}; 92 | } 93 | window.helper.requiredPlugins = {}; 94 | /** 95 | * Required Plugins namespace. 96 | * @alias "window.helper.requiredPlugins" 97 | * @variation 2 98 | */ 99 | var self = window.helper.requiredPlugins; 100 | self.spacename = "helper.requiredPlugins"; 101 | self.version = "0.1.0"; 102 | 103 | /** 104 | * Returns true if all the prerequisite plugins are installed. 105 | * @param {PluginMetaData[]} prerequisites An array of 106 | * `RequiredPluginMetaData`. 107 | * @returns {boolean} Returns `true` if all the prerequisite plugins are 108 | * installed; otherwise, returns `false`. 109 | * @example 110 | * window.plugin.myPlugin.requiredPlugins = [{ 111 | * pluginKey: window.plugin.drawTools, 112 | * name: "draw tools" 113 | * }, { 114 | * pluginKey: window.plugin.myotherplugin, 115 | * name: "My Other Plugin" 116 | * }] 117 | * ... 118 | * if (window.helper.requiredPlugins.areMissing(window.plugin.myPlugin.requiredPlugins)) { 119 | * return; 120 | * } 121 | */ 122 | self.areMissing = function (prerequisites) { 123 | var areMissing; 124 | areMissing = prerequisites.some(function (metadata) { 125 | return (typeof window.plugin[metadata.pluginKey] === "undefined"); 126 | }); 127 | return areMissing; 128 | }; 129 | 130 | /** 131 | * Checks if the prerequisite/required plugins are installed. 132 | * @param {PluginMetaData[]} requiredPlugins An array of plugin meta-data on 133 | * the required plugins. 134 | * @returns {PluginMetaData[]} 135 | * @example 136 | * window.plugin.myPlugin.requiredPlugins = [{ 137 | * pluginKey: window.plugin.drawTools, 138 | * name: "draw tools" 139 | * }, { 140 | * pluginKey: window.plugin.myotherplugin, 141 | * name: "My Other Plugin" 142 | * }] 143 | * ... 144 | * var missing = window.helper.requiredPlugins.missingPluginNames(window.plugin.myPlugin.requiredPlugins); 145 | * if (missing.length > 0) { 146 | * msg = 'IITC plugin "' + pluginName + '" requires IITC plugin' + ((missing.length === 1) ? ' ' : 's ') + 147 | * ((missing.length === 1) ? missing[0] : (missing.slice(0,-1).join(", ") + " and " + missing[missing.length - 1])) + '.'; 148 | * console.warn(msg); 149 | * alert(msg); 150 | * } 151 | */ 152 | self.missingPluginNames = function (requiredPlugins) { 153 | var missing = []; 154 | requiredPlugins.forEach(function (metadata) { 155 | if (metadata.pluginKey === undefined) { 156 | missing.push('"' + metadata.name + '"'); 157 | } 158 | }); 159 | return missing; 160 | }; 161 | 162 | /** 163 | * Checks if the pre-requisite plugins are installed. If one or more requisites are not installed, an alert is 164 | * displayed. 165 | * @param {RequiredPluginMetaData[]} requiredPlugins An array of plugin meta-data on the required plugins. 166 | * @param {string} pluginName The name of the plugin requiring the required plugins. Recommend using 167 | * `plugin_info.script.name`. 168 | * @returns {boolean} 169 | * @example 170 | * window.plugin.myPlugin.requiredPlugins = [{ 171 | * pluginKey: window.plugin.drawTools, 172 | * name: "draw tools" 173 | * }, { 174 | * pluginKey: window.plugin.myotherplugin, 175 | * name: "My Other Plugin" 176 | * }] 177 | * ... 178 | * if (!window.helper.requiredPlugins.alertIfNotInstalled(window.plugin.myPlugin.requiredPlugins, plugin_info.script.name) { 179 | * return; 180 | * } 181 | */ 182 | self.alertIfNotInstalled = function (requiredPlugins, pluginName) { 183 | var missing = [], 184 | msg; 185 | missing = self.missingPluginNames(requiredPlugins); 186 | if (missing.length > 0) { 187 | msg = 'IITC plugin "' + pluginName + '" requires IITC plugin' + ((missing.length === 1) ? ' ' : 's ') + 188 | ((missing.length === 1) ? missing[0] : (missing.slice(0, -1).join(", ") + " and " + missing[missing.length - 1])) + '.'; 189 | window.console.warn(msg); 190 | alert(msg); 191 | } 192 | return (missing.length === 0); 193 | }; 194 | }()); 195 | 196 | /** 197 | * Toolbox Control Section helper. 198 | * @module {function} "window.helper.ToolboxControlSection" 199 | */ 200 | ;(function () { 201 | "use strict"; 202 | // Aggregate helpers in the window.helper object 203 | if (typeof window.helper !== "object") { 204 | window.helper = {}; 205 | } 206 | 207 | /** 208 | * ToolboxControlSection Class. Provides a standardized way of adding toolbox controls and grouping controls in 209 | * the same "family". 210 | */ 211 | /** 212 | * Creates a new ToolboxControlSection. 213 | * 214 | * @class 215 | * @param {String|Element|Text|Array|jQuery} content A object suitable for passing to `jQuery.append()`: a 216 | * DOM element, text node, array of elements and text nodes, HTML string, or jQuery object to insert at the end of 217 | * each element in the set of matched elements. 218 | * @param {String} controlSectionClass The class name for a section of controls, typically in a `div` tag. 219 | * @param {String} [controlClass] An optional class name of a simple control or collection of controls. 220 | * @property {String} defaultStyle Global CSS for the toolbox control section. Set 221 | * using `setStyle()`. 222 | * @property {String} style Global CSS for the toolbox control section. Set 223 | * using `setStyle()`. 224 | */ 225 | window.helper.ToolboxControlSection = function (content, controlSectionClass, controlClass) { 226 | this.controlSectionClass = controlSectionClass; 227 | this.controlClass = controlClass; 228 | this.merged = false; 229 | this.jQueryObj = jQuery('
').append(content).addClass(controlSectionClass); 230 | }; 231 | // Properties 232 | var self = window.helper.ToolboxControlSection; 233 | self.version = "0.1.0"; 234 | self.defaultStyle = "div.wise-toolbox-control-section {color:#00C5FF;text-align:center;width:fit-content;border-top: 1px solid #20A8B1;border-bottom: 1px solid #20A8B1;}"; 235 | self.style = undefined; 236 | /** 237 | * See jQuery `.attr()` function. 238 | * 239 | * @returns {String} 240 | * @todo Consider removing this. 241 | */ 242 | self.prototype.attr = function (attributeNameOrAttributes, valueOrFunction) { 243 | if (typeof valueOrFunction === 'undefined') { 244 | return this.jQueryObj.attr(attributeNameOrAttributes); 245 | } else { 246 | return this.jQueryObj.attr(attributeNameOrAttributes, valueOrFunction); 247 | } 248 | }; 249 | 250 | /** 251 | * Appends toolbox controls with the same toolbox control section class and toolbox control class. 252 | *

253 | * Merge 254 | * ``` 255 | *

256 | * ...this control... 257 | *
258 | * ``` 259 | * with 260 | * ``` 261 | *
262 | * ...other control... 263 | *
264 | * ``` 265 | * to get 266 | * ``` 267 | *
268 | * ...this control... 269 | * ...other control... 270 | *
271 | * ``` 272 | */ 273 | self.prototype.mergeWithFamily = function () { 274 | var controlFamily, 275 | that; 276 | if (!this.merged) { 277 | that = this; 278 | controlFamily = jQuery('.' + this.controlSectionClass); 279 | if (controlFamily.length > 0) { 280 | controlFamily.each(function () { 281 | var jQobj = jQuery(this); 282 | jQobj.css("border-style", "none"); 283 | that.jQueryObj.append(jQobj.removeClass(that.controlSectionClass).addClass(that.controlSectionClass + "-moved")); // remove oringal section so any subsequent merges have a single control section to deal with 284 | }); 285 | this.merged = true; 286 | } 287 | if (typeof this.controlClass !== 'undefined') { 288 | controlFamily = jQuery(':not(.' + this.controlSectionClass + ') .' + this.controlClass); 289 | if (controlFamily.length > 0) { 290 | controlFamily.each(function () { 291 | that.jQueryObj.append(jQuery(this)); 292 | }); 293 | this.merged = true; 294 | } 295 | } 296 | } 297 | return this.jQueryObj; 298 | }; 299 | 300 | /** 301 | * Sets the documents's styling. Will not add the style if previously used. 302 | * @param {String} [styling] CSS styles. 303 | */ 304 | self.prototype.setStyle = function (styling) { 305 | if (typeof styling === "undefined") { 306 | styling = self.defaultStyle; 307 | } 308 | if (typeof self.style === 'undefined' || (self.style !== styling)) { 309 | self.style = styling; 310 | jQuery("