<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>题解 on karahoi&#39;s blog</title>
    <link>https://www.961996.xyz/tags/%E9%A2%98%E8%A7%A3/</link>
    <description>Recent content in 题解 on karahoi&#39;s blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Mon, 13 Sep 2021 16:58:00 +0800</lastBuildDate><atom:link href="https://www.961996.xyz/tags/%E9%A2%98%E8%A7%A3/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>NOIP2012普及组题解</title>
      <link>https://www.961996.xyz/p/noip2012%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</link>
      <pubDate>Mon, 13 Sep 2021 16:58:00 +0800</pubDate>
      
      <guid>https://www.961996.xyz/p/noip2012%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</guid>
      <description>质因数分解 已知正整数n是两个不同的质数的乘积，试求出较大的那个质数。
题解 分解质因数模板题。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; int main() { int n, ans; cin &amp;gt;&amp;gt; n; for (int i = 2; i * i &amp;lt;= n; i++) { while (n % i == 0) { n /= i; ans = i; } } if (n &amp;gt; 1) { ans = n; } cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; endl; } 寻宝 题面 传说很遥远的藏宝楼顶层藏着诱人的宝藏。小明历尽千辛万苦终于找到传说中的这个藏宝楼，藏宝楼的门口竖着一个木板，上面写有几个大字：寻宝说明书。说明书的内容如下：
藏宝楼共有N+1层，最上面一层是顶层，顶层有一个房间里面藏着宝藏。除了顶层外，藏宝楼另有N层，每层M个房间，这M个房间围成一圈并按逆时针方向依次编号为0，…，M-1。其中一些房间有通往上一层的楼梯，每层楼的楼梯设计可能不同。每个房间里有一个指示牌，指示牌上有一个数字x，表示从这个房间开始按逆时针方向选择第x个有楼梯的房间（假定该房间的编号为k），从该房间上楼，上楼后到达上一层的k号房间。比如当前房间的指示牌上写着2，则按逆时针方向开始尝试，找到第2个有楼梯的房间，从该房间上楼。如果当前房间本身就有楼梯通向上层，该房间作为第一个有楼梯的房间。
寻宝说明书的最后用红色大号字体写着：“寻宝须知：帮助你找到每层上楼房间的指示牌上的数字（即每层第一个进入的房间内指示牌上的数字）总和为打开宝箱的密钥”。
请帮助小明算出这个打开宝箱的密钥。
输入 第一行2个整数N和M，之间用一个空格隔开。N表示除了顶层外藏宝楼共N层楼，M表示除顶层外每层楼有M个房间。
接下来N*M行，每行两个整数，之间用一个空格隔开，每行描述一个房间内的情况，其中第(i-1)*M+j行表示第i层j-1号房间的情况（i=1, 2, …, N；j=1, 2, … ,M）。第一个整数表示该房间是否有楼梯通往上一层（0表示没有，1表示有），第二个整数表示指示牌上的数字。注意，从j号房间的楼梯爬到上一层到达的房间一定也是j号房间。</description>
    </item>
    
    <item>
      <title>NOIP2011普及组题解</title>
      <link>https://www.961996.xyz/p/noip2011%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</link>
      <pubDate>Sun, 12 Sep 2021 10:14:44 +0800</pubDate>
      
      <guid>https://www.961996.xyz/p/noip2011%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</guid>
      <description>数字反转 将一个数反转之后输出，不能有前导零。
