{"id":272,"date":"2024-04-27T11:06:28","date_gmt":"2024-04-27T03:06:28","guid":{"rendered":"https:\/\/seanxd.com\/?p=272"},"modified":"2024-04-27T11:06:30","modified_gmt":"2024-04-27T03:06:30","slug":"zerojudge-k632","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-k632\/","title":{"rendered":"ZeroJudge K632: Generating Random Number"},"content":{"rendered":"<p class=\"\">In many cases, we do need to use a program to randomly generate a sequence composed of numbers from 1 to N.<\/p>\n\n\n\n<p class=\"\">For example: randomly sorting students numbered from 1 to N, randomly sorting balloons numbered from 1 to N for testing, and so on.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td>Input a positive integer N (N &lt; 2147483647).<\/td><td class=\"translation-block\">Output a random sequence of numbers from 1 to N, separated by spaces.<\/td><\/tr><tr><td>3<\/td><td>2  1  3<\/td><\/tr><tr><td>5<\/td><td>5 3 2 1 4<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"translation-block\">Since outputting from 1 to N is also a possible random ordering, you can simply use a for loop to output from 1 to N.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=k632\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge K632: Generating Random Number<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap nfd-wb-animate nfd-wb-reveal-right nfd-delay-50\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\nusing namespace std;\n\nint main() {\n    cin.sync_with_stdio(0);\n    cin.tie(0);\n    int N;\n    cin &gt;&gt; N;\n    for (int i = 0; i&lt;N; i++)\n    {\n        cout &lt;&lt; i+1 &lt;&lt; &quot; &quot;;\n    }\n    cout &lt;&lt; &quot;\\n&quot;;\n}\n\n\/\/Z.O.J. K632\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u5728\u5f88\u591a\u60c5\u6cc1\u4e0b\uff0c\u6211\u5011\u78ba\u5be6\u8981\u5229\u7528\u7a0b\u5e8f\u96a8\u6a5f\u7522\u751f\u4e00\u500b\u7531 1\uff5eN \u7684\u7d44\u6210\u7684\u6578\u5217\u3002 \u4f8b\u5982\uff1a\u8981\u5c07\u7de8\u865f\u7531 1\uff5eN \u7684\u5b78\u751f\u96a8\u6a5f\u6392 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[6],"tags":[9],"class_list":["post-272","post","type-post","status-publish","format-standard","hentry","category-6","tag-9"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=272"}],"version-history":[{"count":2,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/272\/revisions"}],"predecessor-version":[{"id":274,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/272\/revisions\/274"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}