diff --git a/.gitignore b/.gitignore index 4b64967..4069360 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ -.vscode .DS_Store +.vscode +*.xlsx diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cbe5ad1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,437 @@ +Attribution-NonCommercial-ShareAlike 4.0 International + +======================================================================= + +Creative Commons Corporation ("Creative Commons") is not a law firm and +does not provide legal services or legal advice. Distribution of +Creative Commons public licenses does not create a lawyer-client or +other relationship. Creative Commons makes its licenses and related +information available on an "as-is" basis. Creative Commons gives no +warranties regarding its licenses, any material licensed under their +terms and conditions, or any related information. Creative Commons +disclaims all liability for damages resulting from their use to the +fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and +conditions that creators and other rights holders may use to share +original works of authorship and other material subject to copyright +and certain other rights specified in the public license below. The +following considerations are for informational purposes only, are not +exhaustive, and do not form part of our licenses. + + Considerations for licensors: Our public licenses are + intended for use by those authorized to give the public + permission to use material in ways otherwise restricted by + copyright and certain other rights. Our licenses are + irrevocable. Licensors should read and understand the terms + and conditions of the license they choose before applying it. + Licensors should also secure all rights necessary before + applying our licenses so that the public can reuse the + material as expected. Licensors should clearly mark any + material not subject to the license. This includes other CC- + licensed material, or material used under an exception or + limitation to copyright. More considerations for licensors: + wiki.creativecommons.org/Considerations_for_licensors + + Considerations for the public: By using one of our public + licenses, a licensor grants the public permission to use the + licensed material under specified terms and conditions. If + the licensor's permission is not necessary for any reason--for + example, because of any applicable exception or limitation to + copyright--then that use is not regulated by the license. Our + licenses grant only permissions under copyright and certain + other rights that a licensor has authority to grant. Use of + the licensed material may still be restricted for other + reasons, including because others have copyright or other + rights in the material. A licensor may make special requests, + such as asking that all changes be marked or described. + Although not required by our licenses, you are encouraged to + respect those requests where reasonable. More considerations + for the public: + wiki.creativecommons.org/Considerations_for_licensees + +======================================================================= + +Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International +Public License + +By exercising the Licensed Rights (defined below), You accept and agree +to be bound by the terms and conditions of this Creative Commons +Attribution-NonCommercial-ShareAlike 4.0 International Public License +("Public License"). To the extent this Public License may be +interpreted as a contract, You are granted the Licensed Rights in +consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the +Licensor receives from making the Licensed Material available under +these terms and conditions. + + +Section 1 -- Definitions. + + a. Adapted Material means material subject to Copyright and Similar + Rights that is derived from or based upon the Licensed Material + and in which the Licensed Material is translated, altered, + arranged, transformed, or otherwise modified in a manner requiring + permission under the Copyright and Similar Rights held by the + Licensor. For purposes of this Public License, where the Licensed + Material is a musical work, performance, or sound recording, + Adapted Material is always produced where the Licensed Material is + synched in timed relation with a moving image. + + b. Adapter's License means the license You apply to Your Copyright + and Similar Rights in Your contributions to Adapted Material in + accordance with the terms and conditions of this Public License. + + c. BY-NC-SA Compatible License means a license listed at + creativecommons.org/compatiblelicenses, approved by Creative + Commons as essentially the equivalent of this Public License. + + d. Copyright and Similar Rights means copyright and/or similar rights + closely related to copyright including, without limitation, + performance, broadcast, sound recording, and Sui Generis Database + Rights, without regard to how the rights are labeled or + categorized. For purposes of this Public License, the rights + specified in Section 2(b)(1)-(2) are not Copyright and Similar + Rights. + + e. Effective Technological Measures means those measures that, in the + absence of proper authority, may not be circumvented under laws + fulfilling obligations under Article 11 of the WIPO Copyright + Treaty adopted on December 20, 1996, and/or similar international + agreements. + + f. Exceptions and Limitations means fair use, fair dealing, and/or + any other exception or limitation to Copyright and Similar Rights + that applies to Your use of the Licensed Material. + + g. License Elements means the license attributes listed in the name + of a Creative Commons Public License. The License Elements of this + Public License are Attribution, NonCommercial, and ShareAlike. + + h. Licensed Material means the artistic or literary work, database, + or other material to which the Licensor applied this Public + License. + + i. Licensed Rights means the rights granted to You subject to the + terms and conditions of this Public License, which are limited to + all Copyright and Similar Rights that apply to Your use of the + Licensed Material and that the Licensor has authority to license. + + j. Licensor means the individual(s) or entity(ies) granting rights + under this Public License. + + k. NonCommercial means not primarily intended for or directed towards + commercial advantage or monetary compensation. For purposes of + this Public License, the exchange of the Licensed Material for + other material subject to Copyright and Similar Rights by digital + file-sharing or similar means is NonCommercial provided there is + no payment of monetary compensation in connection with the + exchange. + + l. Share means to provide material to the public by any means or + process that requires permission under the Licensed Rights, such + as reproduction, public display, public performance, distribution, + dissemination, communication, or importation, and to make material + available to the public including in ways that members of the + public may access the material from a place and at a time + individually chosen by them. + + m. Sui Generis Database Rights means rights other than copyright + resulting from Directive 96/9/EC of the European Parliament and of + the Council of 11 March 1996 on the legal protection of databases, + as amended and/or succeeded, as well as other essentially + equivalent rights anywhere in the world. + + n. You means the individual or entity exercising the Licensed Rights + under this Public License. Your has a corresponding meaning. + + +Section 2 -- Scope. + + a. License grant. + + 1. Subject to the terms and conditions of this Public License, + the Licensor hereby grants You a worldwide, royalty-free, + non-sublicensable, non-exclusive, irrevocable license to + exercise the Licensed Rights in the Licensed Material to: + + a. reproduce and Share the Licensed Material, in whole or + in part, for NonCommercial purposes only; and + + b. produce, reproduce, and Share Adapted Material for + NonCommercial purposes only. + + 2. Exceptions and Limitations. For the avoidance of doubt, where + Exceptions and Limitations apply to Your use, this Public + License does not apply, and You do not need to comply with + its terms and conditions. + + 3. Term. The term of this Public License is specified in Section + 6(a). + + 4. Media and formats; technical modifications allowed. The + Licensor authorizes You to exercise the Licensed Rights in + all media and formats whether now known or hereafter created, + and to make technical modifications necessary to do so. The + Licensor waives and/or agrees not to assert any right or + authority to forbid You from making technical modifications + necessary to exercise the Licensed Rights, including + technical modifications necessary to circumvent Effective + Technological Measures. For purposes of this Public License, + simply making modifications authorized by this Section 2(a) + (4) never produces Adapted Material. + + 5. Downstream recipients. + + a. Offer from the Licensor -- Licensed Material. Every + recipient of the Licensed Material automatically + receives an offer from the Licensor to exercise the + Licensed Rights under the terms and conditions of this + Public License. + + b. Additional offer from the Licensor -- Adapted Material. + Every recipient of Adapted Material from You + automatically receives an offer from the Licensor to + exercise the Licensed Rights in the Adapted Material + under the conditions of the Adapter's License You apply. + + c. No downstream restrictions. You may not offer or impose + any additional or different terms or conditions on, or + apply any Effective Technological Measures to, the + Licensed Material if doing so restricts exercise of the + Licensed Rights by any recipient of the Licensed + Material. + + 6. No endorsement. Nothing in this Public License constitutes or + may be construed as permission to assert or imply that You + are, or that Your use of the Licensed Material is, connected + with, or sponsored, endorsed, or granted official status by, + the Licensor or others designated to receive attribution as + provided in Section 3(a)(1)(A)(i). + + b. Other rights. + + 1. Moral rights, such as the right of integrity, are not + licensed under this Public License, nor are publicity, + privacy, and/or other similar personality rights; however, to + the extent possible, the Licensor waives and/or agrees not to + assert any such rights held by the Licensor to the limited + extent necessary to allow You to exercise the Licensed + Rights, but not otherwise. + + 2. Patent and trademark rights are not licensed under this + Public License. + + 3. To the extent possible, the Licensor waives any right to + collect royalties from You for the exercise of the Licensed + Rights, whether directly or through a collecting society + under any voluntary or waivable statutory or compulsory + licensing scheme. In all other cases the Licensor expressly + reserves any right to collect such royalties, including when + the Licensed Material is used other than for NonCommercial + purposes. + + +Section 3 -- License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the +following conditions. + + a. Attribution. + + 1. If You Share the Licensed Material (including in modified + form), You must: + + a. retain the following if it is supplied by the Licensor + with the Licensed Material: + + i. identification of the creator(s) of the Licensed + Material and any others designated to receive + attribution, in any reasonable manner requested by + the Licensor (including by pseudonym if + designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of + warranties; + + v. a URI or hyperlink to the Licensed Material to the + extent reasonably practicable; + + b. indicate if You modified the Licensed Material and + retain an indication of any previous modifications; and + + c. indicate the Licensed Material is licensed under this + Public License, and include the text of, or the URI or + hyperlink to, this Public License. + + 2. You may satisfy the conditions in Section 3(a)(1) in any + reasonable manner based on the medium, means, and context in + which You Share the Licensed Material. For example, it may be + reasonable to satisfy the conditions by providing a URI or + hyperlink to a resource that includes the required + information. + 3. If requested by the Licensor, You must remove any of the + information required by Section 3(a)(1)(A) to the extent + reasonably practicable. + + b. ShareAlike. + + In addition to the conditions in Section 3(a), if You Share + Adapted Material You produce, the following conditions also apply. + + 1. The Adapter's License You apply must be a Creative Commons + license with the same License Elements, this version or + later, or a BY-NC-SA Compatible License. + + 2. You must include the text of, or the URI or hyperlink to, the + Adapter's License You apply. You may satisfy this condition + in any reasonable manner based on the medium, means, and + context in which You Share Adapted Material. + + 3. You may not offer or impose any additional or different terms + or conditions on, or apply any Effective Technological + Measures to, Adapted Material that restrict exercise of the + rights granted under the Adapter's License You apply. + + +Section 4 -- Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that +apply to Your use of the Licensed Material: + + a. for the avoidance of doubt, Section 2(a)(1) grants You the right + to extract, reuse, reproduce, and Share all or a substantial + portion of the contents of the database for NonCommercial purposes + only; + + b. if You include all or a substantial portion of the database + contents in a database in which You have Sui Generis Database + Rights, then the database in which You have Sui Generis Database + Rights (but not its individual contents) is Adapted Material, + including for purposes of Section 3(b); and + + c. You must comply with the conditions in Section 3(a) if You Share + all or a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not +replace Your obligations under this Public License where the Licensed +Rights include other Copyright and Similar Rights. + + +Section 5 -- Disclaimer of Warranties and Limitation of Liability. + + a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE + EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS + AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF + ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, + IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, + WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR + PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, + ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT + KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT + ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. + + b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE + TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, + NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, + INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, + COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR + USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN + ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR + DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR + IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. + + c. The disclaimer of warranties and limitation of liability provided + above shall be interpreted in a manner that, to the extent + possible, most closely approximates an absolute disclaimer and + waiver of all liability. + + +Section 6 -- Term and Termination. + + a. This Public License applies for the term of the Copyright and + Similar Rights licensed here. However, if You fail to comply with + this Public License, then Your rights under this Public License + terminate automatically. + + b. Where Your right to use the Licensed Material has terminated under + Section 6(a), it reinstates: + + 1. automatically as of the date the violation is cured, provided + it is cured within 30 days of Your discovery of the + violation; or + + 2. upon express reinstatement by the Licensor. + + For the avoidance of doubt, this Section 6(b) does not affect any + right the Licensor may have to seek remedies for Your violations + of this Public License. + + c. For the avoidance of doubt, the Licensor may also offer the + Licensed Material under separate terms or conditions or stop + distributing the Licensed Material at any time; however, doing so + will not terminate this Public License. + + d. Sections 1, 5, 6, 7, and 8 survive termination of this Public + License. + + +Section 7 -- Other Terms and Conditions. + + a. The Licensor shall not be bound by any additional or different + terms or conditions communicated by You unless expressly agreed. + + b. Any arrangements, understandings, or agreements regarding the + Licensed Material not stated herein are separate from and + independent of the terms and conditions of this Public License. + + +Section 8 -- Interpretation. + + a. For the avoidance of doubt, this Public License does not, and + shall not be interpreted to, reduce, limit, restrict, or impose + conditions on any use of the Licensed Material that could lawfully + be made without permission under this Public License. + + b. To the extent possible, if any provision of this Public License is + deemed unenforceable, it shall be automatically reformed to the + minimum extent necessary to make it enforceable. If the provision + cannot be reformed, it shall be severed from this Public License + without affecting the enforceability of the remaining terms and + conditions. + + c. No term or condition of this Public License will be waived and no + failure to comply consented to unless expressly agreed to by the + Licensor. + + d. Nothing in this Public License constitutes or may be interpreted + as a limitation upon, or waiver of, any privileges and immunities + that apply to the Licensor or You, including from the legal + processes of any jurisdiction or authority. + +======================================================================= + +Creative Commons is not a party to its public +licenses. Notwithstanding, Creative Commons may elect to apply one of +its public licenses to material it publishes and in those instances +will be considered the “Licensor.” The text of the Creative Commons +public licenses is dedicated to the public domain under the CC0 Public +Domain Dedication. Except for the limited purpose of indicating that +material is shared under a Creative Commons public license or as +otherwise permitted by the Creative Commons policies published at +creativecommons.org/policies, Creative Commons does not authorize the +use of the trademark "Creative Commons" or any other trademark or logo +of Creative Commons without its prior written consent including, +without limitation, in connection with any unauthorized modifications +to any of its public licenses or any other arrangements, +understandings, or agreements concerning use of licensed material. For +the avoidance of doubt, this paragraph does not form part of the +public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index d379d94..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,173 +0,0 @@ -# Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International - -Creative Commons Corporation (“Creative Commons”) is not a law firm and does not provide legal services or legal advice. Distribution of Creative Commons public licenses does not create a lawyer-client or other relationship. Creative Commons makes its licenses and related information available on an “as-is” basis. Creative Commons gives no warranties regarding its licenses, any material licensed under their terms and conditions, or any related information. Creative Commons disclaims all liability for damages resulting from their use to the fullest extent possible. - -### Using Creative Commons Public Licenses - -Creative Commons public licenses provide a standard set of terms and conditions that creators and other rights holders may use to share original works of authorship and other material subject to copyright and certain other rights specified in the public license below. The following considerations are for informational purposes only, are not exhaustive, and do not form part of our licenses. - -* __Considerations for licensors:__ Our public licenses are intended for use by those authorized to give the public permission to use material in ways otherwise restricted by copyright and certain other rights. Our licenses are irrevocable. Licensors should read and understand the terms and conditions of the license they choose before applying it. Licensors should also secure all rights necessary before applying our licenses so that the public can reuse the material as expected. Licensors should clearly mark any material not subject to the license. This includes other CC-licensed material, or material used under an exception or limitation to copyright. [More considerations for licensors](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensors). - -* __Considerations for the public:__ By using one of our public licenses, a licensor grants the public permission to use the licensed material under specified terms and conditions. If the licensor’s permission is not necessary for any reason–for example, because of any applicable exception or limitation to copyright–then that use is not regulated by the license. Our licenses grant only permissions under copyright and certain other rights that a licensor has authority to grant. Use of the licensed material may still be restricted for other reasons, including because others have copyright or other rights in the material. A licensor may make special requests, such as asking that all changes be marked or described. Although not required by our licenses, you are encouraged to respect those requests where reasonable. [More considerations for the public](http://wiki.creativecommons.org/Considerations_for_licensors_and_licensees#Considerations_for_licensees). - -## Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License - -By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. - -### Section 1 – Definitions. - -a. __Adapted Material__ means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. - -b. __Adapter's License__ means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. - -c. __BY-NC-SA Compatible License__ means a license listed at [creativecommons.org/compatiblelicenses](http://creativecommons.org/compatiblelicenses), approved by Creative Commons as essentially the equivalent of this Public License. - -d. __Copyright and Similar Rights__ means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. - -e. __Effective Technological Measures__ means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. - -f. __Exceptions and Limitations__ means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. - -g. __License Elements__ means the license attributes listed in the name of a Creative Commons Public License. The License Elements of this Public License are Attribution, NonCommercial, and ShareAlike. - -h. __Licensed Material__ means the artistic or literary work, database, or other material to which the Licensor applied this Public License. - -i. __Licensed Rights__ means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. - -j. __Licensor__ means the individual(s) or entity(ies) granting rights under this Public License. - -k. __NonCommercial__ means not primarily intended for or directed towards commercial advantage or monetary compensation. For purposes of this Public License, the exchange of the Licensed Material for other material subject to Copyright and Similar Rights by digital file-sharing or similar means is NonCommercial provided there is no payment of monetary compensation in connection with the exchange. - -l. __Share__ means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. - -m. __Sui Generis Database Rights__ means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. - -n. __You__ means the individual or entity exercising the Licensed Rights under this Public License. __Your__ has a corresponding meaning. - -### Section 2 – Scope. - -a. ___License grant.___ - - 1. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: - - A. reproduce and Share the Licensed Material, in whole or in part, for NonCommercial purposes only; and - - B. produce, reproduce, and Share Adapted Material for NonCommercial purposes only. - - 2. __Exceptions and Limitations.__ For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. - - 3. __Term.__ The term of this Public License is specified in Section 6(a). - - 4. __Media and formats; technical modifications allowed.__ The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. - - 5. __Downstream recipients.__ - - A. __Offer from the Licensor – Licensed Material.__ Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. - - B. __Additional offer from the Licensor – Adapted Material.__ Every recipient of Adapted Material from You automatically receives an offer from the Licensor to exercise the Licensed Rights in the Adapted Material under the conditions of the Adapter’s License You apply. - - C. __No downstream restrictions.__ You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. - - 6. __No endorsement.__ Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). - -b. ___Other rights.___ - - 1. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. - - 2. Patent and trademark rights are not licensed under this Public License. - - 3. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties, including when the Licensed Material is used other than for NonCommercial purposes. - -### Section 3 – License Conditions. - -Your exercise of the Licensed Rights is expressly made subject to the following conditions. - -a. ___Attribution.___ - - 1. If You Share the Licensed Material (including in modified form), You must: - - A. retain the following if it is supplied by the Licensor with the Licensed Material: - - i. identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); - - ii. a copyright notice; - - iii. a notice that refers to this Public License; - - iv. a notice that refers to the disclaimer of warranties; - - v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; - - B. indicate if You modified the Licensed Material and retain an indication of any previous modifications; and - - C. indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. - - 2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. - - 3. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. - -b. ___ShareAlike.___ - -In addition to the conditions in Section 3(a), if You Share Adapted Material You produce, the following conditions also apply. - -1. The Adapter’s License You apply must be a Creative Commons license with the same License Elements, this version or later, or a BY-NC-SA Compatible License. - -2. You must include the text of, or the URI or hyperlink to, the Adapter's License You apply. You may satisfy this condition in any reasonable manner based on the medium, means, and context in which You Share Adapted Material. - -3. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, Adapted Material that restrict exercise of the rights granted under the Adapter's License You apply. - -### Section 4 – Sui Generis Database Rights. - -Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: - -a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database for NonCommercial purposes only; - -b. if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material, including for purposes of Section 3(b); and - -c. You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. - -For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. - -### Section 5 – Disclaimer of Warranties and Limitation of Liability. - -a. __Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You.__ - -b. __To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You.__ - -c. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. - -### Section 6 – Term and Termination. - -a. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. - -b. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: - - 1. automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or - - 2. upon express reinstatement by the Licensor. - - For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. - -c. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. - -d. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. - -### Section 7 – Other Terms and Conditions. - -a. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. - -b. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. - -### Section 8 – Interpretation. - -a. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. - -b. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. - -c. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. - -d. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. - -> Creative Commons is not a party to its public licenses. Notwithstanding, Creative Commons may elect to apply one of its public licenses to material it publishes and in those instances will be considered the “Licensor.” Except for the limited purpose of indicating that material is shared under a Creative Commons public license or as otherwise permitted by the Creative Commons policies published at [creativecommons.org/policies](http://creativecommons.org/policies), Creative Commons does not authorize the use of the trademark “Creative Commons” or any other trademark or logo of Creative Commons without its prior written consent including, without limitation, in connection with any unauthorized modifications to any of its public licenses or any other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. -> -> Creative Commons may be contacted at creativecommons.org diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 395d94c..1163fa5 --- a/README.md +++ b/README.md @@ -1,186 +1,74 @@ -# :book: 图解算法数据结构 +
+
+
+
+
+
+
+
+
+
+
+
+ 《Hello 算法》 —— 动画图解、一键运行的数据结构与算法教程 +
+ +此书旨在引导初学者探索数据结构与算法的知识地图,掌握刷题需要的前置知识与工具库。 + +> [!TIP] +> 建议先读完这本书(概括且全面地了解数据结构与算法),再开始刷题(深入探索各类算法和数据结构)。 + +### 第二步:刷算法题 + +推荐以下 LeetCode 题单: + +1. [Krahets 笔面试精选 88 题](https://leetcode.cn/studyplan/selected-coding-interview/):从“剑指 Offer”和“热题 100”精选出的 88 道高频算法笔试题,适合初学者入门。 +2. [图解算法数据结构](https://leetcode-cn.com/leetbook/detail/illustration-of-algorithm/)([Interview-75](https://leetcode.cn/studyplan/coding-interviews/)):题目更贴近实际应用,相较于“剑指 Offer”难度有所增加。 +3. [LeetCode 热题 100](https://leetcode.cn/studyplan/top-100-liked/):力扣用户最喜爱的 100 道题。 +4. [面试经典 150 题](https://leetcode.cn/studyplan/top-interview-150/):150 道经典面试力扣题。 +5. [LeetCode-75](https://leetcode.cn/studyplan/leetcode-75/):精选 75 道面试核心题目。 + +> [!TIP] +> 第 `1.` `2.` 项的题目分类与《Hello 算法》的章节内容对应,且提供 [@krahets](https://leetcode.cn/u/jyd/) 写的题解,适合作为配套习题。 + +对初学者刷题的一些建议: + +1. 建议每日刷 2~3 题。若能轻松完成,可以尝试增加至 5~8 题。 +2. 刷题的质量比数量更加重要。请确保你真正理解了每个题目的解法及背后的算法原理。 +3. 建议你按照题单目录的顺序做题。如果感觉一道题很难,可以先跳过,后续再攻克。 +4. 题目通常有不止一种解法,请你注意比较和探讨各种方法的特点和适用情况。 +5. 如果你发现自己遗忘了题目解法,不必灰心;我们通常需要复习三次以上,才能真正掌握一个知识点。 +6. 行百里者半九十。坚持至关重要,加油! + +## License + +The texts, code, and images in this repository are licensed under [CC BY-NC-SA-4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/). diff --git a/cpp/include/PrintUtil.hpp b/cpp/include/PrintUtil.hpp deleted file mode 100644 index 34e8b86..0000000 --- a/cpp/include/PrintUtil.hpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * File: PrintUtil.hpp - * Created Time: 2021-12-19 - * Author: Krahets (krahets@163.com) - */ - -#pragma once - -#include 0:
+ if a % 2: rem = (rem * x) % p
+ x = x ** 2 % p
+ a //= 2
+ return rem
+```
+
+**帮助理解:** 根据下表, 初始状态 $rem=1$, $x=3$, $a=19$, $p=1000000007$ ,最后会将 $rem \times (x^a \odot p)$ 化为 $rem \times (x^0 \odot p) = rem \times 1$ 的形式,即 $rem$ 为余数答案。
+
+| $n$ | $rem \times (x^a \odot p)$ | $rem_n=rem_{n-1} \times x_{n-1} \odot p$ | $x_n=x_{n-1}^2 \odot p$ | $a_n=a_{n-1}//2$ |
+| --- | -----------------------------------------: | ---------------------------------------: | -----------------------------: | :--------------: |
+| $1$ | $1 \times (3^{19} \odot p)$ | $1$ | $3$ | $19$ |
+| $2$ | $3 \times (9^{9} \odot p)$ | $3=1\times3\odot p$ | $9=3^2 \odot p$ | $9=19//2$ |
+| $3$ | $27 \times (81^{4} \odot p)$ | $27 = 3 \times 9 \odot p$ | $81=9^2\odot p$ | $4=9//2$ |
+| $4$ | $27 \times (6561^{2} \odot p)$ | $27$ | $6561=81^2 \odot p$ | $2=4//2$ |
+| $5$ | $27 \times (43046721^{1} \odot p)$ | $27$ | $43046721=6561^2 \odot p$ | $1=2//2$ |
+| $6$ | $162261460 \times (175880701^{0} \odot p)$ | $162261460=27 \times 43046721 \odot p$ | $175880701=43046721^2 \odot p$ | $0=1//2$ |
+
+## 代码:
+
+**Python 代码:** 由于语言特性,理论上 Python 中的变量取值范围由系统内存大小决定(无限大),因此在 Python 中其实不用考虑大数越界问题。
+**Java/C++ 代码:** 根据二分法计算原理,至少要保证变量 `x` 和 `rem` 可以正确存储 $1000000007^2$ ,而 $2^{64} > 1000000007^2 > 2^{32}$ ,因此我们选取 `long` 类型。
+
+```Python []
+class Solution:
+ def cuttingBamboo(self, bamboo_len: int) -> int:
+ if bamboo_len <= 3: return bamboo_len - 1
+ a, b, p, x, rem = bamboo_len // 3 - 1, bamboo_len % 3, 1000000007, 3 , 1
+ while a > 0:
+ if a % 2: rem = (rem * x) % p
+ x = x ** 2 % p
+ a //= 2
+ if b == 0: return (rem * 3) % p # = 3^(a+1) % p
+ if b == 1: return (rem * 4) % p # = 3^a * 4 % p
+ return (rem * 6) % p # = 3^(a+1) * 2 % p
+```
+
+```Java []
+class Solution {
+ public int cuttingBamboo(int bamboo_len) {
+ if(bamboo_len <= 3) return bamboo_len - 1;
+ int b = bamboo_len % 3, p = 1000000007;
+ long rem = 1, x = 3;
+ for(int a = bamboo_len / 3 - 1; a > 0; a /= 2) {
+ if(a % 2 == 1) rem = (rem * x) % p;
+ x = (x * x) % p;
+ }
+ if(b == 0) return (int)(rem * 3 % p);
+ if(b == 1) return (int)(rem * 4 % p);
+ return (int)(rem * 6 % p);
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ int cuttingBamboo(int bamboo_len) {
+ if(bamboo_len <= 3) return bamboo_len - 1;
+ int b = bamboo_len % 3, p = 1000000007;
+ long rem = 1, x = 3;
+ for(int a = bamboo_len / 3 - 1; a > 0; a /= 2) {
+ if(a % 2 == 1) rem = (rem * x) % p;
+ x = (x * x) % p;
+ }
+ if(b == 0) return (int)(rem * 3 % p);
+ if(b == 1) return (int)(rem * 4 % p);
+ return (int)(rem * 6 % p);
+ }
+};
+```
+
+```Python []
+# 由于语言特性,Python 可以不考虑大数越界问题
+class Solution:
+ def cuttingBamboo(self, bamboo_len: int) -> int:
+ if bamboo_len <= 3: return bamboo_len - 1
+ a, b, p = bamboo_len // 3, bamboo_len % 3, 1000000007
+ if b == 0: return 3 ** a % p
+ if b == 1: return 3 ** (a - 1) * 4 % p
+ return 3 ** a * 2 % p
+```
+
+### 复杂度分析:
+
+> 以下为 **二分求余法** 的复杂度。
+
+- **时间复杂度 $O(\log N)$ :** 其中 $N=a$ ,二分法为对数级别复杂度,每轮仅有求整、求余、次方运算。
+ - [求整和求余运算](https://stackoverflow.com/questions/35189851/time-complexity-of-modulo-operator-in-python):资料提到不超过机器数的整数可以看作是 $O(1)$ ;
+ - [幂运算](https://stackoverflow.com/questions/32418731/java-math-powa-b-time-complexity):查阅资料,提到浮点取幂为 $O(1)$ 。
+- **空间复杂度 $O(1)$ :** 变量 `a, b, p, x, rem` 使用常数大小额外空间。
diff --git "a/leetbook_ioa/docs/LCR 133. \344\275\215 1 \347\232\204\344\270\252\346\225\260.md" "b/leetbook_ioa/docs/LCR 133. \344\275\215 1 \347\232\204\344\270\252\346\225\260.md"
new file mode 100755
index 0000000..9cb4025
--- /dev/null
+++ "b/leetbook_ioa/docs/LCR 133. \344\275\215 1 \347\232\204\344\270\252\346\225\260.md"
@@ -0,0 +1,126 @@
+## 方法一:逐位判断
+
+根据 **与运算** 定义,设二进制数字 $n$ ,则有:
+
+- 若 $n \& 1 = 0$ ,则 $n$ 二进制 **最右一位** 为 $0$ ;
+- 若 $n \& 1 = 1$ ,则 $n$ 二进制 **最右一位** 为 $1$ 。
+
+根据以上特点,考虑以下 **循环判断** :
+
+1. 判断 $n$ 最右一位是否为 $1$ ,根据结果计数。
+2. 将 $n$ 右移一位(本题要求把数字 $n$ 看作无符号数,因此使用 **无符号右移** 操作)。
+
+### 算法流程:
+
+1. 初始化数量统计变量 $res = 0$ 。
+2. 循环逐位判断: 当 $n = 0$ 时跳出。
+ 1. **`res += n & 1` :** 若 $n \& 1 = 1$ ,则统计数 $res$ 加一。
+ 2. **`n >>= 1` :** 将二进制数字 $n$ 无符号右移一位( Java 中无符号右移为 "$>>>$" ) 。
+3. 返回统计数量 $res$ 。
+
+
+
+### 代码:
+
+```Python []
+class Solution:
+ def hammingWeight(self, n: int) -> int:
+ res = 0
+ while n:
+ res += n & 1
+ n >>= 1
+ return res
+```
+
+```Java []
+public class Solution {
+ public int hammingWeight(int n) {
+ int res = 0;
+ while(n != 0) {
+ res += n & 1;
+ n >>>= 1;
+ }
+ return res;
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ int hammingWeight(uint32_t n) {
+ unsigned int res = 0; // c++ 使用无符号数
+ while(n != 0) {
+ res += n & 1;
+ n >>= 1;
+ }
+ return res;
+ }
+};
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(\log_2 n)$ :** 此算法循环内部仅有 **移位、与、加** 等基本运算,占用 $O(1)$ ;逐位判断需循环 $log_2 n$ 次,其中 $\log_2 n$ 代表数字 $n$ 最高位 $1$ 的所在位数(例如 $\log_2 4 = 2$, $\log_2 16 = 4$)。
+- **空间复杂度 $O(1)$ :** 变量 $res$ 使用常数大小额外空间。
+
+## 方法二:巧用 $n \& (n - 1)$
+
+- **$(n - 1)$ 解析:** 二进制数字 $n$ 最右边的 $1$ 变成 $0$ ,此 $1$ 右边的 $0$ 都变成 $1$ 。
+- **$n \& (n - 1)$ 解析:** 二进制数字 $n$ 最右边的 $1$ 变成 $0$ ,其余不变。
+
+{:align=center width=450}
+
+### 算法流程:
+
+1. 初始化数量统计变量 $res$ 。
+2. 循环消去最右边的 $1$ :当 $n = 0$ 时跳出。
+ 1. **`res += 1` :** 统计变量加 $1$ ;
+ 2. **`n &= n - 1` :** 消去数字 $n$ 最右边的 $1$ 。
+3. 返回统计数量 $res$ 。
+
+
+
+### 代码:
+
+```Python []
+class Solution:
+ def hammingWeight(self, n: int) -> int:
+ res = 0
+ while n:
+ res += 1
+ n &= n - 1
+ return res
+```
+
+```Java []
+public class Solution {
+ public int hammingWeight(int n) {
+ int res = 0;
+ while(n != 0) {
+ res++;
+ n &= n - 1;
+ }
+ return res;
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ int hammingWeight(uint32_t n) {
+ int res = 0;
+ while(n != 0) {
+ res++;
+ n &= n - 1;
+ }
+ return res;
+ }
+};
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(M)$ :** $n \& (n - 1)$ 操作仅有减法和与运算,占用 $O(1)$ ;设 $M$ 为二进制数字 $n$ 中 $1$ 的个数,则需循环 $M$ 次(每轮消去一个 $1$ ),占用 $O(M)$ 。
+- **空间复杂度 $O(1)$ :** 变量 $res$ 使用常数大小额外空间。
diff --git a/leetbook_ioa/docs/LCR 134. Pow(x, n).md b/leetbook_ioa/docs/LCR 134. Pow(x, n).md
new file mode 100755
index 0000000..fef1472
--- /dev/null
+++ b/leetbook_ioa/docs/LCR 134. Pow(x, n).md
@@ -0,0 +1,134 @@
+## 解题思路:
+
+求 $x^n$ 最简单的方法是通过循环将 $n$ 个 $x$ 乘起来,依次求 $x^1, x^2, ..., x^{n-1}, x^n$ ,时间复杂度为 $O(n)$ 。
+**快速幂法** 可将时间复杂度降低至 $O(\log n)$ ,以下从 「分治法」 和 「二进制」 两个角度解析快速幂法。
+
+### 快速幂解析(分治法角度):
+
+> 快速幂实际上是分治思想的一种应用。
+
+**二分推导:** $x^n = x^{n/2} \times x^{n/2} = (x^2)^{n/2}$ ,令 $n/2$ 为整数,则需要分为奇偶两种情况(设向下取整除法符号为 "$//$" ):
+
+$$
+x^n =
+\begin{cases}
+ (x^2)^{n//2} & , n 为偶数 \\
+ x(x^2)^{n//2} & , n 为奇数 \\
+\end{cases}
+$$
+
+> 观察发现,当 $n$ 为奇数时,二分后会多出一项 $x$ 。
+
+**幂结果获取:**
+
+- 根据推导,可通过循环 $x = x^2$ 操作,每次把幂从 $n$ 降至 $n//2$ ,直至将幂降为 $0$ ;
+- 设 $res=1$ ,则初始状态 $x^n = x^n \times res$ 。在循环二分时,每当 $n$ 为奇数时,将多出的一项 $x$ 乘入 $res$ ,则最终可化至 $x^n = x^0 \times res = res$ ,返回 $res$ 即可。
+
+{:align=center width=500}
+
+**转化为位运算:**
+
+- 向下整除 $n // 2$ **等价于** 右移一位 $n >> 1$ ;
+- 取余数 $n \mod 2$ **等价于** 判断二进制最右位 $n \& 1$ ;
+
+### 快速幂解析(二进制角度):
+
+> 利用十进制数字 $n$ 的二进制表示,可对快速幂进行数学化解释。
+
+对于任何十进制正整数 $n$ ,设其二进制为 "$b_m...b_3b_2b_1$"( $b_i$ 为二进制某位值,$i \in [1,m]$ ),则有:
+
+- **二进制转十进制:** $n = 1b_1 + 2b_2 + 4b_3 + ... + 2^{m-1}b_m$ *(即二进制转十进制公式)* ;
+- **幂的二进制展开:** $x^n = x^{1b_1 + 2b_2 + 4b_3 + ... + 2^{m-1}b_m} = x^{1b_1}x^{2b_2}x^{4b_3}...x^{2^{m-1}b_m}$ ;
+
+根据以上推导,可把计算 $x^n$ 转化为解决以下两个问题:
+
+- **计算 $x^1, x^2, x^4, ..., x^{2^{m-1}}$ 的值:** 循环赋值操作 $x = x^2$ 即可;
+- **获取二进制各位 $b_1, b_2, b_3, ..., b_m$ 的值:** 循环执行以下操作即可。
+ 1. **$n \& 1$ (与操作):** 判断 $n$ 二进制最右一位是否为 $1$ ;
+ 2. **$n>>1$ (移位操作):** $n$ 右移一位(可理解为删除最后一位)。
+
+因此,应用以上操作,可在循环中依次计算 $x^{2^{0}b_1}, x^{2^{1}b_2}, ..., x^{2^{m-1}b_m}$ 的值,并将所有 $x^{2^{i-1}b_i}$ 累计相乘即可,其中:
+
+$$
+x^{2^{i-1}b_i}=
+\begin{cases}
+ 1 & , b_i = 0 \\
+ x^{2^{i-1}} & , b_i = 1 \\
+\end{cases}
+$$
+
+{:align=center width=500}
+
+### 算法流程:
+
+1. 当 $x = 0.0$ 时:直接返回 $0.0$ ,以避免后续 $1$ 除以 $0$ 操作报错。**分析:** 数字 $0$ 的正数次幂恒为 $0$ ;$0$ 的 $0$ 次幂和负数次幂没有意义,因此直接返回 $0.0$ 即可。
+2. 初始化 $res = 1$ 。
+3. 当 $n < 0$ 时:把问题转化至 $n \geq 0$ 的范围内,即执行 $x = 1/x$ ,$n = - n$ 。
+4. 循环计算:当 $n = 0$ 时跳出。
+ 1. 当 $n \& 1 = 1$ 时:将当前 $x$ 乘入 $res$ (即 $res *= x$ )。
+ 2. 执行 $x = x^2$ (即 $x *= x$ )。
+ 3. 执行 $n$ 右移一位(即 $n >>= 1$)。
+5. 返回 $res$ 。
+
+## 代码:
+
+Java 中 int32 变量区间 $n \in [-2147483648, 2147483647]$ ,因此当 $n = -2147483648$ 时执行 $n = -n$ 会因越界而赋值出错。解决方法是先将 $n$ 存入 long 变量 $b$ ,后面用 $b$ 操作即可。
+
+```Python []
+class Solution:
+ def myPow(self, x: float, n: int) -> float:
+ if x == 0.0: return 0.0
+ res = 1
+ if n < 0: x, n = 1 / x, -n
+ while n:
+ if n & 1: res *= x
+ x *= x
+ n >>= 1
+ return res
+```
+
+```Java []
+class Solution {
+ public double myPow(double x, int n) {
+ if(x == 0.0f) return 0.0d;
+ long b = n;
+ double res = 1.0;
+ if(b < 0) {
+ x = 1 / x;
+ b = -b;
+ }
+ while(b > 0) {
+ if((b & 1) == 1) res *= x;
+ x *= x;
+ b >>= 1;
+ }
+ return res;
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ double myPow(double x, int n) {
+ if(x == 0.0f) return 0.0;
+ long b = n;
+ double res = 1.0;
+ if(b < 0) {
+ x = 1 / x;
+ b = -b;
+ }
+ while(b > 0) {
+ if((b & 1) == 1) res *= x;
+ x *= x;
+ b >>= 1;
+ }
+ return res;
+ }
+};
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(\log n)$ :** 二分的时间复杂度为对数级别。
+- **空间复杂度 $O(1)$ :** $res$, $b$ 等变量占用常数大小额外空间。
diff --git "a/leetbook_ioa/docs/LCR 135. \346\212\245\346\225\260.md" "b/leetbook_ioa/docs/LCR 135. \346\212\245\346\225\260.md"
new file mode 100755
index 0000000..7ec06f2
--- /dev/null
+++ "b/leetbook_ioa/docs/LCR 135. \346\212\245\346\225\260.md"
@@ -0,0 +1,269 @@
+## 解题思路:
+
+题目要求打印 “从 $1$ 至 $cnt$ 的数字” ,因此需考虑以下两个问题:
+
+1. **最大的 $cnt$ 位数(记为 $end$ )和位数 $cnt$ 的关系:** 例如最大的 $1$ 位数是 $9$ ,最大的 $2$ 位数是 $99$ ,最大的 $3$ 位数是 $999$ 。则可推出公式:
+
+$$
+end = 10^{cnt} - 1
+$$
+
+2. **大数越界问题:** 当 $cnt$ 较大时,$end$ 会超出 $int32$ 整型的取值范围,超出取值范围的数字无法正常存储。但由于本题要求返回 int 类型数组,相当于默认所有数字都在 int32 整型取值范围内,因此不考虑大数越界问题。
+
+因此,只需定义区间 $[1, 10^{cnt} - 1]$ 和步长 $1$ ,通过 $for$ 循环生成结果列表 $res$ 并返回即可。
+
+### 代码:
+
+```Python []
+class Solution:
+ def countNumbers(self, cnt: int) -> List[int]:
+ res = []
+ for i in range(1, 10 ** cnt):
+ res.append(i)
+ return res
+```
+
+```Java []
+class Solution {
+ public int[] countNumbers(int cnt) {
+ int end = (int)Math.pow(10, cnt) - 1;
+ int[] res = new int[end];
+ for(int i = 0; i < end; i++)
+ res[i] = i + 1;
+ return res;
+ }
+}
+```
+
+利用 Python 的语言特性,可以简化代码:先使用 `range()` 方法生成可迭代对象,再使用 `list()` 方法转化为列表并返回即可。
+
+```Python
+class Solution:
+ def countNumbers(self, cnt: int) -> List[int]:
+ return list(range(1, 10 ** cnt))
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(10^{cnt})$ :** 生成长度为 $10^{cnt}$ 的列表需使用 $O(10^{cnt})$ 时间。
+- **空间复杂度 $O(1)$ :** 建立列表需使用 $O(1)$ 大小的额外空间( 列表作为返回结果,不计入额外空间 )。
+
+## 大数打印拓展:
+
+实际上,本题的主要考点是大数越界情况下的打印。需要解决以下三个问题:
+
+**1. 表示大数的变量类型:**
+
+- 无论是 short / int / long ... 任意变量类型,数字的取值范围都是有限的。因此,大数的表示应用字符串 String 类型。
+
+**2. 生成数字的字符串集:**
+
+- 使用 int 类型时,每轮可通过 $+1$ 生成下个数字,而此方法无法应用至 String 类型。并且, String 类型的数字的进位操作效率较低,例如 `"9999"` 至 `"10000"` 需要从个位到千位循环判断,进位 4 次。
+- 观察可知,生成的列表实际上是 $cnt$ 位 $0$ - $9$ 的 **全排列** ,因此可避开进位操作,通过递归生成数字的 String 列表。
+
+**3. 递归生成全排列:**
+
+- 基于分治算法的思想,先固定高位,向低位递归,当个位已被固定时,添加数字的字符串。例如当 $cnt = 2$ 时(数字范围 $1 - 99$ ),固定十位为 $0$ - $9$ ,按顺序依次开启递归,固定个位 $0$ - $9$ ,终止递归并添加数字字符串。
+
+> 下图中的 `n` 对应本题中的 `cnt` 。
+
+{:align=center width=500}
+
+根据以上方法,可初步编写全排列代码:
+
+```Python []
+class Solution:
+ def countNumbers(self, cnt: int) -> [int]:
+ def dfs(x):
+ if x == cnt: # 终止条件:已固定完所有位
+ res.append(''.join(num)) # 拼接 num 并添加至 res 尾部
+ return
+ for i in range(10): # 遍历 0 - 9
+ num[x] = str(i) # 固定第 x 位为 i
+ dfs(x + 1) # 开启固定第 x + 1 位
+
+ num = ['0'] * cnt # 起始数字定义为 cnt 个 0 组成的字符列表
+ res = [] # 数字字符串列表
+ dfs(0) # 开启全排列递归
+ return ','.join(res) # 拼接所有数字字符串,使用逗号隔开,并返回
+```
+
+```Java []
+class Solution {
+ StringBuilder res;
+ int count = 0, cnt;
+ char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+ public String countNumbers(int cnt) {
+ this.cnt = cnt;
+ res = new StringBuilder(); // 数字字符串集
+ num = new char[cnt]; // 定义长度为 cnt 的字符列表
+ dfs(0); // 开启全排列递归
+ res.deleteCharAt(res.length() - 1); // 删除最后多余的逗号
+ return res.toString(); // 转化为字符串并返回
+ }
+ void dfs(int x) {
+ if(x == cnt) { // 终止条件:已固定完所有位
+ res.append(String.valueOf(num) + ","); // 拼接 num 并添加至 res 尾部,使用逗号隔开
+ return;
+ }
+ for(char i : loop) { // 遍历 ‘0‘ - ’9‘
+ num[x] = i; // 固定第 x 位为 i
+ dfs(x + 1); // 开启固定第 x + 1 位
+ }
+ }
+}
+```
+
+在此方法下,各数字字符串被逗号隔开,共同组成长字符串。返回的数字集字符串如下所示:
+
+```yaml
+输入:n = 1
+输出:"0,1,2,3,4,5,6,7,8,9"
+
+输入:n = 2
+输出:"00,01,02,...,10,11,12,...,97,98,99"
+
+输入:n = 3
+输出:"000,001,002,...,100,101,102,...,997,998,999"
+```
+
+观察可知,当前的生成方法仍有以下问题:
+
+1. 诸如 $00, 01, 02, \cdots$ 应显示为 $0, 1, 2, \cdots$ ,即应 **删除高位多余的 $0$** ;
+2. 此方法从 $0$ 开始生成,而题目要求 **列表从 $1$ 开始** ;
+
+以上两个问题的解决方法如下:
+
+**1. 删除高位多余的 $0$ :**
+
+- **字符串左边界定义:** 声明变量 $start$ 规定字符串的左边界,以保证添加的数字字符串 `num[start:]` 中无高位多余的 $0$ 。例如当 $cnt = 2$ 时,$1 - 9$ 时 $start = 1$ ,$10 - 99$ 时 $start = 0$ 。
+
+- **左边界 $start$ 变化规律:** 观察可知,当输出数字的所有位都是 $9$ 时,则下个数字需要向更高位进 $1$ ,此时左边界 $start$ 需要减 $1$ (即高位多余的 $0$ 减少一个)。例如当 $cnt = 3$ (数字范围 $1 - 999$ )时,左边界 $start$ 需要减 $1$ 的情况有: "009" 进位至 "010" , "099" 进位至 "100" 。设数字各位中 $9$ 的数量为 $nine$ ,所有位都为 $9$ 的判断条件可用以下公式表示:
+
+$$
+cnt - start = nine
+$$
+
+- **统计 $nine$ 的方法:** 固定第 $x$ 位时,当 $i = 9$ 则执行 $nine = nine + 1$ ,并在回溯前恢复 $nine = nine - 1$ 。
+
+**2. 列表从 $1$ 开始:**
+
+- 在以上方法的基础上,添加数字字符串前判断其是否为 `"0"` ,若为 `"0"` 则直接跳过。
+
+
+
+### 代码:
+
+为 **正确表示大数** ,以下代码的返回值为数字字符串集拼接而成的长字符串。
+
+```Python []
+class Solution:
+ def countNumbers(self, cnt: int) -> [int]:
+ def dfs(x):
+ if x == cnt:
+ s = ''.join(num[self.start:])
+ if s != '0': res.append(s)
+ if cnt - self.start == self.nine: self.start -= 1
+ return
+ for i in range(10):
+ if i == 9: self.nine += 1
+ num[x] = str(i)
+ dfs(x + 1)
+ self.nine -= 1
+
+ num, res = ['0'] * cnt, []
+ self.nine = 0
+ self.start = cnt - 1
+ dfs(0)
+ return ','.join(res)
+```
+
+```Java []
+class Solution {
+ StringBuilder res;
+ int nine = 0, count = 0, start, cnt;
+ char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+ public String countNumbers(int cnt) {
+ this.cnt = cnt;
+ res = new StringBuilder();
+ num = new char[cnt];
+ start = cnt - 1;
+ dfs(0);
+ res.deleteCharAt(res.length() - 1);
+ return res.toString();
+ }
+ void dfs(int x) {
+ if(x == cnt) {
+ String s = String.valueOf(num).substring(start);
+ if(!s.equals("0")) res.append(s + ",");
+ if(cnt - start == nine) start--;
+ return;
+ }
+ for(char i : loop) {
+ if(i == '9') nine++;
+ num[x] = i;
+ dfs(x + 1);
+ }
+ nine--;
+ }
+}
+```
+
+本题要求输出 int 类型数组。为 **运行通过** ,可在添加数字字符串 $s$ 前,将其转化为 int 类型。代码如下所示:
+
+```Python []
+class Solution:
+ def countNumbers(self, cnt: int) -> [int]:
+ def dfs(x):
+ if x == cnt:
+ s = ''.join(num[self.start:])
+ if s != '0': res.append(int(s))
+ if cnt - self.start == self.nine: self.start -= 1
+ return
+ for i in range(10):
+ if i == 9: self.nine += 1
+ num[x] = str(i)
+ dfs(x + 1)
+ self.nine -= 1
+
+ num, res = ['0'] * cnt, []
+ self.nine = 0
+ self.start = cnt - 1
+ dfs(0)
+ return res
+```
+
+```Java []
+class Solution {
+ int[] res;
+ int nine = 0, count = 0, start, cnt;
+ char[] num, loop = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
+ public int[] countNumbers(int cnt) {
+ this.cnt = cnt;
+ res = new int[(int)Math.pow(10, cnt) - 1];
+ num = new char[cnt];
+ start = cnt - 1;
+ dfs(0);
+ return res;
+ }
+ void dfs(int x) {
+ if(x == cnt) {
+ String s = String.valueOf(num).substring(start);
+ if(!s.equals("0")) res[count++] = Integer.parseInt(s);
+ if(cnt - start == nine) start--;
+ return;
+ }
+ for(char i : loop) {
+ if(i == '9') nine++;
+ num[x] = i;
+ dfs(x + 1);
+ }
+ nine--;
+ }
+}
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(10^{cnt})$ :** 递归的生成的排列的数量为 $10^{cnt}$ 。
+- **空间复杂度 $O(10^{cnt})$ :** 结果列表 $res$ 的长度为 $10^{cnt} - 1$ ,各数字字符串的长度区间为 $1, 2, ..., cnt$ ,因此占用 $O(10^{cnt})$ 大小的额外空间。
diff --git "a/leetbook_ioa/docs/LCR 136. \345\210\240\351\231\244\351\223\276\350\241\250\350\212\202\347\202\271.md" "b/leetbook_ioa/docs/LCR 136. \345\210\240\351\231\244\351\223\276\350\241\250\350\212\202\347\202\271.md"
new file mode 100755
index 0000000..d271763
--- /dev/null
+++ "b/leetbook_ioa/docs/LCR 136. \345\210\240\351\231\244\351\223\276\350\241\250\350\212\202\347\202\271.md"
@@ -0,0 +1,69 @@
+## 解题思路:
+
+本题删除值为 `val` 的节点分需为两步:定位节点、修改引用。
+
+1. **定位节点:** 遍历链表,直到 `head.val == val` 时跳出,即可定位目标节点。
+2. **修改引用:** 设节点 `cur` 的前驱节点为 `pre` ,后继节点为 `cur.next` ;则执行 `pre.next = cur.next` ,即可实现删除 `cur` 节点。
+
+{:align=center width=450}
+
+### 算法流程:
+
+1. **特例处理:** 当应删除头节点 `head` 时,直接返回 `head.next` 即可。
+2. **初始化:** `pre = head` , `cur = head.next` 。
+3. **定位节点:** 当 `cur` 为空 **或** `cur` 节点值等于 `val` 时跳出。
+ 1. 保存当前节点索引,即 `pre = cur` 。
+ 2. 遍历下一节点,即 `cur = cur.next` 。
+4. **删除节点:** 若 `cur` 指向某节点,则执行 `pre.next = cur.next` ;若 `cur` 指向 $\text{null}$ ,代表链表中不包含值为 `val` 的节点。
+5. **返回值:** 返回链表头部节点 `head` 即可。
+
+
+
+## 代码:
+
+```Python []
+class Solution:
+ def deleteNode(self, head: ListNode, val: int) -> ListNode:
+ if head.val == val: return head.next
+ pre, cur = head, head.next
+ while cur and cur.val != val:
+ pre, cur = cur, cur.next
+ if cur: pre.next = cur.next
+ return head
+```
+
+```Java []
+class Solution {
+ public ListNode deleteNode(ListNode head, int val) {
+ if(head.val == val) return head.next;
+ ListNode pre = head, cur = head.next;
+ while(cur != null && cur.val != val) {
+ pre = cur;
+ cur = cur.next;
+ }
+ if(cur != null) pre.next = cur.next;
+ return head;
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ ListNode* deleteNode(ListNode* head, int val) {
+ if(head->val == val) return head->next;
+ ListNode *pre = head, *cur = head->next;
+ while(cur != nullptr && cur->val != val) {
+ pre = cur;
+ cur = cur->next;
+ }
+ if(cur != nullptr) pre->next = cur->next;
+ return head;
+ }
+};
+```
+
+### 复杂度分析:
+
+- **时间复杂度 $O(N)$ :** $N$ 为链表长度,删除操作平均需循环 $N/2$ 次,最差 $N$ 次。
+- **空间复杂度 $O(1)$ :** `cur`, `pre` 占用常数大小额外空间。
diff --git "a/leetbook_ioa/docs/LCR 137. \346\250\241\347\263\212\346\220\234\347\264\242\351\252\214\350\257\201.md" "b/leetbook_ioa/docs/LCR 137. \346\250\241\347\263\212\346\220\234\347\264\242\351\252\214\350\257\201.md"
new file mode 100755
index 0000000..134cad1
--- /dev/null
+++ "b/leetbook_ioa/docs/LCR 137. \346\250\241\347\263\212\346\220\234\347\264\242\351\252\214\350\257\201.md"
@@ -0,0 +1,185 @@
+## 解题思路:
+
+> 设 $s$ 的长度为 $n$ ,$p$ 的长度为 $m$ ;将 $s$ 的第 $i$ 个字符记为 $s_i$ ,$p$ 的第 $j$ 个字符记为 $p_j$ ,将 $s$ 的前 $i$ 个字符组成的子字符串记为 $s[:i]$ , 同理将 $p$ 的前 $j$ 个字符组成的子字符串记为 $p[:j]$ 。
+>
+> 因此,本题可转化为求 $s[:n]$ 是否能和 $p[:m]$ 匹配。
+
+总体思路是从 $s[:1]$ 和 $p[:1]$ 是否能匹配开始判断,每轮添加一个字符并判断是否能匹配,直至添加完整个字符串 $s$ 和 $p$ 。展开来看,假设 $s[:i]$ 与 $p[:j]$ 可以匹配,那么下一状态有两种:
+
+1. 添加一个字符 $s_{i+1}$ 后是否能匹配?
+2. 添加字符 $p_{j+1}$ 后是否能匹配?
+
+{:align=center width=500}
+
+因此,本题的状态共有 $m \times n$ 种,应定义状态矩阵 $dp$ ,$dp[i][j]$ 代表 $s[:i]$ 与 $p[:j]$ 是否可以匹配。
+
+做好状态定义,接下来就是根据 「`普通字符`」 , 「`.`」 , 「`*`」三种字符的功能定义,分析出动态规划的转移方程。
+
+### 动态规划解析:
+
+**状态定义:** 设动态规划矩阵 `dp` ,`dp[i][j]` 代表字符串 `s` 的前 `i` 个字符和 `p` 的前 `j` 个字符能否匹配。
+
+**转移方程:** 需要注意,由于 `dp[0][0]` 代表的是空字符的状态, 因此 `dp[i][j]` 对应的添加字符是 `s[i - 1]` 和 `p[j - 1]` 。
+
+- 当 `p[j - 1] = '*'` 时,`dp[i][j]` 在当以下任一情况为 $\text{true}$ 时等于 $\text{true}$ :
+
+ 1. **`dp[i][j - 2]`:** 即将字符组合 `p[j - 2] *` 看作出现 0 次时,能否匹配;
+ 2. **`dp[i - 1][j]` 且 `s[i - 1] = p[j - 2]`:** 即让字符 `p[j - 2]` 多出现 1 次时,能否匹配;
+ 3. **`dp[i - 1][j]` 且 `p[j - 2] = '.'`:** 即让字符 `'.'` 多出现 1 次时,能否匹配;
+
+- 当 `p[j - 1] != '*'` 时,`dp[i][j]` 在当以下任一情况为 $\text{true}$ 时等于 $\text{true}$ :
+
+ 1. **`dp[i - 1][j - 1]` 且 `s[i - 1] = p[j - 1]`:** 即让字符 `p[j - 1]` 多出现一次时,能否匹配;
+ 2. **`dp[i - 1][j - 1]` 且 `p[j - 1] = '.'`:** 即将字符 `.` 看作字符 `s[i - 1]` 时,能否匹配;
+
+**初始化:** 需要先初始化 `dp` 矩阵首行,以避免状态转移时索引越界。
+
+- **`dp[0][0] = true`:** 代表两个空字符串能够匹配。
+- **`dp[0][j] = dp[0][j - 2]` 且 `p[j - 1] = '*'`:** 首行 `s` 为空字符串,因此当 `p` 的偶数位为 `*` 时才能够匹配(即让 `p` 的奇数位出现 0 次,保持 `p` 是空字符串)。因此,循环遍历字符串 `p` ,步长为 2(即只看偶数位)。
+
+**返回值:** `dp` 矩阵右下角字符,代表字符串 `s` 和 `p` 能否匹配。
+
+
+
+## 代码:
+
+```Python []
+class Solution:
+ def articleMatch(self, s: str, p: str) -> bool:
+ m, n = len(s) + 1, len(p) + 1
+ dp = [[False] * n for _ in range(m)]
+ dp[0][0] = True
+ for j in range(2, n, 2):
+ dp[0][j] = dp[0][j - 2] and p[j - 1] == '*'
+ for i in range(1, m):
+ for j in range(1, n):
+ dp[i][j] = dp[i][j - 2] or dp[i - 1][j] and (s[i - 1] == p[j - 2] or p[j - 2] == '.') \
+ if p[j - 1] == '*' else \
+ dp[i - 1][j - 1] and (p[j - 1] == '.' or s[i - 1] == p[j - 1])
+ return dp[-1][-1]
+```
+
+```Java []
+class Solution {
+ public boolean articleMatch(String s, String p) {
+ int m = s.length() + 1, n = p.length() + 1;
+ boolean[][] dp = new boolean[m][n];
+ dp[0][0] = true;
+ for(int j = 2; j < n; j += 2)
+ dp[0][j] = dp[0][j - 2] && p.charAt(j - 1) == '*';
+ for(int i = 1; i < m; i++) {
+ for(int j = 1; j < n; j++) {
+ dp[i][j] = p.charAt(j - 1) == '*' ?
+ dp[i][j - 2] || dp[i - 1][j] && (s.charAt(i - 1) == p.charAt(j - 2) || p.charAt(j - 2) == '.') :
+ dp[i - 1][j - 1] && (p.charAt(j - 1) == '.' || s.charAt(i - 1) == p.charAt(j - 1));
+ }
+ }
+ return dp[m - 1][n - 1];
+ }
+}
+```
+
+```C++ []
+class Solution {
+public:
+ bool articleMatch(string s, string p) {
+ int m = s.size() + 1, n = p.size() + 1;
+ vector