题解 模拟。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; int n; int main() { cin &amp;gt;&amp;gt; n; int m = 0; int x = (n &amp;lt; 0); n = abs(n); while (n &amp;gt; 0) { m = m * 10 + n % 10; n /= 10; } if (x) { m = -m; } cout &amp;lt;&amp;lt; m &amp;lt;&amp;lt; endl; } 统计单词数 给一个单词和一段文章，输出单词在文章中出现的次数和第一次出现的位置，不区分大小写。
题解 模拟。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; const int N = 1e6+5; string s, p; int main() { getline(cin, s); getline(cin, p); s += &amp;#39; &amp;#39;; p += &amp;#39; &amp;#39;; for (int i = 0; i &amp;lt; s.</description>
    </item>
    
    <item>
      <title>NOIP2010普及组题解</title>
      <link>https://www.961996.xyz/p/noip2010%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</link>
      <pubDate>Sat, 11 Sep 2021 20:20:30 +0800</pubDate>
      
      <guid>https://www.961996.xyz/p/noip2010%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</guid>
      <description>数字统计 统计[L, R]的所有整数中，数字2出现的次数。
题解 经典题，这题数据范围较小，直接暴力。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; int main() { int count = 0, l, r; cin &amp;gt;&amp;gt; l &amp;gt;&amp;gt; r; for (int i = l; i &amp;lt;= r; i++) { int x = i; while(x &amp;gt; 0) { count += (x%10 == 2); x /= 10; } } cout &amp;lt;&amp;lt; count &amp;lt;&amp;lt; endl; } 接水问题 n个学生，m个水龙头按顺序接水，计算总时间。
方法1 模拟，时间复杂度$O(nm)$。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; const int N = 10005; int n, m, a[N], b[N]; int main() { cin &amp;gt;&amp;gt; n &amp;gt;&amp;gt; m; for (int i = 1; i &amp;lt;= n; i++) { scanf(&amp;#34;%d&amp;#34;, &amp;amp;a[i]); } int ans = 0; for (int i = 1; i &amp;lt;= n; i++) { int mn = 1e9, k; for (int j = 1; j &amp;lt;= m; j++) { if (mn &amp;gt; b[j]) { mn = b[j]; k = j; } } if (mn == 0) { b[k] = a[i]; } else { ans += mn; for (int j = 1; j &amp;lt;= m; j++) { b[j] -= mn; } b[k] = a[i]; } } int mx = 0; for (int j = 1; j &amp;lt;= m; j++) { mx = max(mx, b[j]); } ans += mx; cout &amp;lt;&amp;lt; ans &amp;lt;&amp;lt; endl; } 方法2 也可以用优先队列，每次pop最小的出队时间，push当前同学下次出队的时间，时间复杂度到$O(n\log{m})$。</description>
    </item>
    
    <item>
      <title>NOIP2009普及组题解</title>
      <link>https://www.961996.xyz/p/noip2009%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</link>
      <pubDate>Fri, 10 Sep 2021 11:00:44 +0800</pubDate>
      
      <guid>https://www.961996.xyz/p/noip2009%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</guid>
      <description>多项式输出 给一个存了多项式系数的数组，按一定规则输出多项式。
题解 模拟。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; const int N = 105; int n, a[N]; int main() { cin &amp;gt;&amp;gt; n; for (int i = n; i &amp;gt;= 0; i--) cin &amp;gt;&amp;gt; a[i]; for (int i = n; i &amp;gt;= 0; i--) { if (a[i] == 0) { continue; } if (a[i] &amp;gt; 0) { if(i != n) { putchar(&amp;#39;+&amp;#39;); } } else { a[i] = -a[i]; putchar(&amp;#39;-&amp;#39;); } if (i &amp;gt; 1) { if (a[i] !</description>
    </item>
    
    <item>
      <title>NOIP2008普及组题解</title>
      <link>https://www.961996.xyz/p/noip2008%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</link>
      <pubDate>Sun, 05 Sep 2021 10:42:26 +0800</pubDate>
      
      <guid>https://www.961996.xyz/p/noip2008%E6%99%AE%E5%8F%8A%E7%BB%84%E9%A2%98%E8%A7%A3/</guid>
      <description>ISBN号码 对于一个形式为“x-xxx-xxxxx-x”的ISBN，判断其是否合法。
题解 模拟，需要特别处理X。
#include &amp;lt;bits/stdc++.h&amp;gt;using namespace std; int main() { char a[100]; scanf(&amp;#34;%s&amp;#34;, a); int n = strlen(a); int s = 0; for (int i = 0, j = 0; i &amp;lt; n - 1; i++) { if (a[i] != &amp;#39;-&amp;#39;) { j += 1; s += (a[i] - &amp;#39;0&amp;#39;) * j; } } if (s % 11 == (a[n-1] - &amp;#39;0&amp;#39;) || s % 11 == 10 &amp;amp;&amp;amp; a[n-1] == &amp;#39;X&amp;#39;) { puts(&amp;#34;Right&amp;#34;); } else { a[n-1] = s % 11 + &amp;#39;0&amp;#39;; if(s%11 == 10) { a[n-1] = &amp;#39;X&amp;#39;; } puts(a); } } 排座椅 题解 贪心，分别统计每一行每一列加一条通道能隔开的数量，优先选择最多的K条横向的和L条纵向的。</description>
    </item>
    
  </channel>
</rss>
