-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
167 lines (92 loc) · 104 KB
/
atom.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>光之微</title>
<subtitle>迎接光的洗礼</subtitle>
<link href="http://example.com/atom.xml" rel="self"/>
<link href="http://example.com/"/>
<updated>2024-09-26T16:30:28.482Z</updated>
<id>http://example.com/</id>
<author>
<name>OCCJ</name>
</author>
<generator uri="https://hexo.io/">Hexo</generator>
<entry>
<title>page</title>
<link href="http://example.com/undefined/undefined.html"/>
<id>http://example.com/undefined/undefined.html</id>
<published>2024-09-26T16:30:28.000Z</published>
<updated>2024-09-26T16:30:28.482Z</updated>
</entry>
<entry>
<title>第五届太原理工大学新生赛初赛题解</title>
<link href="http://example.com/undefined/dfab75bc.html"/>
<id>http://example.com/undefined/dfab75bc.html</id>
<published>2023-10-21T15:30:11.000Z</published>
<updated>2023-10-21T15:47:22.903Z</updated>
<content type="html"><![CDATA[<h1>第五届太原理工大学程序设计竞赛新生赛(初赛)题解</h1><h2 id="⭐A-饿饿饭饭">⭐A.饿饿饭饭</h2><h3 id="题目:">题目:</h3><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021204708027-1697902243556-1.png?raw=true" alt="image-20231021204708027-1697902243556-1.png"></p><h2 id="🌟题解:">🌟题解:</h2><blockquote><p>很简单,签个到输出谁饿了</p></blockquote><h3 id="代码:">代码:</h3><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> string s; cin>>s;</span><br><span class="line"> cout<<s<<<span class="string">":eeff"</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐B-扣点点">⭐B.扣点点</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021205039596-1697902243556-2.png?raw=true" alt="image-20231021205039596-1697902243556-2.png"></p><p>🌟题解:</p><blockquote><p>hammer喜欢玩扣点点但太菜了理不清牌(doge),让你帮忙按一定顺序整理,典型的排序吧</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>这种字符串数组排序较为简单</span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">15</span>;</span><br><span class="line">string s[N];</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> n; cin>>n;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">0</span>;i<n;i++) </span><br><span class="line"> {</span><br><span class="line"> <span class="type">char</span> j[<span class="number">2</span>];</span><br><span class="line"> cin>>j[<span class="number">1</span>]>>j[<span class="number">0</span>];</span><br><span class="line"> s[i] += j[<span class="number">0</span>];</span><br><span class="line"> s[i] += j[<span class="number">1</span>];</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">sort</span>(s,s+n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">0</span>;i<n;i++) </span><br><span class="line"> {</span><br><span class="line"> cout<<s[i][<span class="number">1</span>]<<s[i][<span class="number">0</span>]<<<span class="string">' '</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="number">2.</span>标记法</span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">15</span>;</span><br><span class="line"><span class="type">int</span> cnt[<span class="number">4</span>][<span class="number">10</span>]; </span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="type">int</span> n;</span><br><span class="line"> cin >> n;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">1</span>; i <= n; ++i) {</span><br><span class="line"> <span class="type">int</span> num;</span><br><span class="line"> <span class="type">char</span> s;</span><br><span class="line"> cin >> num >> s;</span><br><span class="line"> <span class="type">int</span> id;</span><br><span class="line"> <span class="keyword">if</span> (s == <span class="string">'B'</span>) id = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (s == <span class="string">'C'</span>) id = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">else</span> id = <span class="number">2</span>;</span><br><span class="line"> cnt[id][num]++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < <span class="number">3</span>; ++i) { </span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> j = <span class="number">1</span>; j <= <span class="number">9</span>; ++j) {</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> k = <span class="number">0</span>; k < cnt[i][j]; ++k) { <span class="comment">//可能这里不好理解,就是看k+到比cnt这大就是cnt-反过来也可以写成while(cnt[i][j]--&&cnt>0)</span></span><br><span class="line"> cout << j << (i==<span class="number">0</span> ? <span class="string">'B'</span> : i==<span class="number">1</span> ? <span class="string">'C'</span> : <span class="string">'D'</span>) << <span class="string">" "</span>; </span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> cout << endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="number">3.</span>自己写个结构体排序</span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">int</span> n;</span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">node</span>{</span><br><span class="line"> <span class="type">char</span> x,y;</span><br><span class="line">}a[<span class="number">15</span>];</span><br><span class="line"><span class="function"><span class="type">bool</span> <span class="title">cmp</span><span class="params">(node q,node p)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(q.y!=p.y)<span class="keyword">return</span> q.y<p.y;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">return</span> q.x<p.x;</span><br><span class="line">}</span><br><span class="line">string s;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> cin>>n;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> cin>>s;</span><br><span class="line"> a[i].x=s[<span class="number">0</span>];</span><br><span class="line"> a[i].y=s[<span class="number">1</span>];</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">sort</span>(a,a+n,cmp);</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> cout<<a[i].x<<a[i].y<<<span class="string">" "</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="number">4.</span>利用mulimap性质(某孙神的)</span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> multimap<<span class="type">char</span>,<span class="type">char</span>>mp;</span><br><span class="line"> multimap<<span class="type">char</span>,<span class="type">char</span>>ans;</span><br><span class="line"> <span class="type">int</span> n;</span><br><span class="line"> cin>>n;</span><br><span class="line"> <span class="keyword">while</span>(n--){</span><br><span class="line"> <span class="type">char</span> ch;</span><br><span class="line"> <span class="type">char</span> temp;</span><br><span class="line"> cin>>temp>>ch;</span><br><span class="line"> mp.<span class="built_in">insert</span>({temp,ch});</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> it=mp.<span class="built_in">begin</span>();it!=mp.<span class="built_in">end</span>();it++){</span><br><span class="line"> ans.<span class="built_in">insert</span>(<span class="built_in">pair</span><<span class="type">char</span>,<span class="type">char</span>>(it->second,it->first));</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> it=ans.<span class="built_in">begin</span>();it!=ans.<span class="built_in">end</span>();it++){</span><br><span class="line"> cout<<it->second<<it->first<<<span class="string">" "</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐C-String-problem">⭐C.String problem</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021211432622-1697902243557-3.png?raw=true" alt="image-20231021211432622-1697902243557-3.png"></p><p>🌟题解:</p><blockquote><p>也很简单的一道,比较三个字符串字符就行,2个一样就改一次,都不一样就改两次,</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">int</span> n;</span><br><span class="line">string s1,s2,s3;</span><br><span class="line"><span class="type">int</span> ans;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cin>>n;</span><br><span class="line"> cin>>s1>>s2>>s3;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(s1[i]==s2[i] && s1[i]==s3[i]) <span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(s1[i]==s2[i] || s1[i]==s3[i] || s2[i]==s3[i]) ans++;</span><br><span class="line"> <span class="keyword">else</span> ans+=<span class="number">2</span>;</span><br><span class="line"> }</span><br><span class="line"> cout<<ans<<endl; </span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐D-数豆豆">⭐D.数豆豆</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021213103623-1697902243557-4.png?raw=true" alt="image-20231021213103623-1697902243557-4.png"></p><p>🌟题解:</p><blockquote><p>考察一下思维吧,其实也很简单,就是每次拿大的数字,排下序就好了</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><string></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> string s;</span><br><span class="line"> cin>>s;</span><br><span class="line"> <span class="built_in">sort</span>(s.<span class="built_in">begin</span>(),s.<span class="built_in">end</span>());</span><br><span class="line"> <span class="built_in">reverse</span>(s.<span class="built_in">begin</span>(),s.<span class="built_in">end</span>());</span><br><span class="line"> string s1,s2;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<s.<span class="built_in">size</span>();++i)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(i%<span class="number">2</span>==<span class="number">0</span>)</span><br><span class="line"> s1=s1+s[i];</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> s2=s2+s[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(s1[<span class="number">0</span>]==<span class="string">'0'</span>) s1=<span class="string">"0"</span>;</span><br><span class="line"> <span class="keyword">if</span>(s2[<span class="number">0</span>]==<span class="string">'0'</span>) s2=<span class="string">"0"</span>;</span><br><span class="line"> cout<<s1<<endl;</span><br><span class="line"> cout<<s2<<endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐E-Another-string-problem">⭐E.Another string problem</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021214553076.png?raw=true" alt="image-20231021214553076.png"></p><p>🌟题解:</p><blockquote><p>也是挺简单的,呆梨同学们都可以报名新生赛体验今年12月。就判断下是否两个字符串只有一个字符不一样就行,注意中间缺字符或者多字符也是可以的,那么就有三种情况,字符一样长,不一样长是删除还是增加(差距为1),还有差距大于1了因为只能改一次肯定不行。</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> string s, t;</span><br><span class="line"> cin >> s ; cin>>t;</span><br><span class="line"> <span class="type">int</span> n = s.<span class="built_in">size</span>(), m = t.<span class="built_in">size</span>();</span><br><span class="line"> <span class="keyword">if</span> (<span class="built_in">abs</span>(n-m) > <span class="number">1</span>) cout << <span class="string">"NO"</span> << endl;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (n == m) {</span><br><span class="line"> <span class="type">int</span> cnt = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < n; ++i)</span><br><span class="line"> <span class="keyword">if</span> (s[i] != t[i] && ++cnt > <span class="number">1</span>) {</span><br><span class="line"> cout << <span class="string">"NO"</span> << endl; <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> cout << <span class="string">"YES"</span> << endl;</span><br><span class="line"> } <span class="keyword">else</span> { </span><br><span class="line"> <span class="type">int</span> i, j,cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span> (i = <span class="number">0</span>, j = <span class="number">0</span>; i < n && j < m; ++i, ++j) {</span><br><span class="line"> <span class="keyword">if</span> (s[i] != t[j]) {</span><br><span class="line"> <span class="keyword">if</span> (n > m) --j;</span><br><span class="line"> <span class="keyword">else</span> --i;</span><br><span class="line"> <span class="keyword">if</span> (++cnt > <span class="number">1</span>) {</span><br><span class="line"> cout << <span class="string">"NO"</span> << endl; <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (i < n || j < m) ++cnt;</span><br><span class="line"> cout << (cnt == <span class="number">1</span> ? <span class="string">"YES"</span> : <span class="string">"NO"</span>) << endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐F-迷失的Syuggie">⭐F.迷失的Syuggie</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231016042.png?raw=true" alt="image-20231021231016042.png"></p><p>🌟题解:</p><blockquote><p>也是一道典型的bfs题</p><p>网格由字符的二维数组"f"表示,其中"#“表示障碍物,”."表示空白格子。算法从起始点(标记为’S’)开始,探索所有可能的路径,直到达到目标点(标记为’T’)或者在给定的步数限制"k"内探索完所有可能的路径。最短路径长度存储在变量"ans"中,每当找到一条更短的路径时,它就会被更新。最后,最短路径长度被打印出来。</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><queue></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N=<span class="number">1010</span>;</span><br><span class="line"><span class="keyword">typedef</span> pair<<span class="type">int</span>,<span class="type">int</span>> PII;</span><br><span class="line"><span class="keyword">struct</span> <span class="title class_">point</span> {</span><br><span class="line"> <span class="type">int</span> x,y,step;</span><br><span class="line">};</span><br><span class="line">queue<point> q;</span><br><span class="line"><span class="type">char</span> f[N][N];</span><br><span class="line"><span class="type">int</span> x[]={<span class="number">-1</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},y[]={<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">-1</span>};</span><br><span class="line"><span class="type">int</span> n,m,k;</span><br><span class="line"><span class="type">int</span> sx,sy,tx,ty;</span><br><span class="line"><span class="type">int</span> ans=<span class="number">1e6</span>;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">bfs</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> q.<span class="built_in">push</span>({sx,sy,<span class="number">0</span>});</span><br><span class="line"> f[sx][sy]=<span class="string">'#'</span>;</span><br><span class="line"> <span class="keyword">while</span>(q.<span class="built_in">size</span>())</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">auto</span> t=q.<span class="built_in">front</span>();</span><br><span class="line"> q.<span class="built_in">pop</span>();</span><br><span class="line"> <span class="keyword">if</span>(t.step<=k) </span><br><span class="line"> {</span><br><span class="line"> ans=<span class="built_in">min</span>(ans,<span class="built_in">abs</span>(t.x-tx)+<span class="built_in">abs</span>(t.y-ty));</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>;i<<span class="number">4</span>;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="type">int</span> a=t.x+x[i],b=t.y+y[i];</span><br><span class="line"> <span class="keyword">if</span>(a>=<span class="number">1</span>&&a<=n&&b>=<span class="number">1</span>&&b<=m&&f[a][b]!=<span class="string">'#'</span>)</span><br><span class="line"> {</span><br><span class="line"> q.<span class="built_in">push</span>({a,b,t.step+<span class="number">1</span>});</span><br><span class="line"> f[a][b]=<span class="string">'#'</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> ans;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cin>>n>>m>>k;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">1</span>;j<=m;j++)</span><br><span class="line"> {</span><br><span class="line"> <span class="type">char</span> c;</span><br><span class="line"> cin>>c;</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'T'</span>)</span><br><span class="line"> {</span><br><span class="line"> tx=i;</span><br><span class="line"> ty=j;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'S'</span>)</span><br><span class="line"> {</span><br><span class="line"> sx=i;</span><br><span class="line"> sy=j;</span><br><span class="line"> }</span><br><span class="line"> f[i][j]=c;</span><br><span class="line"> }</span><br><span class="line"> cout<<<span class="built_in">bfs</span>()<<endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="⭐G-寻找签到题之路">⭐G.寻找签到题之路</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021221209375.png?raw=true" alt="image-20231021221209375.png"></p><p>🌟题解:</p><blockquote><p>一眼典型背包dp,直接写就好。。。。就是时间有限要得分最大,每个题目时间也知道。总时间就是背包,每个题目分数就是价值,时间就是重量。不过也有大佬别的做法</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">10010</span>;</span><br><span class="line"><span class="type">int</span> t[N],s[N]; </span><br><span class="line"><span class="type">int</span> f[N][N]; </span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="type">int</span> n, m; </span><br><span class="line"> cin >> n >> m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">1</span>; i <= n; i++) </span><br><span class="line"> cin >> s[i] >> t[i];</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">1</span>; i <= n; i++) </span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j = <span class="number">1</span>; j <= m; j++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(j < t[i]) </span><br><span class="line"> f[i][j] = f[i - <span class="number">1</span>][j];</span><br><span class="line"> <span class="keyword">else</span> </span><br><span class="line"> f[i][j] = <span class="built_in">max</span>(f[i - <span class="number">1</span>][j], f[i - <span class="number">1</span>][j - t[i]] + s[i]);</span><br><span class="line"> } </span><br><span class="line"> cout << f[n][m] << endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}<span class="comment">//正的</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">1000005</span>;</span><br><span class="line"><span class="type">int</span> n,m;</span><br><span class="line"><span class="type">int</span> f[N];</span><br><span class="line"><span class="type">int</span> v,w;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cin>>n>>m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> {</span><br><span class="line"> cin>>w>>v;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j=m;j>=v;j--)</span><br><span class="line"> {</span><br><span class="line"> f[j]=<span class="built_in">max</span>(f[j],f[j-v]+w);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> cout<<f[m]<<endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}<span class="comment">//逆的</span></span><br><span class="line"><span class="number">2.</span>dfs来自dy</span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">int</span> t, n;</span><br><span class="line"><span class="type">int</span> s[<span class="number">21</span>], ti[<span class="number">21</span>];</span><br><span class="line"><span class="type">int</span> maxn;</span><br><span class="line"><span class="function"><span class="type">void</span> <span class="title">dfs</span><span class="params">(<span class="type">int</span> time, <span class="type">int</span> score, <span class="type">int</span> tit)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (time <<span class="number">0</span>)<span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span> (tit == n){</span><br><span class="line"> maxn = <span class="built_in">max</span>(maxn, score);</span><br><span class="line"> <span class="keyword">return</span>;}</span><br><span class="line"> <span class="built_in">dfs</span>(time,score,tit+<span class="number">1</span>);</span><br><span class="line"> <span class="built_in">dfs</span>(time-ti[tit],score+s[tit],tit+<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> cin >> n >> t;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">0</span>; i < n; i++) {</span><br><span class="line"> cin >> s[i] >> ti[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">dfs</span>(t, <span class="number">0</span>, <span class="number">0</span>);</span><br><span class="line"> cout << maxn;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐H-子矩阵和">⭐H.子矩阵和</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021222537488.png?raw=true" alt="image-20231021222537488.png"></p><p>🌟题解:</p><blockquote><p>就是典型的二维前缀和处理一下查询</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> ll;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N=<span class="number">10010</span>;</span><br><span class="line">ll a[N],b[N],c[N][N],s[N][N];</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> ll n,m,q;</span><br><span class="line"> cin>>n>>m;</span><br><span class="line"> <span class="keyword">for</span>(ll i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> cin>>a[i];</span><br><span class="line"> <span class="keyword">for</span>(ll i=<span class="number">1</span>;i<=m;i++)</span><br><span class="line"> cin>>b[i];</span><br><span class="line"> <span class="keyword">for</span>(ll i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(ll j=<span class="number">1</span>;j<=m;j++)</span><br><span class="line"> c[i][j]=a[i]*b[j];</span><br><span class="line"> <span class="keyword">for</span>(ll i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(ll j=<span class="number">1</span>;j<=m;j++)</span><br><span class="line"> s[i][j] = s[i][j - <span class="number">1</span>] + s[i - <span class="number">1</span>][j] - s[i - <span class="number">1</span>][j - <span class="number">1</span>] + c[i][j];</span><br><span class="line"> cin>>q;</span><br><span class="line"> <span class="keyword">while</span>(q--)</span><br><span class="line"> {</span><br><span class="line"> ll x1,y1,x2,y2;</span><br><span class="line"> cin>>x1>>y1>>x2>>y2;</span><br><span class="line"> cout<<s[x2][y2] - s[x1 - <span class="number">1</span>][y2] - s[x2][y1 - <span class="number">1</span>] + s[x1 - <span class="number">1</span>][y1 - <span class="number">1</span>]<<endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐I-最短区间">⭐I.最短区间</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021222929110.png?raw=true" alt="image-20231021222929110.png"></p><p>🌟题解:</p><blockquote><p>双指针i,j指一指循环区间根据条件找到最小区间</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">100005</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> ll;</span><br><span class="line">ll n,x;</span><br><span class="line">ll a[N];</span><br><span class="line">ll mul=<span class="number">1</span>,ma;</span><br><span class="line"><span class="type">int</span> ans=N;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cin>>n>>x;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n;i++) cin>>a[i];</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>,j=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">while</span>(mul<x && j<=n)</span><br><span class="line"> {</span><br><span class="line"> mul*=a[j];j++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(mul>=x) ans=<span class="built_in">min</span>(ans,j-i);</span><br><span class="line"> mul/=a[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(ans>n) ans=<span class="number">-1</span>;</span><br><span class="line"> cout<<ans<<endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="number">2.</span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">1e5</span> + <span class="number">5</span>;</span><br><span class="line"><span class="type">int</span> a[N];</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span> </span>{</span><br><span class="line"> <span class="type">int</span> n, x;</span><br><span class="line"> cin >> n >> x;</span><br><span class="line"> <span class="keyword">for</span> (<span class="type">int</span> i = <span class="number">1</span>; i <= n; ++i)</span><br><span class="line"> cin >> a[i];</span><br><span class="line"> <span class="type">int</span> left = <span class="number">1</span>, right = <span class="number">1</span>, len = <span class="number">0</span>;</span><br><span class="line"> <span class="type">long</span> <span class="type">long</span> prod = a[<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">while</span> (right <= n) {</span><br><span class="line"> <span class="keyword">if</span> (prod >= x) { </span><br><span class="line"> <span class="keyword">if</span> (len == <span class="number">0</span> || right - left + <span class="number">1</span> < len) </span><br><span class="line"> len = right - left + <span class="number">1</span>;</span><br><span class="line"> prod /= a[left]; </span><br><span class="line"> left++;</span><br><span class="line"> <span class="keyword">if</span> (left > right) { </span><br><span class="line"> right++;</span><br><span class="line"> <span class="keyword">if</span> (right <= n)</span><br><span class="line"> prod *= a[right];</span><br><span class="line"> }</span><br><span class="line"> } <span class="keyword">else</span> {</span><br><span class="line"> right++;</span><br><span class="line"> <span class="keyword">if</span> (right <= n)</span><br><span class="line"> prod *= a[right];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (len == <span class="number">0</span>)</span><br><span class="line"> cout << <span class="string">"-1"</span> << endl;</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> cout << len << endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="⭐J-点球大战">⭐J.点球大战</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231553939.png?raw=true" alt="image-20231021231553939.png"></p><p>🌟题解:</p><p>代码:</p><hr><h2 id="⭐K-冠军预言">⭐K.冠军预言</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231610977.png?raw=true" alt="image-20231021231610977.png"></p><p>🌟题解:</p><p>代码:</p><hr><h2 id="⭐L-an-interesting-problem">⭐L.an interesting problem</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231632155.png?raw=true" alt="image-20231021231632155.png"></p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231655031.png?raw=true" alt="image-20231021231655031.png"></p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021231705949.png?raw=true" alt="image-20231021231705949.png"></p><p>🌟题解:</p><blockquote><p>很复杂的一道题但是思维很简单,代码量很多</p></blockquote><p>代码:</p><hr><h2 id="⭐M-选数异或">⭐M.选数异或</h2><p>题目:</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/image-20231021230033580.png?raw=true" alt="image-20231021230033580.png"></p><p>🌟题解:</p><blockquote><p>我们可以用一个桶来记录每个数出现的次数,然后从前往后遍历数列,对于每个数 x,我们可以计算出在它之前出现的比它大的数的个数,就是(i-1-cnt[x]),其中 <em>i</em> 是当前遍历到的位置,<em>c<strong>n</strong>t</em>[<em>x</em>] 是 x* 出现的次数。这个式子的意思是,在 x 之前,一共有 i<em>−1 个数,其中有 c<strong>n</strong>t</em>[<em>x</em>] 个数等于 <em>x</em>,所以比 x<em>大的数的个数就是 i</em>−1−<em>c<strong>n</strong>t</em>[<em>x</em>]。</p><p>最后的答案就是所有的逆序对个数之和。时间复杂度 O*(*n)。</p></blockquote><p>代码:</p><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">1000010</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> ll;</span><br><span class="line">ll n,cnt[N],x,ans;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> cin>>n;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n;i++) </span><br><span class="line"> {</span><br><span class="line"> cin>>x;</span><br><span class="line"> ans+=(i<span class="number">-1</span>-cnt[x]);</span><br><span class="line"> cnt[x]++;</span><br><span class="line"> }</span><br><span class="line"> cout<<ans<<endl;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><hr><h2 id="题目难度:A-B-CG-HD-E-I-M-F-JKL">题目难度:A<B<CG<HD<E<I<M<F<JKL</h2>]]></content>
<summary type="html"><h1>第五届太原理工大学程序设计竞赛新生赛(初赛)题解</h1>
<h2 id="⭐A-饿饿饭饭">⭐A.饿饿饭饭</h2>
<h3 id="题目:">题目:</h3>
<p><img src="https://github.com/cjmarklll/cjmarklll.gi</summary>
<category term="题解" scheme="http://example.com/tags/%E9%A2%98%E8%A7%A3/"/>
</entry>
<entry>
<title>杂题结论</title>
<link href="http://example.com/undefined/f1b6fc8a.html"/>
<id>http://example.com/undefined/f1b6fc8a.html</id>
<published>2023-09-16T06:49:45.000Z</published>
<updated>2023-09-16T07:44:24.735Z</updated>
<content type="html"><![CDATA[<h1>1.[a,b]的奇数之和</h1><h2 id="1-2k-1-的奇数之和:k-2">[1,2k-1]的奇数之和:k^2</h2><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/111.png?raw=true" alt="111.png"></p><h1>((b+1)/2)<em>((b+1)/2)-(a/2)</em>(a/2)</h1><h1>2.[a,b]的偶数之和:</h1><h2 id="1-2k-的偶数和">[1,2k]的偶数和</h2><h2 id="k-k-2">k+k^2</h2><p>:(b/2-(a-1)/2)+(b/2)<em>(b/2)-((a-1)/2)</em>((a-1)/2)</p><h1>3.八进制十进制小数</h1><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string"><cstring></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> N = <span class="number">10010</span>;</span><br><span class="line"><span class="type">char</span> d[N] ; <span class="comment">//八进制数</span></span><br><span class="line"><span class="type">int</span> ans[N] ; <span class="comment">//十进制数</span></span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(cin>>d){</span><br><span class="line"> <span class="built_in">memset</span>(ans,<span class="number">0</span>,<span class="built_in">sizeof</span>(ans)); <span class="comment">//每组数据都必须先初始化ans[] </span></span><br><span class="line"> <span class="type">int</span> d2;</span><br><span class="line"> <span class="type">int</span> len = <span class="built_in">strlen</span>(d); <span class="comment">//记录小数的位数 </span></span><br><span class="line"> <span class="type">int</span> t = <span class="number">0</span> ;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = len - <span class="number">1</span> ; i > <span class="number">1</span> ; i--){</span><br><span class="line"> d2 = d[i] - <span class="string">'0'</span> ; <span class="comment">//d2来接收小数的每一位的数 </span></span><br><span class="line"> <span class="type">int</span> k = <span class="number">0</span> , j = <span class="number">0</span> ;</span><br><span class="line"> <span class="keyword">while</span>(j<t || d2){ <span class="comment">//此循环内语句为数组模拟除法计算 </span></span><br><span class="line"> d2 = d2*<span class="number">10</span> + ans[j++]; </span><br><span class="line"> ans[k++] = d2/<span class="number">8</span> ;</span><br><span class="line"> d2 %= <span class="number">8</span> ;</span><br><span class="line"> }</span><br><span class="line"> t = k; <span class="comment">//记录最后的得到的位数 </span></span><br><span class="line"> }</span><br><span class="line"> cout<<d<<<span class="string">" [8] = 0."</span> ;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i = <span class="number">0</span> ; i < t ; i++)</span><br><span class="line"> cout<<ans[i];</span><br><span class="line"> cout<<<span class="string">" [10]"</span><<endl;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>十进制转R进制</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdlib.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">char</span> digits[] = <span class="string">"0123456789ABCDEF"</span>;</span><br><span class="line"><span class="meta">#<span class="keyword">define</span> N 32</span></span><br><span class="line"><span class="type">char</span> ans[N + <span class="number">2</span>];</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">{</span><br><span class="line"> <span class="type">int</span> n, r;</span><br><span class="line"> <span class="keyword">while</span> (~<span class="built_in">scanf</span> (<span class="string">"%d%d"</span>, &n, &r)) {</span><br><span class="line"> <span class="keyword">if</span>(r==<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">if</span> (n < <span class="number">0</span>) {<span class="built_in">printf</span>(<span class="string">"-"</span>); n = -n;}</span><br><span class="line"> <span class="type">int</span> i = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span> (n) ans[i++] = digits[n % r], n /= r;</span><br><span class="line"> <span class="keyword">if</span> (i == <span class="number">0</span>) ans[i++] = <span class="string">'0'</span>;</span><br><span class="line"></span><br><span class="line"> <span class="comment">/* 输出结果 */</span></span><br><span class="line"> <span class="keyword">while</span> (--i >= <span class="number">0</span>) <span class="built_in">putchar</span>(ans[i]);</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>A转B</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><string></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><ctype.h></span></span></span><br><span class="line">using namespace <span class="built_in">std</span>;</span><br><span class="line"><span class="built_in">string</span> <span class="title function_">convert</span><span class="params">(<span class="type">int</span> a, <span class="built_in">string</span>& s, <span class="type">int</span> b)</span></span><br><span class="line">{</span><br><span class="line"> <span class="type">long</span> val, dcount, digit;</span><br><span class="line"> <span class="type">char</span> result[<span class="number">72</span>], c;</span><br><span class="line"> <span class="built_in">string</span> ans;</span><br><span class="line"> </span><br><span class="line"> val = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>; i<(<span class="type">int</span>)s.size(); i++) {</span><br><span class="line"> <span class="keyword">if</span>(<span class="built_in">isdigit</span>(s[i]))</span><br><span class="line"> val = val * a + s[i] - <span class="string">'0'</span>;</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> val = val * a + <span class="built_in">toupper</span>(s[i]) - <span class="string">'A'</span> + <span class="number">10</span>;</span><br><span class="line"> }</span><br><span class="line"> dcount = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(val) {</span><br><span class="line"> digit = val % b;</span><br><span class="line"> val /= b;</span><br><span class="line"> result[dcount++] = ((digit >= <span class="number">10</span>) ? <span class="string">'A'</span> - <span class="number">10</span> : <span class="string">'0'</span>) + digit;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(dcount == <span class="number">0</span>) {</span><br><span class="line"> result[dcount++] = <span class="string">'0'</span>;</span><br><span class="line"> result[dcount] = <span class="string">'\0'</span>;</span><br><span class="line"> } <span class="keyword">else</span></span><br><span class="line"> result[dcount] = <span class="string">'\0'</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">0</span>, j=dcount<span class="number">-1</span>; i<j; i++, j--) {</span><br><span class="line"> c = result[i];</span><br><span class="line"> result[i] = result[j];</span><br><span class="line"> result[j] = c;</span><br><span class="line"> }</span><br><span class="line"> ans = result;</span><br><span class="line"> <span class="keyword">return</span> ans;</span><br><span class="line">}</span><br><span class="line"> </span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">{</span><br><span class="line"> <span class="type">int</span> a, b;</span><br><span class="line"> <span class="built_in">string</span> s;</span><br><span class="line"> <span class="built_in">cin</span> >> a >> s >> b;</span><br><span class="line"> <span class="built_in">cout</span> << convert(a, s, b) << <span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>2转16位数爆longlong</p><figure class="highlight c#"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* Bailian2798 2进制转化为16进制 */</span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#include <stdio.h></span></span><br><span class="line"><span class="meta">#include <string.h></span></span><br><span class="line"> </span><br><span class="line"><span class="meta">#<span class="keyword">define</span> N 10000</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> N2 4</span></span><br><span class="line"><span class="built_in">char</span> s[N + N2 + <span class="number">1</span>];</span><br><span class="line"> </span><br><span class="line"><span class="built_in">char</span> convert[] = <span class="string">"0123456789ABCDEF"</span>;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="built_in">int</span> <span class="title">main</span>(<span class="params"><span class="keyword">void</span></span>)</span></span><br><span class="line">{</span><br><span class="line"> <span class="built_in">int</span> n, len, digits, i, k;</span><br><span class="line"> </span><br><span class="line"> scanf(<span class="string">"%d"</span>, &n);</span><br><span class="line"> getchar();</span><br><span class="line"> <span class="keyword">while</span>(n--) {</span><br><span class="line"> gets(s + N2);</span><br><span class="line"> </span><br><span class="line"> s[<span class="number">0</span>] = s[<span class="number">1</span>] = s[<span class="number">2</span>] = s[<span class="number">3</span>] = <span class="string">'0'</span>;</span><br><span class="line"> len = strlen(s + N2); <span class="comment">/* 2进制位数 */</span></span><br><span class="line"> digits = (len + N2 - <span class="number">1</span>) / N2; <span class="comment">/* 16进制位数 */</span></span><br><span class="line"> len += N2 - <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(i=<span class="number">1</span>, k=len; i<=digits; i++) {</span><br><span class="line"> s[k--] = convert[(s[len - <span class="number">3</span>] - <span class="string">'0'</span>) * <span class="number">8</span> + (s[len - <span class="number">2</span>] - <span class="string">'0'</span>) * <span class="number">4</span> + (s[len - <span class="number">1</span>] - <span class="string">'0'</span>) * <span class="number">2</span> + (s[len] - <span class="string">'0'</span>)];</span><br><span class="line"> len -= N2;</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> printf(<span class="string">"%s\n"</span>, &s[k + <span class="number">1</span>]);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>4.大小写转换</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">大写变小写、小写变大写 : 字符 ^= <span class="number">32</span>;</span><br><span class="line"></span><br><span class="line">大写变小写、小写变小写 : 字符 |= <span class="number">32</span>;</span><br><span class="line"></span><br><span class="line">小写变大写、大写变大写 : 字符 &= <span class="number">-33</span>;</span><br><span class="line">a-z:<span class="number">97</span><span class="number">-122</span></span><br><span class="line">A-Z:<span class="number">65</span><span class="number">-90</span></span><br><span class="line"><span class="number">0</span><span class="number">-9</span>:<span class="number">48</span><span class="number">-57</span></span><br></pre></td></tr></table></figure><ol start="5"><li class="lvl-3"></li></ol><figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"> <span class="type">int</span> t = x;</span><br><span class="line"> <span class="type">int</span> value = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span> (x / <span class="number">10</span>){</span><br><span class="line"> value = <span class="number">10</span> * value + x % <span class="number">10</span>;</span><br><span class="line"> x /= <span class="number">10</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(value*<span class="number">10</span> + x == t) <span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}判断回文数字</span><br><span class="line"> <span class="comment">/*幻方*/</span> <span class="meta">#<span class="keyword">include</span><span class="string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> std;</span><br><span class="line"> <span class="type">int</span> n,a[<span class="number">40</span>][<span class="number">40</span>],x,y;</span><br><span class="line"><span class="function"><span class="type">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> cin>>n;</span><br><span class="line"> x=<span class="number">1</span>,y=(n+<span class="number">1</span>)/<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n*n;i++){</span><br><span class="line"> a[x][y]=i;</span><br><span class="line"> <span class="keyword">if</span>(!a[(x<span class="number">-2</span>+n)%n+<span class="number">1</span>][y%n+<span class="number">1</span>]) x=(x<span class="number">-2</span>+n)%n+<span class="number">1</span>,y=y%n+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">else</span> x=x%n+<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">1</span>;j<=n;j++){cout<<a[i][j]<<<span class="string">' '</span>;}</span><br><span class="line"> cout<<endl;}</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html"><h1>1.[a,b]的奇数之和</h1>
<h2 id="1-2k-1-的奇数之和:k-2">[1,2k-1]的奇数之和:k^2</h2>
<p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/ma</summary>
<category term="杂题" scheme="http://example.com/tags/%E6%9D%82%E9%A2%98/"/>
</entry>
<entry>
<title>序列式容器</title>
<link href="http://example.com/undefined/1ae3852a.html"/>
<id>http://example.com/undefined/1ae3852a.html</id>
<published>2023-09-12T05:50:18.000Z</published>
<updated>2023-09-16T08:41:03.283Z</updated>
<content type="html"><![CDATA[<h1>一、简介</h1><p>序列容器以线性序列的方式存储元素。它没有对元素进行排序,元素的顺序和存储它们的顺序相同。一般来说,有 5 种标准的序列容器,每种容器都具有不同的特性:</p><ul class="lvl-0"><li class="lvl-2"><p>array<T,N> (数组 :是一个长度固定的序列,有N个T类型的对象,不能增加或删除元素。</p></li><li class="lvl-2"><p>vector<T> (向量容器) :</T></p></li><li class="lvl-2"><p>是一个长度可变的序列,用来存放T类型的对象。必要时,可以自动增加容量,但只能在序列的末尾高效地增加或删除元素。</p></li><li class="lvl-2"><p>deque<T> (双向队列容器) :</T></p></li><li class="lvl-2"><p>是一个长度可变的、可以自动增长的序列,在序列的两端都不能高效地增加或删除元素。</p></li><li class="lvl-2"><p>list<T> (链表容器) :</T></p></li><li class="lvl-2"><p>是一个长度可变的、由 T 类型对象组成的序列,它以双向链表的形式组织元素,在这个序列的任何地方都可以高效地增加或删除元素。访问容器中任意元素的速度要比前三种容器慢,这是因为 list<T> 必须从第一个元素或最后一个元素开始访问,需要沿着链表移动,直到到达想要的元素。</T></p></li><li class="lvl-2"><p>forward list<T> (正向链表容器) :</T></p></li><li class="lvl-2"><p>是一个长度可变的、由 T 类型对象组成的序列,它以单链表的形式组织元素,是一类比链表容器快、更节省内存的容器,但是它内部的元素只能从第一个元素开始访问。</p></li></ul><p>下面是一些具体性质:</p><ul class="lvl-0"><li class="lvl-2"><p>array<T,N>(数组容器):</p></li><li class="lvl-2"><p>表示可以存储 N 个 T 类型的元素,是 C++ 本身提供的一种容器。此类容器一旦建立,其长度就是固定不变的,这意味着不能增加或删除元素,只能改变某个元素的值;</p></li><li class="lvl-2"><p>vector<T>(向量容器):</T></p></li><li class="lvl-2"><p>用来存放 T 类型的元素,是一个长度可变的序列容器,即在存储空间不足时,会自动申请更多的内存。使用此容器,在尾部增加或删除元素的效率最高(时间复杂度为 O(1) 常数阶),在其它位置插入或删除元素效率较差(时间复杂度为 O(n) 线性阶,其中 n 为容器中元素的个数);</p></li><li class="lvl-2"><p>deque<T>(双端队列容器):</T></p></li><li class="lvl-2"><p>和 vector 非常相似,区别在于使用该容器不仅尾部插入和删除元素高效,在头部插入或删除元素也同样高效,时间复杂度都是 O(1) 常数阶,但是在容器中某一位置处插入或删除元素,时间复杂度为 O(n) 线性阶;</p></li><li class="lvl-2"><p>list<T>(链表容器):</T></p></li><li class="lvl-2"><p>是一个长度可变的、由 T 类型元素组成的序列,它以双向链表的形式组织元素,在这个序列的任何地方都可以高效地增加或删除元素(时间复杂度都为常数阶 O(1)),但访问容器中任意元素的速度要比前三种容器慢,这是因为 list<T> 必须从第一个元素或最后一个元素开始访问,需要沿着链表移动,直到到达想要的元素。</T></p></li><li class="lvl-2"><p>forward_list<T>(正向链表容器):</T></p></li><li class="lvl-2"><p>和 list 容器非常类似,只不过它以单链表的形式组织元素,它内部的元素只能从第一个元素开始访问,是一类比链表容器快、更节省内存的容器。</p><p><img src="https://github.com/cjmarklll/cjmarklll.github.io/blob/main/undefined/f1b6fc8a/222.png?raw=true" alt="222.png"></p></li></ul><h1>二、函数成员</h1><p>这些容器都有一些常见的函数成员帮助去实现各种操作。</p><table><thead><tr><th>函数成员</th><th>函数功能</th><th>vector<T,N></th><th>array<T,N></th><th style="text-align:center">deque<T></T></th></tr></thead><tbody><tr><td>begin()</td><td>返回指向容器中第一个元素的迭代器。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>end()</td><td>返回指向容器最后一个元素所在位置后一个位置的迭代器,通常和 begin() 结合使用。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>rbegin()</td><td>返回指向最后一个元素的迭代器。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>rend()</td><td>返回指向第一个元素所在位置前一个位置的迭代器。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>cbegin()</td><td>和 begin() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>cend()</td><td>和 end() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>crbegin()</td><td>和 rbegin() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>crend()</td><td>和 rend() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>assign()</td><td>用新元素替换原有内容。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>operator=()</td><td>复制同类型容器的元素,或者用初始化列表替换现有内容。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>size()</td><td>返回实际元素个数。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>max_size()</td><td>返回元素个数的最大值。这通常是一个很大的值,一般是 232-1,所以我们很少会用到这个函数。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>capacity()</td><td>返回当前容量。</td><td>-</td><td>是</td><td style="text-align:center">-</td></tr><tr><td>empty()</td><td>判断容器中是否有元素,若无元素,则返回 true;反之,返回 false。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>resize()</td><td>改变实际元素的个数。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>shrink _to_fit()</td><td>将内存减少到等于当前元素实际所使用的大小。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>front()</td><td>返回第一个元素的引用。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>back()</td><td>返回最后一个元素的引用。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>operator</td><td>使用索引访问元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>at()</td><td>使用经过边界检査的索引访问元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>push_back()</td><td>在序列的尾部添加一个元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>insert()</td><td>在指定的位置插入一个或多个元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>emplace()</td><td>在指定的位置直接生成一个元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>emplace_back()</td><td>在序列尾部生成一个元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>pop_back()</td><td>移出序列尾部的元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>erase()</td><td>移出一个元素或一段元素。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>clear()</td><td>移出所有的元素,容器大小变为 0。</td><td>-</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>swap()</td><td>交换两个容器的所有元素。</td><td>是</td><td>是</td><td style="text-align:center">是</td></tr><tr><td>data()</td><td>返回指向容器中第一个元素的指针。</td><td>是</td><td>是</td><td style="text-align:center">-</td></tr></tbody></table><p>list and forward_list</p><table><thead><tr><th>函数成员</th><th>函数功能</th><th>list<T></T></th><th>forward_list<T></T></th></tr></thead><tbody><tr><td>begin()</td><td>返回指向容器中第一个元素的迭代器。</td><td>是</td><td>是</td></tr><tr><td>end()</td><td>返回指向容器最后一个元素所在位置后一个位置的迭代器。</td><td>是</td><td>是</td></tr><tr><td>rbegin()</td><td>返回指向最后一个元素的迭代器。</td><td>是</td><td>-</td></tr><tr><td>rend()</td><td>返回指向第一个元素所在位置前一个位置的迭代器。</td><td>是</td><td>-</td></tr><tr><td>cbegin()</td><td>和 begin() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>是</td></tr><tr><td>before_begin()</td><td>返回指向第一个元素前一个位置的迭代器。</td><td>-</td><td>是</td></tr><tr><td>cbefore_begin()</td><td>和 before_begin() 功能相同,只不过在其基础上,增加了 const 属性,即不能用该指针修改元素的值。</td><td>-</td><td>是</td></tr><tr><td>cend()</td><td>和 end() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素</td><td>是</td><td>是</td></tr><tr><td>crbegin()</td><td>和 rbegin() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>-</td></tr><tr><td>crend()</td><td>和 rend() 功能相同,只不过在其基础上,增加了 const 属性,不能用于修改元素。</td><td>是</td><td>-</td></tr><tr><td>assign()</td><td>用新元素替换原有内容。</td><td>是</td><td>是</td></tr><tr><td>operator=()</td><td>复制同类型容器的元素,或者用初始化列表替换现有内容。</td><td>是</td><td>是</td></tr><tr><td>size()</td><td>返回实际元素个数。</td><td>是</td><td>-</td></tr><tr><td>max_size()</td><td>返回元素个数的最大值,这通常是一个很大的值,一般是 232-1,所以我们很少会用到这个函数。</td><td>是</td><td>是</td></tr><tr><td>resize()</td><td>改变实际元素的个数。</td><td>是</td><td>是</td></tr><tr><td>empty()</td><td>判断容器中是否有元素,若无元素,则返回 true;反之,返回 false。</td><td>是</td><td>是</td></tr><tr><td>front()</td><td>返回容器中第一个元素的引用。</td><td>是</td><td>是</td></tr><tr><td>back()</td><td>返回容器中最后一个元素的引用。</td><td>是</td><td>-</td></tr><tr><td>push_back()</td><td>在序列的尾部添加一个元素。</td><td>是</td><td>-</td></tr><tr><td>push_front()</td><td>在序列的起始位置添加一个元素。</td><td>是</td><td>是</td></tr><tr><td>emplace()</td><td>在指定位置直接生成一个元素。</td><td>是</td><td>-</td></tr><tr><td>emplace_after()</td><td>在指定位置的后面直接生成一个元素。</td><td>-</td><td>是</td></tr><tr><td>emplace_back()</td><td>在序列尾部生成一个元素。</td><td>是</td><td>-</td></tr><tr><td>cmplacc_front()</td><td>在序列的起始位生成一个元索。</td><td>是</td><td>是</td></tr><tr><td>insert()</td><td>在指定的位置插入一个或多个元素。</td><td>是</td><td>-</td></tr><tr><td>insert_after()</td><td>在指定位置的后面插入一个或多个元素。</td><td>-</td><td>是</td></tr><tr><td>pop_back()</td><td>移除序列尾部的元素。</td><td>是</td><td>-</td></tr><tr><td>pop_front()</td><td>移除序列头部的元素。</td><td>是</td><td>是</td></tr><tr><td>reverse()</td><td>反转容器中某一段的元素。</td><td>是</td><td>是</td></tr><tr><td>erase()</td><td>移除指定位置的一个元素或一段元素。</td><td>是</td><td>-</td></tr><tr><td>erase_after()</td><td>移除指定位置后面的一个元素或一段元素。</td><td>-</td><td>是</td></tr><tr><td>remove()</td><td>移除所有和参数匹配的元素。</td><td>是</td><td>是</td></tr><tr><td>remove_if()</td><td>移除满足一元函数条件的所有元素。</td><td>是</td><td>是</td></tr><tr><td>unique()</td><td>移除所有连续重复的元素。</td><td>是</td><td>是</td></tr><tr><td>clear()</td><td>移除所有的元素,容器大小变为 0。</td><td>是</td><td>是</td></tr><tr><td>swap()</td><td>交换两个容器的所有元素。</td><td>是</td><td>是</td></tr><tr><td>sort()</td><td>对元素进行排序。</td><td>是</td><td>是</td></tr><tr><td>merge()</td><td>合并两个有序容器。</td><td>是</td><td>是</td></tr><tr><td>splice()</td><td>移动指定位置前面的所有元素到另一个同类型的 list 中。</td><td>是</td><td>-</td></tr><tr><td>splice_after()</td><td>移动指定位置后面的所有元素到另一个同类型的 list 中。</td><td>-</td><td>是</td></tr></tbody></table><p>非常多不过也没必要都记下来,只要掌握几种如begin(),end(),push_back(),sort(),swap()就好</p>]]></content>
<summary type="html"><h1>一、简介</h1>
<p>序列容器以线性序列的方式存储元素。它没有对元素进行排序,元素的顺序和存储它们的顺序相同。一般来说,有 5 种标准的序列容器,每种容器都具有不同的特性:</p>
<ul class="lvl-0">
<li class="lvl-2">
<p>ar</summary>
<category term="STL" scheme="http://example.com/categories/STL/"/>
<category term="STL" scheme="http://example.com/tags/STL/"/>
</entry>
<entry>
<title>STL简介</title>
<link href="http://example.com/undefined/6d927e9f.html"/>
<id>http://example.com/undefined/6d927e9f.html</id>
<published>2023-09-11T12:07:01.000Z</published>
<updated>2023-09-11T13:11:44.445Z</updated>
<content type="html"><![CDATA[<h2 id="STL简介">STL简介</h2><h3 id="⭐STL的组成:">⭐STL的组成:</h3><ul class="lvl-0"><li class="lvl-2"><h4 id="容器(container)">容器(container)</h4></li><li class="lvl-2"><h4 id="迭代器(iterator)这个概念很重要">迭代器(iterator)这个概念很重要</h4></li><li class="lvl-2"><h4 id="算法(algorithm)">算法(algorithm)</h4></li><li class="lvl-2"><h4 id="仿函数(function-object)">仿函数(function object)</h4></li><li class="lvl-2"><h4 id="适配器(adaptor">适配器(adaptor)</h4></li><li class="lvl-2"><h4 id="空间配置器(allocator">空间配置器(allocator)</h4><p>本博客主要讲讲容器和算法还有一些迭代器的知识。另外三个我也不是很理解,共同进步。</p><h3 id="🌟容器:顾名思义是放东西的">🌟容器:顾名思义是放东西的</h3><h4 id="主要是:序列式容器(Sequence-container)、关联式容器(associated-container)、容器适配器(container-adaptor)">主要是:序列式容器(Sequence container)、关联式容器(associated container)、容器适配器(container adaptor)</h4><ul class="lvl-2"><li class="lvl-4"><h5 id="序列式容器:每个元素都有固定位置,取决于插入时间和地点,和值没有关系。(如vector、deque,list)">序列式容器:每个元素都有固定位置,取决于插入时间和地点,和值没有关系。(如vector、deque,list)</h5></li><li class="lvl-4"><h5 id="关联式容器:元素位置取决于特定的排序原则,和插入顺序无关。(如map、set、multiset,multimap)">关联式容器:元素位置取决于特定的排序原则,和插入顺序无关。(如map、set、multiset,multimap)</h5></li><li class="lvl-4"><h5 id="容器适配器:包括stack、queue。">容器适配器:包括stack、queue。</h5><h3 id="⭐算法:一些封装函数直接使用">⭐算法:一些封装函数直接使用</h3><h4 id="比如sort,mergesort,heapsort进行排序;max-element-min-element是元素值大最大最小;去掉重复数字的unique;元素反转的reverse等很多很多。">比如sort,mergesort,heapsort进行排序;max_element,min_element是元素值大最大最小;去掉重复数字的unique;元素反转的reverse等很多很多。</h4><h3 id="🌟迭代器:STL使用迭代器来表示数据位置,可以简单认为是容器的指针,后面又更具体的介绍。">🌟迭代器:STL使用迭代器来表示数据位置,可以简单认为是容器的指针,后面又更具体的介绍。</h3></li></ul></li></ul>]]></content>
<summary type="html"><h2 id="STL简介">STL简介</h2>
<h3 id="⭐STL的组成:">⭐STL的组成:</h3>
<ul class="lvl-0">
<li class="lvl-2">
<h4 id="容器(container)">容器(container)</h4>
</</summary>
<category term="STL" scheme="http://example.com/categories/STL/"/>
<category term="STL" scheme="http://example.com/tags/STL/"/>
<category term="算法" scheme="http://example.com/tags/%E7%AE%97%E6%B3%95/"/>
</entry>
<entry>
<title>分解质因数</title>
<link href="http://example.com/undefined/ece2ea76.html"/>
<id>http://example.com/undefined/ece2ea76.html</id>
<published>2023-09-07T08:47:30.000Z</published>
<updated>2023-09-11T13:12:24.739Z</updated>
<content type="html"><![CDATA[<h1>分解质因数</h1><p>:</p><p>算术基本定理:</p><p>算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积。</p><h3 id="结论一">结论一</h3><p>首先根据 <strong>算术基本定理</strong> 可以知道,一个合数可以由多个比他小的质数相乘而得,而这些质数就是他的质因数。</p><p>并且,例如一个数 x是 n 的因数,并且是合数,那么问一个问题。是否存在一个质数是 x 的质因数,而不是 n 的质因数?答案是不可能的哈</p><p>证明:</p><blockquote><p>很明显 因为 n/x = k,那么 x 的质因数组成 x 的时候只要再乘以 k 就可以得到 n,因此可以得出一个结论:<strong>n 的因数的质因数,肯定也是 n 的质因数</strong>。</p></blockquote><h3 id="结论二"><strong>结论二</strong></h3><p>那么能不能得到一个结论就是,<strong>n 的任何一个因数 x假如他是合数,那么他绝对可以由 n 的小于x的质因数所相乘而得</strong></p><p>答案是可以的哈</p><p>证明:</p><blockquote><p>根据上面的结论推导一下就可以了。n 的因数如果是合数,那么他绝对可以由比他小的质因数组合而成,同时这些质因数是 n 的质因数,那么不就可以得到上面问题的结论。</p></blockquote><h3 id="结论三">结论三</h3><p>因此最后我们又可以得到一条结论:<strong>一个数的因数,如果排序的话,最开始的因数肯定是质因数,后面才有合数</strong>。</p><p>可不可以这么推论呢?可以的。</p><p>证明:</p><blockquote><p>还是根据第一条理论。假如n 的因数除了 1 之外第一个因数是合数,那么他绝对可以由一些质因数组合而成,那么这些数是比他小的,且是 n 的质因数,因此,这些数也是 n 的因数,并且是质数。</p></blockquote><h3 id="结论四">结论四</h3><p>**数 x 是数 n 的因数,且是合数,那么 n 的质因数不一定是 x 的质因数,而 x 的 质因数一定是 n 的质因数。**因此当将 n 的所有比x 小的质因数都除尽的时候,因此当 i 为 x 的时候自然是无法进行整除的。</p><p>因此现在可以证明,从小到大遍历数 n 的因数,并且每次都除尽的话,那么只会遍历到数 n 的质因数,而不会是合数</p><p>最后可以得出,每次<code>if(n%i==0)</code> 成立的时候 i 一定是 n 的质因数。</p>]]></content>
<summary type="html"><h1>分解质因数</h1>
<p>:</p>
<p>算术基本定理:</p>
<p>算术基本定理可表述为:任何一个大于1的自然数 N,如果N不为质数,那么N可以唯一分解成有限个质数的乘积。</p>
<h3 id="结论一">结论一</h3>
<p>首先根据 <strong>算术基</summary>
<category term="数论" scheme="http://example.com/tags/%E6%95%B0%E8%AE%BA/"/>
</entry>
</feed>