{"id":27,"date":"2025-11-28T18:14:24","date_gmt":"2025-11-28T10:14:24","guid":{"rendered":"https:\/\/www.yun-games.com\/?p=27"},"modified":"2025-11-28T18:15:08","modified_gmt":"2025-11-28T10:15:08","slug":"%e5%af%b9%e4%b8%80%e4%b8%aa%e6%95%b0%e6%88%96%e8%80%85%e8%a1%a8%e8%be%be%e5%bc%8f%e5%ae%9e%e7%8e%b0%e5%90%91%e4%b8%8a%e6%95%b4%e9%99%a4","status":"publish","type":"post","link":"https:\/\/www.yun-games.com\/?p=27","title":{"rendered":"\u5bf9\u4e00\u4e2a\u6570\u6216\u8005\u8868\u8fbe\u5f0f\u5b9e\u73b0\u5411\u4e0a\u6574\u9664"},"content":{"rendered":"\n<div style=\"max-width:800px;margin:0 auto;font-family:serif;line-height:1.8\">\n\n<h2>\u5bfc\u8bed<\/h2>\n<p>\u201c\u5411\u4e0a\u53d6\u6574\u201d\u662f\u7f16\u7a0b\u4e2d\u6700\u5e38\u7528\u7684\u5c0f\u64cd\u4f5c\u4e4b\u4e00\uff0c\u4f46 C \u6807\u51c6\u5e93\u5e76\u6ca1\u6709\u7ed9\u6574\u6570\u7248\u672c\u5f00\u7bb1\u5373\u7528\u7684\u63a5\u53e3\u3002\u672c\u6587\u603b\u7ed3\u51e0\u79cd\u96f6\u4f9d\u8d56\u3001\u53ef\u5d4c\u5165\u7684\u5199\u6cd5\uff0c\u5e76\u6307\u51fa\u6d6e\u70b9\u573a\u666f\u7684\u6b63\u786e\u6253\u5f00\u65b9\u5f0f\u3002<\/p>\n\n<h2>\u4e00\u3001\u9700\u6c42\u573a\u666f<\/h2>\n<ul>\n<li>\u5206\u9875\u8ba1\u7b97\uff1a\u603b\u8bb0\u5f55\u6570 n\uff0c\u6bcf\u9875 m \u6761\uff0c\u9700\u8981\u591a\u5c11\u9875\uff1f<\/li>\n<li>\u5185\u5b58\u5bf9\u9f50\uff1a\u7533\u8bf7 n \u5b57\u8282\uff0c\u6309 m \u5b57\u8282\u5bf9\u9f50\uff0c\u81f3\u5c11\u5206\u914d\u591a\u5c11\uff1f<\/li>\n<li>\u4efb\u52a1\u6253\u5305\uff1an \u4e2a\u4efb\u52a1\uff0c\u6bcf\u6279\u5904\u7406 m \u4e2a\uff0c\u9700\u8981\u591a\u5c11\u6279\uff1f<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u95ee\u9898\u672c\u8d28\u90fd\u662f\u300cn \u00f7 m \u5411\u4e0a\u53d6\u6574\u300d\u3002<\/p>\n\n<h2>\u4e8c\u3001\u6574\u6570\u5411\u4e0a\u53d6\u6574\uff1a\u4e00\u53e5\u4ee3\u7801\u5c31\u591f<\/h2>\n<pre><code>int ceildiv(int n, int m)\n{\n    return (n + m - 1) \/ m;   \/* m > 0 \u65f6\u6210\u7acb *\/\n}<\/code><\/pre>\n<p><strong>\u539f\u7406<\/strong>\uff1a\u5148\u628a\u4f59\u6570\u201c\u8865\u6ee1\u201d\u5230 m-1\uff0c\u518d\u6574\u9664 m\uff0c\u76f8\u5f53\u4e8e\u8fdb\u4e00\u4f4d\u3002<\/p>\n<p><strong>\u590d\u6742\u5ea6<\/strong>\uff1aO(1)\uff0c\u65e0\u5206\u652f\uff0c\u4e0d\u8c03\u7528\u4efb\u4f55\u5e93\u3002<\/p>\n\n<h2>\u4e09\u3001\u5b8f\u7248\uff1a\u7f16\u8bd1\u671f\u5185\u8054<\/h2>\n<pre><code>#define CEILDIV(n, m) (((n) + (m) - 1) \/ (m))<\/code><\/pre>\n<p>\u6ce8\u610f\uff1am \u4e3a\u8d1f\u6570\u65f6\u9700\u5148\u53d6\u7edd\u5bf9\u503c\u6216\u53e6\u884c\u5904\u7406\u3002<\/p>\n\n<h2>\u56db\u3001\u6d6e\u70b9\u573a\u666f\uff1a\u7528\u6807\u51c6\u5e93 ceil<\/h2>\n<pre><code>#include &lt;math.h&gt;\n\ndouble x = 10.0 \/ 3.0;\ndouble y = ceil(x);   \/* y == 4.0 *\/<\/code><\/pre>\n<p>\u8fd4\u56de\u7c7b\u578b\u4ecd\u662f\u6d6e\u70b9\uff0c\u5982\u9700\u6574\u6570\u518d\u5f3a\u8f6c\uff1a<code>(int)ceil(x)<\/code>\u3002<\/p>\n\n<h2>\u4e94\u3001\u5b8c\u6574\u793a\u4f8b<\/h2>\n<pre><code>#include &lt;stdio.h&gt;\n#include &lt;math.h&gt;\n\n#define CEILDIV(n, m) (((n) + (m) - 1) \/ (m))\n\nint main(void)\n{\n    int n = 10, m = 3;\n    printf(\"integer ceildiv: %d\\n\", CEILDIV(n, m));  \/* 4 *\/\n\n    double x = (double)n \/ m;\n    printf(\"float ceil: %.0f\\n\", ceil(x));           \/* 4 *\/\n    return 0;\n}<\/code><\/pre>\n\n<h2>\u516d\u3001\u5e38\u89c1\u7591\u95ee<\/h2>\n<ol>\n<li><strong>\u4e3a\u4ec0\u4e48\u6807\u51c6\u5e93\u6ca1\u6709\u6574\u6570 ceil\uff1f<\/strong><br>\n\u5386\u53f2\u539f\u56e0\uff1a\u65e9\u671f C \u4e3b\u8981\u9762\u5411\u7cfb\u7edf\/\u5e95\u5c42\uff0c\u6574\u6570\u9664\u6cd5\u5df2\u591f\u7528\uff0c\u4e14\u300c(a+b-1)\/b\u300d\u8db3\u591f\u7b80\u5355\u3002<\/li>\n\n<li><strong>\u4f1a\u6ea2\u51fa\u5417\uff1f<\/strong><br>\n\u5f53 <code>m > 0<\/code> \u4e14 <code>a + m - 1<\/code> \u4e0d\u8d85\u8fc7\u5bf9\u5e94\u7c7b\u578b\u6700\u5927\u503c\u65f6\u5b89\u5168\uff1b\u82e5\u62c5\u5fc3\uff0c\u53ef\u7528\u66f4\u5927\u5bbd\u5ea6\u7c7b\u578b\u6216\u5224\u65ad\u5206\u652f\u3002<\/li>\n\n<li><strong>\u8d1f\u6570\u600e\u4e48\u529e\uff1f<\/strong><br>\n\u82e5 m \u4e3a\u8d1f\uff0c\u5148\u53d6\u7edd\u5bf9\u503c\uff1b\u82e5 a \u4e3a\u8d1f\uff0c\u9700\u5148\u5b9a\u4e49\u201c\u5411\u4e0a\u201d\u8bed\u4e49\uff08\u5411\u96f6\u8fd8\u662f\u5411\u8d1f\u65e0\u7a77\uff09\u3002<\/li>\n<\/ol>\n\n\n\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u5bfc\u8bed \u201c\u5411\u4e0a\u53d6\u6574\u201d\u662f\u7f16\u7a0b\u4e2d\u6700\u5e38\u7528\u7684\u5c0f\u64cd\u4f5c\u4e4b\u4e00\uff0c\u4f46 C \u6807\u51c6\u5e93\u5e76\u6ca1\u6709\u7ed9\u6574\u6570\u7248\u672c\u5f00\u7bb1\u5373\u7528\u7684\u63a5\u53e3\u3002\u672c\u6587\u603b\u7ed3\u51e0\u79cd\u96f6\u4f9d\u8d56 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":2,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"predecessor-version":[{"id":30,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions\/30"}],"wp:attachment":[{"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yun-games.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}