update markdown files

This commit is contained in:
Oliver Lew
2019-02-02 01:47:19 +08:00
parent fcb3e4e869
commit 943b599462
113 changed files with 4574 additions and 2299 deletions
+30 -12
View File
@@ -9,18 +9,36 @@ permalink: Advanced/1001.html
## 题目
{% raw %}<div class="ques-view"><p>Calculate <span>$a + b$</span> and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case contains a pair of integers <span>$a$</span> and <span>$b$</span> where <span>$-10^6 \le a, b \le 10^6$</span>. The numbers are separated by a space.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, you should output the sum of <span>$a$</span> and <span>$b$</span> in one line. The sum must be written in the standard format.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">-1000000 9
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">-999,991
</code></pre>
</div>{% endraw %}
Calculate $a + b$ and output the sum in standard format -- that is, the digits
must be separated into groups of three by commas (unless there are less than
four digits).
### Input Specification:
Each input file contains one test case. Each case contains a pair of integers
$a$ and $b$ where $-10^6 \le a, b \le 10^6$ . The numbers are separated by a
space.
### Output Specification:
For each test case, you should output the sum of $a$ and $b$ in one line. The
sum must be written in the standard format.
### Sample Input:
-1000000 9
### Sample Output:
-999,991
## 思路
+37 -15
View File
@@ -9,21 +9,43 @@ permalink: Advanced/1002.html
## 题目
{% raw %}<div class="ques-view"><p>This time, you are supposed to find <span>$A+B$</span> where <span>$A$</span> and <span>$B$</span> are two polynomials.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: </p>
<p><span>$K$</span> <span>$N_1$</span> <span>$a_{N_1}$</span> <span>$N_2$</span> <span>$a_{N_2}$</span> ... <span>$N_K$</span> <span>$a_{N_K}$</span></p>
<p>where <span>$K$</span> is the number of nonzero terms in the polynomial, <span>$N_i$</span> and <span>$a_{N_i}$</span> (<span>$i=1, 2, \cdots , K$</span>) are the exponents and coefficients, respectively. It is given that <span>$1 \le K \le 10$</span>,<span>$0 \le N_K &lt; \cdots &lt; N_2 &lt; N_1 \le 1000$</span>.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case you should output the sum of <span>$A$</span> and <span>$B$</span> in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">2 1 2.4 0 3.2
2 2 1.5 1 0.5
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">3 2 1.5 1 2.9 0 3.2
</code></pre>
</div>{% endraw %}
This time, you are supposed to find $A+B$ where $A$ and $B$ are two
polynomials.
### Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each
line contains the information of a polynomial:
$K$ $N_1$ $a_{N_1}$ $N_2$ $a_{N_2}$ ... $N_K$ $a_{N_K}$
where $K$ is the number of nonzero terms in the polynomial, $N_i$ and
$a_{N_i}$ ( $i=1, 2, \cdots , K$ ) are the exponents and coefficients,
respectively. It is given that $1 \le K \le 10$ , $0 \le N_K < \cdots < N_2 <
N_1 \le 1000$ .
### Output Specification:
For each test case you should output the sum of $A$ and $B$ in one line, with
the same format as the input. Notice that there must be NO extra space at the
end of each line. Please be accurate to 1 decimal place.
### Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
### Sample Output:
3 2 1.5 1 2.9 0 3.2
## 思路
+48 -19
View File
@@ -9,25 +9,54 @@ permalink: Advanced/1003.html
## 题目
{% raw %}<div class="ques-view"><p>As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. For each test case, the first line contains 4 positive integers: <span>$N$</span> (<span>$\le 500$</span>) - the number of cities (and the cities are numbered from 0 to <span>$N-1$</span>), <span>$M$</span> - the number of roads, <span>$C_1$</span> and <span>$C_2$</span> - the cities that you are currently in and that you must save, respectively. The next line contains <span>$N$</span> integers, where the <span>$i$</span>-th integer is the number of rescue teams in the <span>$i$</span>-th city. Then <span>$M$</span> lines follow, each describes a road with three integers <span>$c_1$</span>, <span>$c_2$</span> and <span>$L$</span>, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from <span>$C_1$</span> to <span>$C_2$</span>.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line two numbers: the number of different shortest paths between <span>$C_1$</span> and <span>$C_2$</span>, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">2 4
</code></pre>
</div>{% endraw %}
As an emergency rescue team leader of a city, you are given a special map of
your country. The map shows several scattered cities connected by some roads.
Amount of rescue teams in each city and the length of each road between any
pair of cities are marked on the map. When there is an emergency call to you
from some other city, your job is to lead your men to the place as quickly as
possible, and at the mean time, call up as many hands on the way as possible.
### Input Specification:
Each input file contains one test case. For each test case, the first line
contains 4 positive integers: $N$ ( $\le 500$ ) - the number of cities (and
the cities are numbered from 0 to $N-1$ ), $M$ - the number of roads, $C_1$
and $C_2$ - the cities that you are currently in and that you must save,
respectively. The next line contains $N$ integers, where the $i$ -th integer
is the number of rescue teams in the $i$ -th city. Then $M$ lines follow, each
describes a road with three integers $c_1$ , $c_2$ and $L$ , which are the
pair of cities connected by a road and the length of that road, respectively.
It is guaranteed that there exists at least one path from $C_1$ to $C_2$ .
### Output Specification:
For each test case, print in one line two numbers: the number of different
shortest paths between $C_1$ and $C_2$ , and the maximum amount of rescue
teams you can possibly gather. All the numbers in a line must be separated by
exactly one space, and there is no extra space allowed at the end of a line.
### Sample Input:
5 6 0 2
1 2 1 5 3
0 1 1
0 2 2
0 3 1
1 2 1
2 4 1
3 4 1
### Sample Output:
2 4
## 思路
+48 -17
View File
@@ -9,23 +9,54 @@ permalink: Advanced/1004.html
## 题目
{% raw %}<div class="ques-view"><p>A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case starts with a line containing <span>$0&lt;N&lt;100$</span>, the number of nodes in a tree, and <span>$M$</span> (<span>$&lt;N$</span>), the number of non-leaf nodes. Then <span>$M$</span> lines follow, each in the format:</p>
<pre><code>ID K ID[1] ID[2] ... ID[K]
</code></pre><p>where <code>ID</code> is a two-digit number representing a given non-leaf node, <code>K</code> is the number of its children, followed by a sequence of two-digit <code>ID</code>'s of its children. For the sake of simplicity, let us fix the root ID to be <code>01</code>.</p>
<p>The input ends with <span>$N$</span> being 0. That case must NOT be processed.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, you are supposed to count those family members who have no child <strong>for every seniority level</strong> starting from the root. The numbers must be printed in a line, separated by a space, and there must be no extra space at the end of each line.</p>
<p>The sample case represents a tree with only 2 nodes, where <code>01</code> is the root and <code>02</code> is its only child. Hence on the root <code>01</code> level, there is <code>0</code> leaf node; and on the next level, there is <code>1</code> leaf node. Then we should output <code>0 1</code> in a line.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">2 1
01 1 02
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">0 1
</code></pre>
</div>{% endraw %}
A family hierarchy is usually presented by a pedigree tree. Your job is to
count those family members who have no child.
### Input Specification:
Each input file contains one test case. Each case starts with a line
containing $0<N<100$ , the number of nodes in a tree, and $M$ ( $<N$ ), the
number of non-leaf nodes. Then $M$ lines follow, each in the format:
ID K ID[1] ID[2] ... ID[K]
where `ID` is a two-digit number representing a given non-leaf node, `K` is
the number of its children, followed by a sequence of two-digit `ID`'s of its
children. For the sake of simplicity, let us fix the root ID to be `01`.
The input ends with $N$ being 0. That case must NOT be processed.
### Output Specification:
For each test case, you are supposed to count those family members who have no
child **for every seniority level** starting from the root. The numbers must
be printed in a line, separated by a space, and there must be no extra space
at the end of each line.
The sample case represents a tree with only 2 nodes, where `01` is the root
and `02` is its only child. Hence on the root `01` level, there is `0` leaf
node; and on the next level, there is `1` leaf node. Then we should output `0
1` in a line.
### Sample Input:
2 1
01 1 02
### Sample Output:
0 1
## 思路
+29 -12
View File
@@ -9,18 +9,35 @@ permalink: Advanced/1005.html
## 题目
{% raw %}<div class="ques-view"><p>Given a non-negative integer <span>$N$</span>, your task is to compute the sum of all the digits of <span>$N$</span>, and output every digit of the sum in English.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case occupies one line which contains an <span>$N$</span> (<span>$\le 10^{100}$</span>).</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">12345
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">one five
</code></pre>
</div>{% endraw %}
Given a non-negative integer $N$ , your task is to compute the sum of all the
digits of $N$ , and output every digit of the sum in English.
### Input Specification:
Each input file contains one test case. Each case occupies one line which
contains an $N$ ( $\le 10^{100}$ ).
### Output Specification:
For each test case, output in one line the digits of the sum in English words.
There must be one space between two consecutive words, but no extra space at
the end of a line.
### Sample Input:
12345
### Sample Output:
one five
## 思路
+47 -18
View File
@@ -9,24 +9,53 @@ permalink: Advanced/1006.html
## 题目
{% raw %}<div class="ques-view"><p>At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in's and out's, you are supposed to find the ones who have unlocked and locked the door on that day.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer <span>$M$</span>, which is the total number of records, followed by <span>$M$</span> lines, each in the format:</p>
<pre><code>ID_number Sign_in_time Sign_out_time
</code></pre><p>where times are given in the format <code>HH:MM:SS</code>, and <code>ID_number</code> is a string with no more than 15 characters.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.</p>
<p>Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">SC3021234 CS301133
</code></pre>
</div>{% endraw %}
At the beginning of every day, the first person who signs in the computer room
will unlock the door, and the last one who signs out will lock the door. Given
the records of signing in's and out's, you are supposed to find the ones who
have unlocked and locked the door on that day.
### Input Specification:
Each input file contains one test case. Each case contains the records for one
day. The case starts with a positive integer $M$ , which is the total number
of records, followed by $M$ lines, each in the format:
ID_number Sign_in_time Sign_out_time
where times are given in the format `HH:MM:SS`, and `ID_number` is a string
with no more than 15 characters.
### Output Specification:
For each test case, output in one line the ID numbers of the persons who have
unlocked and locked the door on that day. The two ID numbers must be separated
by one space.
Note: It is guaranteed that the records are consistent. That is, the sign in
time must be earlier than the sign out time for each person, and there are no
two persons sign in or out at the same moment.
### Sample Input:
3
CS301111 15:30:28 17:00:10
SC3021234 08:00:00 11:25:25
CS301133 21:45:00 21:58:40
### Sample Output:
SC3021234 CS301133
## 思路
+42 -14
View File
@@ -9,20 +9,48 @@ permalink: Advanced/1007.html
## 题目
{% raw %}<div class="ques-view"><p>Given a sequence of <span>$K$</span> integers { <span>$N_1$</span>, <span>$N_2$</span>, ..., <span>$N_K$</span> }. A continuous subsequence is defined to be { <span>$N_i$</span>, <span>$N_{i+1}$</span>, ..., <span>$N_j$</span> } where <span>$1 \le i \le j \le K$</span>. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.</p>
<p>Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence. </p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer <span>$K$</span> (<span>$\le 10000$</span>). The second line contains <span>$K$</span> numbers, separated by a space. </p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices <span>$i$</span> and <span>$j$</span> (as shown by the sample case). If all the <span>$K$</span> numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence. </p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">10
-10 1 2 3 4 -5 -23 3 7 -21
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">10 1 4
</code></pre>
</div>{% endraw %}
Given a sequence of $K$ integers { $N_1$ , $N_2$ , ..., $N_K$ }. A continuous
subsequence is defined to be { $N_i$ , $N_{i+1}$ , ..., $N_j$ } where $1 \le i
\le j \le K$ . The Maximum Subsequence is the continuous subsequence which has
the largest sum of its elements. For example, given sequence { -2, 11, -4, 13,
-5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being
20.
Now you are supposed to find the largest sum, together with the first and the
last numbers of the maximum subsequence.
### Input Specification:
Each input file contains one test case. Each case occupies two lines. The
first line contains a positive integer $K$ ( $\le 10000$ ). The second line
contains $K$ numbers, separated by a space.
### Output Specification:
For each test case, output in one line the largest sum, together with the
first and the last numbers of the maximum subsequence. The numbers must be
separated by one space, but there must be no extra space at the end of a line.
In case that the maximum subsequence is not unique, output the one with the
smallest indices $i$ and $j$ (as shown by the sample case). If all the $K$
numbers are negative, then its maximum sum is defined to be 0, and you are
supposed to output the first and the last numbers of the whole sequence.
### Sample Input:
10
-10 1 2 3 4 -5 -23 3 7 -21
### Sample Output:
10 1 4
## 思路
+36 -13
View File
@@ -9,19 +9,42 @@ permalink: Advanced/1008.html
## 题目
{% raw %}<div class="ques-view"><p>The highest building in our city has only one elevator. A request list is made up with <span>$N$</span> positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.</p>
<p>For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case contains a positive integer <span>$N$</span>, followed by <span>$N$</span> positive numbers. All the numbers in the input are less than 100.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print the total time on a single line. </p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">3 2 3 1
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">41
</code></pre>
</div>{% endraw %}
The highest building in our city has only one elevator. A request list is made
up with $N$ positive numbers. The numbers denote at which floors the elevator
will stop, in specified order. It costs 6 seconds to move the elevator up one
floor, and 4 seconds to move down one floor. The elevator will stay for 5
seconds at each stop.
For a given request list, you are to compute the total time spent to fulfill
the requests on the list. The elevator is on the 0th floor at the beginning
and does not have to return to the ground floor when the requests are
fulfilled.
### Input Specification:
Each input file contains one test case. Each case contains a positive integer
$N$ , followed by $N$ positive numbers. All the numbers in the input are less
than 100.
### Output Specification:
For each test case, print the total time on a single line.
### Sample Input:
3 2 3 1
### Sample Output:
41
## 思路
+37 -15
View File
@@ -9,21 +9,43 @@ permalink: Advanced/1009.html
## 题目
{% raw %}<div class="ques-view"><p>This time, you are supposed to find <span>$A\times B$</span> where <span>$A$</span> and <span>$B$</span> are two polynomials.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial:</p>
<p><span>$K$</span> <span>$N_1$</span> <span>$a_{N_1}$</span> <span>$N_2$</span> <span>$a_{N_2}$</span> ... <span>$N_K$</span> <span>$a_{N_K}$</span></p>
<p>where <span>$K$</span> is the number of nonzero terms in the polynomial, <span>$N_i$</span> and <span>$a_{N_i}$</span> (<span>$i=1, 2, \cdots , K$</span>) are the exponents and coefficients, respectively. It is given that <span>$1\le K \le 10$</span>, <span>$0 \le N_K &lt; \cdots &lt; N_2 &lt; N_1 \le 1000$</span>. </p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case you should output the product of <span>$A$</span> and <span>$B$</span> in one line, with the same format as the input. Notice that there must be <strong>NO</strong> extra space at the end of each line. Please be accurate up to 1 decimal place. </p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">2 1 2.4 0 3.2
2 2 1.5 1 0.5
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">3 3 3.6 2 6.0 1 1.6
</code></pre>
</div>{% endraw %}
This time, you are supposed to find $A\times B$ where $A$ and $B$ are two
polynomials.
### Input Specification:
Each input file contains one test case. Each case occupies 2 lines, and each
line contains the information of a polynomial:
$K$ $N_1$ $a_{N_1}$ $N_2$ $a_{N_2}$ ... $N_K$ $a_{N_K}$
where $K$ is the number of nonzero terms in the polynomial, $N_i$ and
$a_{N_i}$ ( $i=1, 2, \cdots , K$ ) are the exponents and coefficients,
respectively. It is given that $1\le K \le 10$ , $0 \le N_K < \cdots < N_2 <
N_1 \le 1000$ .
### Output Specification:
For each test case you should output the product of $A$ and $B$ in one line,
with the same format as the input. Notice that there must be **NO** extra
space at the end of each line. Please be accurate up to 1 decimal place.
### Sample Input:
2 1 2.4 0 3.2
2 2 1.5 1 0.5
### Sample Output:
3 3 3.6 2 6.0 1 1.6
## 思路
+58 -22
View File
@@ -9,29 +9,65 @@ permalink: Advanced/1010.html
## 题目
{% raw %}<div class="ques-view"><p>Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is <code>yes</code>, if 6 is a decimal number and 110 is a binary number.</p>
<p>Now for any pair of positive integers <span>$N_1$</span> and <span>$N_2$</span>, your task is to find the radix of one number while that of the other is given.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case occupies a line which contains 4 positive integers:</p>
<pre><code>
N1 N2 tag radix
Given a pair of positive integers, for example, 6 and 110, can this equation 6
= 110 be true? The answer is `yes`, if 6 is a decimal number and 110 is a
binary number.
Now for any pair of positive integers $N_1$ and $N_2$ , your task is to find
the radix of one number while that of the other is given.
### Input Specification:
Each input file contains one test case. Each case occupies a line which
contains 4 positive integers:
N1 N2 tag radix
Here `N1` and `N2` each has no more than 10 digits. A digit is less than its
radix and is chosen from the set { 0-9, `a`-`z` } where 0-9 represent the
decimal numbers 0-9, and `a`-`z` represent the decimal numbers 10-35. The last
number `radix` is the radix of `N1` if `tag` is 1, or of `N2` if `tag` is 2.
### Output Specification:
For each test case, print in one line the radix of the other number so that
the equation `N1` = `N2` is true. If the equation is impossible, print
`Impossible`. If the solution is not unique, output the smallest possible
radix.
### Sample Input 1:
6 110 1 10
### Sample Output 1:
2
### Sample Input 2:
1 ab 1 2
### Sample Output 2:
Impossible
</code></pre><p>Here <code>N1</code> and <code>N2</code> each has no more than 10 digits. A digit is less than its radix and is chosen from the set { 0-9, <code>a</code>-<code>z</code> } where 0-9 represent the decimal numbers 0-9, and <code>a</code>-<code>z</code> represent the decimal numbers 10-35. The last number <code>radix</code> is the radix of <code>N1</code> if <code>tag</code> is 1, or of <code>N2</code> if <code>tag</code> is 2.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line the radix of the other number so that the equation <code>N1</code> = <code>N2</code> is true. If the equation is impossible, print <code>Impossible</code>. If the solution is not unique, output the smallest possible radix.</p>
<h3 id="sample-input-1-">Sample Input 1:</h3>
<pre><code class="lang-in">6 110 1 10
</code></pre>
<h3 id="sample-output-1-">Sample Output 1:</h3>
<pre><code class="lang-out">2
</code></pre>
<h3 id="sample-input-2-">Sample Input 2:</h3>
<pre><code class="lang-in">1 ab 1 2
</code></pre>
<h3 id="sample-output-2-">Sample Output 2:</h3>
<pre><code class="lang-out">Impossible
</code></pre>
</div>{% endraw %}
## 思路
+56 -21
View File
@@ -9,27 +9,62 @@ permalink: Advanced/1011.html
## 题目
{% raw %}<div class="ques-view"><p>With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.</p>
<p>Chinese Football Lottery provided a "Triple Winning" game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results -- namely <code>W</code> for win, <code>T</code> for tie, and <code>L</code> for lose. There was an odd assigned to each result. The winner's odd would be the product of the three odds times 65%.</p>
<p>For example, 3 games' odds are given as the following:</p>
<pre><code> W T L
1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
</code></pre><p>To obtain the maximum profit, one must buy <code>W</code> for the 3rd game, <code>T</code> for the 2nd game, and <code>T</code> for the 1st game. If each bet takes 2 yuans, then the maximum profit would be <span>$(4.1\times 3.1\times 2.5\times 65\%-1)\times 2 = 39.31$</span> yuans (accurate up to 2 decimal places).</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to <code>W</code>, <code>T</code> and <code>L</code>.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">T T W 39.31
</code></pre>
</div>{% endraw %}
With the 2010 FIFA World Cup running, football fans the world over were
becoming increasingly excited as the best players from the best teams doing
battles for the World Cup trophy in South Africa. Similarly, football betting
fans were putting their money where their mouths were, by laying all manner of
World Cup bets.
Chinese Football Lottery provided a "Triple Winning" game. The rule of winning
was simple: first select any three of the games. Then for each selected game,
bet on one of the three possible results -- namely `W` for win, `T` for tie,
and `L` for lose. There was an odd assigned to each result. The winner's odd
would be the product of the three odds times 65%.
For example, 3 games' odds are given as the following:
W T L
1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
To obtain the maximum profit, one must buy `W` for the 3rd game, `T` for the
2nd game, and `T` for the 1st game. If each bet takes 2 yuans, then the
maximum profit would be $(4.1\times 3.1\times 2.5\times 65\%-1)\times 2 =
39.31$ yuans (accurate up to 2 decimal places).
### Input Specification:
Each input file contains one test case. Each case contains the betting
information of 3 games. Each game occupies a line with three distinct odds
corresponding to `W`, `T` and `L`.
### Output Specification:
For each test case, print in one line the best bet of each game, and the
maximum profit accurate up to 2 decimal places. The characters and the number
must be separated by one space.
### Sample Input:
1.1 2.5 1.7
1.2 3.1 1.6
4.1 1.2 1.1
### Sample Output:
T T W 39.31
## 思路
+75 -37
View File
@@ -9,43 +9,81 @@ permalink: Advanced/1012.html
## 题目
{% raw %}<div class="ques-view"><p>To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: <code>C</code> - C Programming Language, <code>M</code> - Mathematics (Calculus or Linear Algrbra), and <code>E</code> - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.</p>
<p>For example, The grades of <code>C</code>, <code>M</code>, <code>E</code> and <code>A</code> - Average of 4 students are given as the following:</p>
<pre><code>StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
</code></pre><p>Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case starts with a line containing 2 numbers <span>$N$</span> and <span>$M$</span> (<span>$\le 2000$</span>), which are the total number of students, and the number of students who would check their ranks, respectively. Then <span>$N$</span> lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of <code>C</code>, <code>M</code> and <code>E</code>. Then there are <span>$M$</span> lines, each containing a student ID.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each of the <span>$M$</span> students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.</p>
<p>The priorities of the ranking methods are ordered as <code>A</code> <span>$&gt;$</span> <code>C</code> <span>$&gt;$</span> <code>M</code> <span>$&gt;$</span> <code>E</code>. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.</p>
<p>If a student is not on the grading list, simply output <code>N/A</code>.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">1 C
1 M
1 E
1 A
3 A
N/A
</code></pre>
</div>{% endraw %}
To evaluate the performance of our first year CS majored students, we consider
their grades of three courses only: `C` \- C Programming Language, `M` \-
Mathematics (Calculus or Linear Algrbra), and `E` \- English. At the mean
time, we encourage students by emphasizing on their best ranks -- that is,
among the four ranks with respect to the three courses and the average grade,
we print the best rank for each student.
For example, The grades of `C`, `M`, `E` and `A` \- Average of 4 students are
given as the following:
StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done
the best in C Programming Language, while the 2nd one in Mathematics, the 3rd
one in English, and the last one in average.
### Input Specification:
Each input file contains one test case. Each case starts with a line
containing 2 numbers $N$ and $M$ ( $\le 2000$ ), which are the total number of
students, and the number of students who would check their ranks,
respectively. Then $N$ lines follow, each contains a student ID which is a
string of 6 digits, followed by the three integer grades (in the range of [0,
100]) of that student in the order of `C`, `M` and `E`. Then there are $M$
lines, each containing a student ID.
### Output Specification:
For each of the $M$ students, print in one line the best rank for him/her, and
the symbol of the corresponding rank, separated by a space.
The priorities of the ranking methods are ordered as `A` $>$ `C` $>$ `M` $>$
`E`. Hence if there are two or more ways for a student to obtain the same best
rank, output the one with the highest priority.
If a student is not on the grading list, simply output `N/A`.
### Sample Input:
5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999
### Sample Output:
1 C
1 M
1 E
1 A
3 A
N/A
## 思路
+46 -18
View File
@@ -9,24 +9,52 @@ permalink: Advanced/1013.html
## 题目
{% raw %}<div class="ques-view"><p>It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any other highways to keep the rest of the cities connected. Given the map of cities which have all the remaining highways marked, you are supposed to tell the number of highways need to be repaired, quickly.</p>
<p>For example, if we have 3 cities and 2 highways connecting <span>$city_1$</span>-<span>$city_2$</span> and <span>$city_1$</span>-<span>$city_3$</span>. Then if <span>$city_1$</span> is occupied by the enemy, we must have 1 highway repaired, that is the highway <span>$city_2$</span>-<span>$city_3$</span>.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case starts with a line containing 3 numbers <span>$N$</span> (<span>$&lt;1000$</span>), <span>$M$</span> and <span>$K$</span>, which are the total number of cities, the number of remaining highways, and the number of cities to be checked, respectively. Then <span>$M$</span> lines follow, each describes a highway by 2 integers, which are the numbers of the cities the highway connects. The cities are numbered from 1 to <span>$N$</span>. Finally there is a line containing <span>$K$</span> numbers, which represent the cities we concern.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each of the <span>$K$</span> cities, output in a line the number of highways need to be repaired if that city is lost.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">3 2 3
1 2
1 3
1 2 3
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">1
0
0
</code></pre>
</div>{% endraw %}
It is vitally important to have all the cities connected by highways in a war.
If a city is occupied by the enemy, all the highways from/toward that city are
closed. We must know immediately if we need to repair any other highways to
keep the rest of the cities connected. Given the map of cities which have all
the remaining highways marked, you are supposed to tell the number of highways
need to be repaired, quickly.
For example, if we have 3 cities and 2 highways connecting $city_1$ - $city_2$
and $city_1$ - $city_3$ . Then if $city_1$ is occupied by the enemy, we must
have 1 highway repaired, that is the highway $city_2$ - $city_3$ .
### Input Specification:
Each input file contains one test case. Each case starts with a line
containing 3 numbers $N$ ( $<1000$ ), $M$ and $K$ , which are the total number
of cities, the number of remaining highways, and the number of cities to be
checked, respectively. Then $M$ lines follow, each describes a highway by 2
integers, which are the numbers of the cities the highway connects. The cities
are numbered from 1 to $N$ . Finally there is a line containing $K$ numbers,
which represent the cities we concern.
### Output Specification:
For each of the $K$ cities, output in a line the number of highways need to be
repaired if that city is lost.
### Sample Input:
3 2 3
1 2
1 3
1 2 3
### Sample Output:
1
0
0
## 思路
+69 -29
View File
@@ -9,35 +9,75 @@ permalink: Advanced/1014.html
## 题目
{% raw %}<div class="ques-view"><p>Suppose a bank has <span>$N$</span> windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the customers to wait in line are:</p>
<ul>
<li>The space inside the yellow line in front of each window is enough to contain a line with <span>$M$</span> customers. Hence when all the <span>$N$</span> lines are full, all the customers after (and including) the <span>$(NM+1)$</span>st one will have to wait in a line behind the yellow line.</li>
<li>Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.</li>
<li><span>$Customer_i$</span> will take <span>$T_i$</span> minutes to have his/her transaction processed.</li>
<li>The first <span>$N$</span> customers are assumed to be served at 8:00am.</li>
</ul>
<p>Now given the processing time of each customer, you are supposed to tell the exact time at which a customer has his/her business done.</p>
<p>For example, suppose that a bank has 2 windows and each window may have 2 custmers waiting inside the yellow line. There are 5 customers waiting with transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the morning, <span>$customer_1$</span> is served at <span>$window_1$</span> while <span>$customer_2$</span> is served at <span>$window_2$</span>. <span>$Customer_3$</span> will wait in front of <span>$window_1$</span> and <span>$customer_4$</span> will wait in front of <span>$window_2$</span>. <span>$Customer_5$</span> will wait behind the yellow line.</p>
<p>At 08:01, <span>$customer_1$</span> is done and <span>$customer_5$</span> enters the line in front of <span>$window_1$</span> since that line seems shorter now. <span>$Customer_2$</span> will leave at 08:02, <span>$customer_4$</span> at 08:06, <span>$customer_3$</span> at 08:07, and finally <span>$customer_5$</span> at 08:10.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case starts with a line containing 4 positive integers: <span>$N$</span> (<span>$\le 20$</span>, number of windows), <span>$M$</span> (<span>$\le 10$</span>, the maximum capacity of each line inside the yellow line), <span>$K$</span> (<span>$\le 1000$</span>, number of customers), and <span>$Q$</span> (<span>$\le 1000$</span>, number of customer queries).</p>
<p>The next line contains <span>$K$</span> positive integers, which are the processing time of the <span>$K$</span> customers.</p>
<p>The last line contains <span>$Q$</span> positive integers, which represent the customers who are asking about the time they can have their transactions done. The customers are numbered from 1 to <span>$K$</span>.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each of the <span>$Q$</span> customers, print in one line the time at which his/her transaction is finished, in the format <code>HH:MM</code> where <code>HH</code> is in [08, 17] and <code>MM</code> is in [00, 59]. Note that since the bank is closed everyday after 17:00, for those customers who cannot be served before 17:00, you must output <code>Sorry</code> instead.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">08:07
08:06
08:10
17:00
Sorry
</code></pre>
</div>{% endraw %}
Suppose a bank has $N$ windows open for service. There is a yellow line in
front of the windows which devides the waiting area into two parts. The rules
for the customers to wait in line are:
* The space inside the yellow line in front of each window is enough to contain a line with $M$ customers. Hence when all the $N$ lines are full, all the customers after (and including) the $(NM+1)$ st one will have to wait in a line behind the yellow line.
* Each customer will choose the shortest line to wait in when crossing the yellow line. If there are two or more lines with the same length, the customer will always choose the window with the smallest number.
* $Customer_i$ will take $T_i$ minutes to have his/her transaction processed.
* The first $N$ customers are assumed to be served at 8:00am.
Now given the processing time of each customer, you are supposed to tell the
exact time at which a customer has his/her business done.
For example, suppose that a bank has 2 windows and each window may have 2
custmers waiting inside the yellow line. There are 5 customers waiting with
transactions taking 1, 2, 6, 4 and 3 minutes, respectively. At 08:00 in the
morning, $customer_1$ is served at $window_1$ while $customer_2$ is served at
$window_2$ . $Customer_3$ will wait in front of $window_1$ and $customer_4$
will wait in front of $window_2$ . $Customer_5$ will wait behind the yellow
line.
At 08:01, $customer_1$ is done and $customer_5$ enters the line in front of
$window_1$ since that line seems shorter now. $Customer_2$ will leave at
08:02, $customer_4$ at 08:06, $customer_3$ at 08:07, and finally $customer_5$
at 08:10.
### Input Specification:
Each input file contains one test case. Each case starts with a line
containing 4 positive integers: $N$ ( $\le 20$ , number of windows), $M$ (
$\le 10$ , the maximum capacity of each line inside the yellow line), $K$ (
$\le 1000$ , number of customers), and $Q$ ( $\le 1000$ , number of customer
queries).
The next line contains $K$ positive integers, which are the processing time of
the $K$ customers.
The last line contains $Q$ positive integers, which represent the customers
who are asking about the time they can have their transactions done. The
customers are numbered from 1 to $K$ .
### Output Specification:
For each of the $Q$ customers, print in one line the time at which his/her
transaction is finished, in the format `HH:MM` where `HH` is in [08, 17] and
`MM` is in [00, 59]. Note that since the bank is closed everyday after 17:00,
for those customers who cannot be served before 17:00, you must output `Sorry`
instead.
### Sample Input:
2 2 7 5
1 2 6 4 3 534 2
3 4 5 6 7
### Sample Output:
08:07
08:06
08:10
17:00
Sorry
## 思路
+37 -18
View File
@@ -9,24 +9,43 @@ permalink: Advanced/1015.html
## 题目
{% raw %}<div class="ques-view"><p>A <strong>reversible prime</strong> in any number system is a prime whose "reverse" in that number system is also a prime. For example in the decimal system 73 is a reversible prime because its reverse 37 is also a prime.</p>
<p>Now given any two positive integers <span>$N$</span> (<span>$&lt; 10^5$</span>) and <span>$D$</span> (<span>$1 &lt; D \le 10$</span>), you are supposed to tell if <span>$N$</span> is a reversible prime with radix <span>$D$</span>.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>The input file consists of several test cases. Each case occupies a line which contains two integers <span>$N$</span> and <span>$D$</span>. The input is finished by a negative <span>$N$</span>.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line <code>Yes</code> if <span>$N$</span> is a reversible prime with radix <span>$D$</span>, or <code>No</code> if not.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">73 10
23 2
23 10
-2
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">Yes
Yes
No
</code></pre>
</div>{% endraw %}
A **reversible prime** in any number system is a prime whose "reverse" in that
number system is also a prime. For example in the decimal system 73 is a
reversible prime because its reverse 37 is also a prime.
Now given any two positive integers $N$ ( $< 10^5$ ) and $D$ ( $1 < D \le 10$
), you are supposed to tell if $N$ is a reversible prime with radix $D$ .
### Input Specification:
The input file consists of several test cases. Each case occupies a line which
contains two integers $N$ and $D$ . The input is finished by a negative $N$ .
### Output Specification:
For each test case, print in one line `Yes` if $N$ is a reversible prime with
radix $D$ , or `No` if not.
### Sample Input:
73 10
23 2
23 10
-2
### Sample Output:
Yes
Yes
No
## 思路
+80 -37
View File
@@ -9,43 +9,86 @@ permalink: Advanced/1016.html
## 题目
{% raw %}<div class="ques-view"><p>A long-distance telephone company charges its customers by the following rules:</p>
<p>Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When a customer starts connecting a long-distance call, the time will be recorded, and so will be the time when the customer hangs up the phone. Every calendar month, a bill is sent to the customer for each minute called (at a rate determined by the time of day). Your job is to prepare the bills for each month, given a set of phone call records.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. Each case has two parts: the rate structure, and the phone call records.</p>
<p>The rate structure consists of a line with 24 non-negative integers denoting the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and so on for each hour in the day.</p>
<p>The next line contains a positive number <span>$N$</span> (<span>$\le 1000$</span>), followed by <span>$N$</span> lines of records. Each phone call record consists of the name of the customer (string of up to 20 characters without space), the time and date (<code>mm:dd:hh:mm</code>), and the word <code>on-line</code> or <code>off-line</code>.</p>
<p>For each test case, all dates will be within a single month. Each <code>on-line</code> record is paired with the chronologically next record for the same customer provided it is an <code>off-line</code> record. Any <code>on-line</code> records that are not paired with an <code>off-line</code> record are ignored, as are <code>off-line</code> records not paired with an <code>on-line</code> record. It is guaranteed that at least one call is well paired in the input. You may assume that no two records for the same customer have the same time. Times are recorded using a 24-hour clock.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, you must print a phone bill for each customer.</p>
<p>Bills must be printed in alphabetical order of customers' names. For each customer, first print in a line the name of the customer and the month of the bill in the format shown by the sample. Then for each time period of a call, print in one line the beginning and ending time and date (<code>dd:hh:mm</code>), the lasting time (in minute) and the charge of the call. The calls must be listed in chronological order. Finally, print the total charge for the month in the format shown by the sample.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
10
CYLL 01:01:06:01 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:07:00 off-line
CYLL 01:01:08:03 off-line
CYJJ 01:01:05:59 on-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
CYLL 01:28:15:41 on-line
aaa 01:05:02:24 on-line
aaa 01:04:23:59 off-line
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10
CYLL 01
01:06:01 01:08:03 122 $24.40
28:15:41 28:16:05 24 $3.85
Total amount: $28.25
aaa 01
02:00:01 04:23:59 4318 $638.80
Total amount: $638.80
</code></pre>
</div>{% endraw %}
A long-distance telephone company charges its customers by the following
rules:
Making a long-distance call costs a certain amount per minute, depending on
the time of day when the call is made. When a customer starts connecting a
long-distance call, the time will be recorded, and so will be the time when
the customer hangs up the phone. Every calendar month, a bill is sent to the
customer for each minute called (at a rate determined by the time of day).
Your job is to prepare the bills for each month, given a set of phone call
records.
### Input Specification:
Each input file contains one test case. Each case has two parts: the rate
structure, and the phone call records.
The rate structure consists of a line with 24 non-negative integers denoting
the toll (cents/minute) from 00:00 - 01:00, the toll from 01:00 - 02:00, and
so on for each hour in the day.
The next line contains a positive number $N$ ( $\le 1000$ ), followed by $N$
lines of records. Each phone call record consists of the name of the customer
(string of up to 20 characters without space), the time and date
(`mm:dd:hh:mm`), and the word `on-line` or `off-line`.
For each test case, all dates will be within a single month. Each `on-line`
record is paired with the chronologically next record for the same customer
provided it is an `off-line` record. Any `on-line` records that are not paired
with an `off-line` record are ignored, as are `off-line` records not paired
with an `on-line` record. It is guaranteed that at least one call is well
paired in the input. You may assume that no two records for the same customer
have the same time. Times are recorded using a 24-hour clock.
### Output Specification:
For each test case, you must print a phone bill for each customer.
Bills must be printed in alphabetical order of customers' names. For each
customer, first print in a line the name of the customer and the month of the
bill in the format shown by the sample. Then for each time period of a call,
print in one line the beginning and ending time and date (`dd:hh:mm`), the
lasting time (in minute) and the charge of the call. The calls must be listed
in chronological order. Finally, print the total charge for the month in the
format shown by the sample.
### Sample Input:
10 10 10 10 10 10 20 20 20 15 15 15 15 15 15 15 20 30 20 15 15 10 10 10
10
CYLL 01:01:06:01 on-line
CYLL 01:28:16:05 off-line
CYJJ 01:01:07:00 off-line
CYLL 01:01:08:03 off-line
CYJJ 01:01:05:59 on-line
aaa 01:01:01:03 on-line
aaa 01:02:00:01 on-line
CYLL 01:28:15:41 on-line
aaa 01:05:02:24 on-line
aaa 01:04:23:59 off-line
### Sample Output:
CYJJ 01
01:05:59 01:07:00 61 $12.10
Total amount: $12.10
CYLL 01
01:06:01 01:08:03 122 $24.40
28:15:41 28:16:05 24 $3.85
Total amount: $28.25
aaa 01
02:00:01 04:23:59 4318 $638.80
Total amount: $638.80
## 思路
+49 -21
View File
@@ -9,27 +9,55 @@ permalink: Advanced/1017.html
## 题目
{% raw %}<div class="ques-view"><p>Suppose a bank has <span>$K$</span> windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. All the customers have to wait in line behind the yellow line, until it is his/her turn to be served and there is a window available. It is assumed that no window can be occupied by a single customer for more than 1 hour.</p>
<p>Now given the arriving time <span>$T$</span> and the processing time <span>$P$</span> of each customer, you are supposed to tell the average waiting time of all the customers.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. For each case, the first line contains 2 numbers: <span>$N$</span> (<span>$\le 10^4$</span>) - the total number of customers, and <span>$K$</span> (<span>$\le 100$</span>) - the number of windows. Then <span>$N$</span> lines follow, each contains 2 times: <code>HH:MM:SS</code> - the arriving time, and <span>$P$</span> - the processing time in minutes of a customer. Here <code>HH</code> is in the range [00, 23], <code>MM</code> and <code>SS</code> are both in [00, 59]. It is assumed that no two customers arrives at the same time.</p>
<p>Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have to wait in line till 08:00, and anyone comes too late (at or after 17:00:01) will not be served nor counted into the average.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line the average waiting time of all the customers, in minutes and accurate up to 1 decimal place.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">8.2
</code></pre>
</div>{% endraw %}
Suppose a bank has $K$ windows open for service. There is a yellow line in
front of the windows which devides the waiting area into two parts. All the
customers have to wait in line behind the yellow line, until it is his/her
turn to be served and there is a window available. It is assumed that no
window can be occupied by a single customer for more than 1 hour.
Now given the arriving time $T$ and the processing time $P$ of each customer,
you are supposed to tell the average waiting time of all the customers.
### Input Specification:
Each input file contains one test case. For each case, the first line contains
2 numbers: $N$ ( $\le 10^4$ ) - the total number of customers, and $K$ ( $\le
100$ ) - the number of windows. Then $N$ lines follow, each contains 2 times:
`HH:MM:SS` \- the arriving time, and $P$ - the processing time in minutes of a
customer. Here `HH` is in the range [00, 23], `MM` and `SS` are both in [00,
59]. It is assumed that no two customers arrives at the same time.
Notice that the bank opens from 08:00 to 17:00. Anyone arrives early will have
to wait in line till 08:00, and anyone comes too late (at or after 17:00:01)
will not be served nor counted into the average.
### Output Specification:
For each test case, print in one line the average waiting time of all the
customers, in minutes and accurate up to 1 decimal place.
### Sample Input:
7 3
07:55:00 16
17:00:01 2
07:59:59 15
08:01:00 60
08:00:00 30
08:00:02 2
08:03:00 10
### Sample Output:
8.2
## 思路
+34 -14
View File
@@ -9,20 +9,40 @@ permalink: Advanced/1020.html
## 题目
{% raw %}<div class="ques-view"><p>Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal sequence of the corresponding binary tree.</p>
<h3 id="input-specification-">Input Specification:</h3>
<p>Each input file contains one test case. For each case, the first line gives a positive integer <span>$N$</span> (<span>$\le 30$</span>), the total number of nodes in the binary tree. The second line gives the postorder sequence and the third line gives the inorder sequence. All the numbers in a line are separated by a space.</p>
<h3 id="output-specification-">Output Specification:</h3>
<p>For each test case, print in one line the level order traversal sequence of the corresponding binary tree. All the numbers in a line must be separated by exactly one space, and there must be no extra space at the end of the line.</p>
<h3 id="sample-input-">Sample Input:</h3>
<pre><code class="lang-in">7
2 3 1 5 7 6 4
1 2 3 4 5 6 7
</code></pre>
<h3 id="sample-output-">Sample Output:</h3>
<pre><code class="lang-out">4 1 6 3 5 7 2
</code></pre>
</div>{% endraw %}
Suppose that all the keys in a binary tree are distinct positive integers.
Given the postorder and inorder traversal sequences, you are supposed to
output the level order traversal sequence of the corresponding binary tree.
### Input Specification:
Each input file contains one test case. For each case, the first line gives a
positive integer $N$ ( $\le 30$ ), the total number of nodes in the binary
tree. The second line gives the postorder sequence and the third line gives
the inorder sequence. All the numbers in a line are separated by a space.
### Output Specification:
For each test case, print in one line the level order traversal sequence of
the corresponding binary tree. All the numbers in a line must be separated by
exactly one space, and there must be no extra space at the end of the line.
### Sample Input:
7
2 3 1 5 7 6 4
1 2 3 4 5 6 7
### Sample Output:
4 1 6 3 5 7 2
## 思路
+32 -14
View File
@@ -9,20 +9,38 @@ permalink: Basic/1001.html
## 题目
{% raw %}<div class="ques-view"><p>卡拉兹(Callatz)猜想:</p>
<p>对任何一个正整数 <span>$n$</span>,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 <span>$(3n+1)$</span> 砍掉一半。这样一直反复砍下去,最后一定在某一步得到 <span>$n=1$</span>。卡拉兹在 1950 年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证 <span>$(3n+1)$</span>,以至于有人说这是一个阴谋,卡拉兹是在蓄意延缓美国数学界教学与科研的进展……</p>
<p>我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过 1000 的正整数 <span>$n$</span>,简单地数一下,需要多少步(砍几下)才能得到 <span>$n=1$</span>?</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例,即给出正整数 <span>$n$</span> 的值。</p>
<h3 id="-">输出格式:</h3>
<p>输出从 <span>$n$</span> 计算到 1 需要的步数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5
</code></pre>
</div>{% endraw %}
卡拉兹(Callatz)猜想:
对任何一个正整数 $n$ ,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 $(3n+1)$ 砍掉一半。这样一直反复砍下去,最后一定在某一步得到
$n=1$ 。卡拉兹在 1950
年的世界数学家大会上公布了这个猜想,传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,结果闹得学生们无心学业,一心只证 $(3n+1)$
,以至于有人说这是一个阴谋,卡拉兹是在蓄意延缓美国数学界教学与科研的进展……
我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过 1000 的正整数 $n$ ,简单地数一下,需要多少步(砍几下)才能得到 $n=1$ ?
### 输入格式:
每个测试输入包含 1 个测试用例,即给出正整数 $n$ 的值。
### 输出格式:
输出从 $n$ 计算到 1 需要的步数。
### 输入样例:
3
### 输出样例:
5
## 思路
+25 -12
View File
@@ -9,18 +9,31 @@ permalink: Basic/1002.html
## 题目
{% raw %}<div class="ques-view"><p>读入一个正整数 <span>$n$</span>,计算其各位数字之和,用汉语拼音写出和的每一位数字。</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例,即给出自然数 <span>$n$</span> 的值。这里保证 <span>$n$</span> 小于 <span>$10^{100}$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行内输出 <span>$n$</span> 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">1234567890987654321123456789
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">yi san wu
</code></pre>
</div>{% endraw %}
读入一个正整数 $n$ ,计算其各位数字之和,用汉语拼音写出和的每一位数字。
### 输入格式:
每个测试输入包含 1 个测试用例,即给出自然数 $n$ 的值。这里保证 $n$ 小于 $10^{100}$ 。
### 输出格式:
在一行内输出 $n$ 的各位数字之和的每一位,拼音数字间有 1 空格,但一行中最后一个拼音数字后没有空格。
### 输入样例:
1234567890987654321123456789
### 输出样例:
yi san wu
## 思路
+50 -34
View File
@@ -9,40 +9,56 @@ permalink: Basic/1003.html
## 题目
{% raw %}<div class="ques-view"><p>“<strong>答案正确</strong>”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“<strong>答案正确</strong>”大派送 —— 只要读入的字符串满足下列条件,系统就输出“<strong>答案正确</strong>”,否则输出“<strong>答案错误</strong>”。</p>
<p>得到“<strong>答案正确</strong>”的条件是:</p>
<ol>
<li>字符串中必须仅有 <code>P</code>、 <code>A</code>、 <code>T</code>这三种字符,不可以包含其它字符;</li>
<li>任意形如 <code>xPATx</code> 的字符串都可以获得“<strong>答案正确</strong>”,其中 <code>x</code> 或者是空字符串,或者是仅由字母 <code>A</code> 组成的字符串;</li>
<li>如果 <code>aPbTc</code> 是正确的,那么 <code>aPbATca</code> 也是正确的,其中 <code>a</code>、 <code>b</code>、 <code>c</code> 均或者是空字符串,或者是仅由字母 <code>A</code> 组成的字符串。</li>
</ol>
<p>现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“<strong>答案正确</strong>”的。</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 <span>$n$</span> (<span>$&lt;10$</span>),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过 100,且不包含空格。</p>
<h3 id="-">输出格式:</h3>
<p>每个字符串的检测结果占一行,如果该字符串可以获得“<strong>答案正确</strong>”,则输出 <code>YES</code>,否则输出 <code>NO</code>。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">8
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">YES
YES
YES
YES
NO
NO
NO
NO
</code></pre>
</div>{% endraw %}
“ **答案正确** ”是自动判题系统给出的最令人欢喜的回复。本题属于 PAT 的“ **答案正确** ”大派送 ——
只要读入的字符串满足下列条件,系统就输出“ **答案正确** ”,否则输出“ **答案错误** ”。
得到“ **答案正确** ”的条件是:
1. 字符串中必须仅有 `P`、 `A`、 `T`这三种字符,不可以包含其它字符;
2. 任意形如 `xPATx` 的字符串都可以获得“ **答案正确** ”,其中 `x` 或者是空字符串,或者是仅由字母 `A` 组成的字符串;
3. 如果 `aPbTc` 是正确的,那么 `aPbATca` 也是正确的,其中 `a`、 `b`、 `c` 均或者是空字符串,或者是仅由字母 `A` 组成的字符串。
现在就请你为 PAT 写一个自动裁判程序,判定哪些字符串是可以获得“ **答案正确** ”的。
### 输入格式:
每个测试输入包含 1 个测试用例。第 1 行给出一个正整数 $n$ ( $<10$ ),是需要检测的字符串个数。接下来每个字符串占一行,字符串长度不超过
100,且不包含空格。
### 输出格式:
每个字符串的检测结果占一行,如果该字符串可以获得“ **答案正确** ”,则输出 `YES`,否则输出 `NO`。
### 输入样例:
8
PAT
PAAT
AAPATAA
AAPAATAAAA
xPATx
PT
Whatever
APAAATAA
### 输出样例:
YES
YES
YES
YES
NO
NO
NO
NO
## 思路
+40 -22
View File
@@ -9,28 +9,46 @@ permalink: Basic/1004.html
## 题目
{% raw %}<div class="ques-view"><p>读入 <span>$n$</span>(<span>$&gt;0$</span>)名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例,格式为</p>
<pre><code>第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩
</code></pre><p>其中<code>姓名</code>和<code>学号</code>均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。</p>
<h3 id="-">输出格式:</h3>
<p>对每个测试用例输出 2 行,第 1 行是成绩最高学生的姓名和学号,第 2 行是成绩最低学生的姓名和学号,字符串间有 1 空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">Mike CS991301
Joe Math990112
</code></pre>
</div>{% endraw %}
读入 $n$ ( $>0$ )名学生的姓名、学号、成绩,分别输出成绩最高和成绩最低学生的姓名和学号。
### 输入格式:
每个测试输入包含 1 个测试用例,格式为
第 1 行:正整数 n
第 2 行:第 1 个学生的姓名 学号 成绩
第 3 行:第 2 个学生的姓名 学号 成绩
... ... ...
第 n+1 行:第 n 个学生的姓名 学号 成绩
其中`姓名`和`学号`均为不超过 10 个字符的字符串,成绩为 0 到 100 之间的一个整数,这里保证在一组测试用例中没有两个学生的成绩是相同的。
### 输出格式:
对每个测试用例输出 2 行,第 1 行是成绩最高学生的姓名和学号,第 2 行是成绩最低学生的姓名和学号,字符串间有 1 空格。
### 输入样例:
3
Joe Math990112 89
Mike CS991301 100
Mary EE990830 95
### 输出样例:
Mike CS991301
Joe Math990112
## 思路
+34 -15
View File
@@ -9,21 +9,40 @@ permalink: Basic/1005.html
## 题目
{% raw %}<div class="ques-view"><p>卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。</p>
<p>当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对 <span>$n=3$</span> 进行验证的时候,我们需要计算 3、5、8、4、2、1,则当我们对 <span>$n=5$</span>、8、4、2 进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这 4 个数已经在验证3的时候遇到过了,我们称 5、8、4、2 是被 3“覆盖”的数。我们称一个数列中的某个数 <span>$n$</span> 为“关键数”,如果 <span>$n$</span> 不能被数列中的其他数字所覆盖。</p>
<p>现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例,第 1 行给出一个正整数 <span>$K$</span> (<span>$&lt;100$</span>),第 2 行给出 <span>$K$</span> 个互不相同的待验证的正整数 <span>$n$</span> (<span>$1&lt;n\le 100$</span>)的值,数字间用空格隔开。</p>
<h3 id="-">输出格式:</h3>
<p>每个测试用例的输出占一行,按从大到小的顺序输出关键数字。数字间用 1 个空格隔开,但一行中最后一个数字后没有空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6
3 5 6 7 8 11
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">7 6
</code></pre>
</div>{% endraw %}
卡拉兹(Callatz)猜想已经在1001中给出了描述。在这个题目里,情况稍微有些复杂。
当我们验证卡拉兹猜想的时候,为了避免重复计算,可以记录下递推过程中遇到的每一个数。例如对 $n=3$ 进行验证的时候,我们需要计算
3、5、8、4、2、1,则当我们对 $n=5$ 、8、4、2 进行验证的时候,就可以直接判定卡拉兹猜想的真伪,而不需要重复计算,因为这 4
个数已经在验证3的时候遇到过了,我们称 5、8、4、2 是被 3“覆盖”的数。我们称一个数列中的某个数 $n$ 为“关键数”,如果 $n$
不能被数列中的其他数字所覆盖。
现在给定一系列待验证的数字,我们只需要验证其中的几个关键数,就可以不必再重复验证余下的数字。你的任务就是找出这些关键数字,并按从大到小的顺序输出它们。
### 输入格式:
每个测试输入包含 1 个测试用例,第 1 行给出一个正整数 $K$ ( $<100$ ),第 2 行给出 $K$ 个互不相同的待验证的正整数 $n$ (
$1<n\le 100$ )的值,数字间用空格隔开。
### 输出格式:
每个测试用例的输出占一行,按从大到小的顺序输出关键数字。数字间用 1 个空格隔开,但一行中最后一个数字后没有空格。
### 输入样例:
6
3 5 6 7 8 11
### 输出样例:
7 6
## 思路
+41 -18
View File
@@ -9,24 +9,47 @@ permalink: Basic/1006.html
## 题目
{% raw %}<div class="ques-view"><p>让我们用字母 <code>B</code> 来表示“百”、字母 <code>S</code> 表示“十”,用 <code>12...n</code> 来表示不为零的个位数字 <code>n</code>(<span>$&lt;10$</span>),换个格式来输出任一个不超过 3 位的正整数。例如 <code>234</code> 应该被输出为 <code>BBSSS1234</code>,因为它有 2 个“百”、3 个“十”、以及个位的 4。</p>
<h3 id="-">输入格式:</h3>
<p>每个测试输入包含 1 个测试用例,给出正整数 <span>$n$</span>(<span>$&lt;1000$</span>)。</p>
<h3 id="-">输出格式:</h3>
<p>每个测试用例的输出占一行,用规定的格式输出 <span>$n$</span>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">234
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">BBSSS1234
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">23
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">SS123
</code></pre>
</div>{% endraw %}
让我们用字母 `B` 来表示“百”、字母 `S` 表示“十”,用 `12...n` 来表示不为零的个位数字 `n`( $<10$
),换个格式来输出任一个不超过 3 位的正整数。例如 `234` 应该被输出为 `BBSSS1234`,因为它有 2 个“百”、3 个“十”、以及个位的
4。
### 输入格式:
每个测试输入包含 1 个测试用例,给出正整数 $n$ ( $<1000$ )。
### 输出格式:
每个测试用例的输出占一行,用规定的格式输出 $n$ 。
### 输入样例 1:
234
### 输出样例 1:
BBSSS1234
### 输入样例 2:
23
### 输出样例 2:
SS123
## 思路
+28 -13
View File
@@ -9,19 +9,34 @@ permalink: Basic/1007.html
## 题目
{% raw %}<div class="ques-view"><p>让我们定义<span>$d_n$</span>为:<span>$d_n = p_{n+1}-p_n$</span>,其中<span>$p_i$</span>是第<span>$i$</span>个素数。显然有<span>$d_1 = 1$</span>,且对于<span>$n&gt;1$</span>有<span>$d_n$</span>是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。</p>
<p>现给定任意正整数<code>N</code>(<span>$&lt;10^5$</span>),请计算不超过<code>N</code>的满足猜想的素数对的个数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行给出正整数<code>N</code>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出不超过<code>N</code>的满足猜想的素数对的个数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">20
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">4
</code></pre>
</div>{% endraw %}
让我们定义 $d_n$ 为: $d_n = p_{n+1}-p_n$ ,其中 $p_i$ 是第 $i$ 个素数。显然有 $d_1 = 1$ ,且对于
$n>1$ 有 $d_n$ 是偶数。“素数对猜想”认为“存在无穷多对相邻且差为2的素数”。
现给定任意正整数`N`( $<10^5$ ),请计算不超过`N`的满足猜想的素数对的个数。
### 输入格式:
输入在一行给出正整数`N`。
### 输出格式:
在一行中输出不超过`N`的满足猜想的素数对的个数。
### 输入样例:
20
### 输出样例:
4
## 思路
+29 -13
View File
@@ -9,19 +9,35 @@ permalink: Basic/1008.html
## 题目
{% raw %}<div class="ques-view"><p>一个数组<span>$A$</span>中存有<span>$N$</span>(<span>$&gt;0$</span>)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移<span>$M$</span>(<span>$\ge 0$</span>)个位置,即将<span>$A$</span>中的数据由(<span>$A_0 A_1 \cdots A_{N-1}$</span>)变换为(<span>$A_{N-M} \cdots A_{N-1} A_0 A_1 \cdots A_{N-M-1}$</span>)(最后<span>$M$</span>个数循环移至最前面的<span>$M$</span>个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含一个测试用例,第1行输入<span>$N$</span>(<span>$1\le N \le 100$</span>)和<span>$M$</span>(<span>$\ge 0$</span>);第2行输入<span>$N$</span>个整数,之间用空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出循环右移<span>$M$</span>位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6 2
1 2 3 4 5 6
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5 6 1 2 3 4
</code></pre>
</div>{% endraw %}
一个数组 $A$ 中存有 $N$ ( $>0$ )个整数,在不允许使用另外数组的前提下,将每个整数循环向右移 $M$ ( $\ge 0$ )个位置,即将
$A$ 中的数据由( $A_0 A_1 \cdots A_{N-1}$ )变换为( $A_{N-M} \cdots A_{N-1} A_0 A_1
\cdots A_{N-M-1}$ )(最后 $M$ 个数循环移至最前面的 $M$ 个位置)。如果需要考虑程序移动数据的次数尽量少,要如何设计移动的方法?
### 输入格式:
每个输入包含一个测试用例,第1行输入 $N$ ( $1\le N \le 100$ )和 $M$ ( $\ge 0$ );第2行输入 $N$
个整数,之间用空格分隔。
### 输出格式:
在一行中输出循环右移 $M$ 位以后的整数序列,之间用空格分隔,序列结尾不能有多余空格。
### 输入样例:
6 2
1 2 3 4 5 6
### 输出样例:
5 6 1 2 3 4
## 思路
+26 -12
View File
@@ -9,18 +9,32 @@ permalink: Basic/1009.html
## 题目
{% raw %}<div class="ques-view"><p>给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。</p>
<h3 id="-">输入格式:</h3>
<p>测试输入包含一个测试用例,在一行内给出总长度不超过 80 的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末尾没有多余的空格。</p>
<h3 id="-">输出格式:</h3>
<p>每个测试用例的输出占一行,输出倒序后的句子。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">Hello World Here I Come
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">Come I Here World Hello
</code></pre>
</div>{% endraw %}
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
### 输入格式:
测试输入包含一个测试用例,在一行内给出总长度不超过 80
的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用 1 个空格分开,输入保证句子末尾没有多余的空格。
### 输出格式:
每个测试用例的输出占一行,输出倒序后的句子。
### 输入样例:
Hello World Here I Come
### 输出样例:
Come I Here World Hello
## 思路
+25 -13
View File
@@ -9,19 +9,31 @@ permalink: Basic/1010.html
## 题目
{% raw %}<div class="ques-view"><p>设计函数求一元多项式的导数。(注:<span>$x^n$</span>(<span>$n$</span>为整数)的一阶导数为<span>$n x^{n-1}$</span>。)</p>
<h3 id="-">输入格式:</h3>
<p>以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 <code>0
0</code>。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3 4 -5 2 6 1 -2 0
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">12 3 -10 1 6 0
</code></pre>
</div>{% endraw %}
设计函数求一元多项式的导数。(注: $x^n$ ( $n$ 为整数)的一阶导数为 $n x^{n-1}$ 。)
### 输入格式:
以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过 1000 的整数)。数字间以空格分隔。
### 输出格式:
以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是 0,但是表示为 `0 0`。
### 输入样例:
3 4 -5 2 6 1 -2 0
### 输出样例:
12 3 -10 1 6 0
## 思路
+34 -19
View File
@@ -9,25 +9,40 @@ permalink: Basic/1011.html
## 题目
{% raw %}<div class="ques-view"><p>给定区间 [<span>$-2^{31}, 2^{31}$</span>] 内的 3 个整数 <span>$A$</span>、<span>$B$</span> 和 <span>$C$</span>,请判断 <span>$A+B$</span> 是否大于 <span>$C$</span>。</p>
<h3 id="-">输入格式:</h3>
<p>输入第 1 行给出正整数 <span>$T$</span> (<span>$\le 10$</span>),是测试用例的个数。随后给出 <span>$T$</span> 组测试用例,每组占一行,顺序给出 <span>$A$</span>、<span>$B$</span> 和 <span>$C$</span>。整数间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对每组测试用例,在一行中输出 <code>Case #X: true</code> 如果 <span>$A+B&gt;C$</span>,否则输出 <code>Case #X: false</code>,其中 <code>X</code> 是测试用例的编号(从 1 开始)。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">Case #1: false
Case #2: true
Case #3: true
Case #4: false
</code></pre>
</div>{% endraw %}
给定区间 [ $-2^{31}, 2^{31}$ ] 内的 3 个整数 $A$ 、 $B$ 和 $C$ ,请判断 $A+B$ 是否大于 $C$ 。
### 输入格式:
输入第 1 行给出正整数 $T$ ( $\le 10$ ),是测试用例的个数。随后给出 $T$ 组测试用例,每组占一行,顺序给出 $A$ 、 $B$ 和
$C$ 。整数间以空格分隔。
### 输出格式:
对每组测试用例,在一行中输出 `Case #X: true` 如果 $A+B>C$ ,否则输出 `Case #X: false`,其中 `X`
是测试用例的编号(从 1 开始)。
### 输入样例:
4
1 2 3
2 3 4
2147483647 0 2147483646
0 -2147483648 -2147483647
### 输出样例:
Case #1: false
Case #2: true
Case #3: true
Case #4: false
## 思路
+48 -26
View File
@@ -9,32 +9,54 @@ permalink: Basic/1012.html
## 题目
{% raw %}<div class="ques-view"><p>给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:</p>
<ul>
<li><span>$A_1$</span> = 能被 5 整除的数字中所有偶数的和;</li>
<li><span>$A_2$</span> = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 <span>$n_1-n_2+n_3-n_4\cdots$</span>;</li>
<li><span>$A_3$</span> = 被 5 除后余 2 的数字的个数;</li>
<li><span>$A_4$</span> = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;</li>
<li><span>$A_5$</span> = 被 5 除后余 4 的数字中最大数字。</li>
</ul>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 <span>$N$</span>,随后给出 <span>$N$</span> 个不超过 1000 的待分类的正整数。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对给定的 <span>$N$</span> 个正整数,按题目要求计算 <span>$A_1$</span>~<span>$A_5$</span> 并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。</p>
<p>若其中某一类数字不存在,则在相应位置输出 <code>N</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">13 1 2 3 4 5 6 7 8 9 10 20 16 18
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">30 11 2 9.7 9
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">8 1 2 4 5 6 7 9 16
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">N 11 2 N 9
</code></pre>
</div>{% endraw %}
给定一系列正整数,请按要求对数字进行分类,并输出以下 5 个数字:
* $A_1$ = 能被 5 整除的数字中所有偶数的和;
* $A_2$ = 将被 5 除后余 1 的数字按给出顺序进行交错求和,即计算 $n_1-n_2+n_3-n_4\cdots$ ;
* $A_3$ = 被 5 除后余 2 的数字的个数;
* $A_4$ = 被 5 除后余 3 的数字的平均数,精确到小数点后 1 位;
* $A_5$ = 被 5 除后余 4 的数字中最大数字。
### 输入格式:
每个输入包含 1 个测试用例。每个测试用例先给出一个不超过 1000 的正整数 $N$ ,随后给出 $N$ 个不超过 1000
的待分类的正整数。数字间以空格分隔。
### 输出格式:
对给定的 $N$ 个正整数,按题目要求计算 $A_1$ ~ $A_5$ 并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。
若其中某一类数字不存在,则在相应位置输出 `N`。
### 输入样例 1:
13 1 2 3 4 5 6 7 8 9 10 20 16 18
### 输出样例 1:
30 11 2 9.7 9
### 输入样例 2:
8 1 2 4 5 6 7 9 16
### 输出样例 2:
N 11 2 N 9
## 思路
+27 -14
View File
@@ -9,20 +9,33 @@ permalink: Basic/1013.html
## 题目
{% raw %}<div class="ques-view"><p>令 <span>$P_i$</span> 表示第 <span>$i$</span> 个素数。现任给两个正整数 <span>$M \le N \le 10^4$</span>,请输出 <span>$P_M$</span> 到 <span>$P_N$</span> 的所有素数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出 <span>$M$</span> 和 <span>$N$</span>,其间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>输出从 <span>$P_M$</span> 到 <span>$P_N$</span> 的所有素数,每 10 个数字占 1 行,其间以空格分隔,但行末不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5 27
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103
</code></pre>
</div>{% endraw %}
令 $P_i$ 表示第 $i$ 个素数。现任给两个正整数 $M \le N \le 10^4$ ,请输出 $P_M$ 到 $P_N$ 的所有素数。
### 输入格式:
输入在一行中给出 $M$ 和 $N$ ,其间以空格分隔。
### 输出格式:
输出从 $P_M$ 到 $P_N$ 的所有素数,每 10 个数字占 1 行,其间以空格分隔,但行末不得有多余空格。
### 输入样例:
5 27
### 输出样例:
11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103
## 思路
+34 -15
View File
@@ -9,21 +9,40 @@ permalink: Basic/1014.html
## 题目
{% raw %}<div class="ques-view"><p>大侦探福尔摩斯接到一张奇怪的字条:<code>我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&amp;hgsfdk d&amp;Hyscvnm</code>。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间<code>星期四 14:04</code>,因为前面两字符串中第 1 对相同的大写英文字母(大小写有区分)是第 4 个字母 <code>D</code>,代表星期四;第 2 对相同的字符是 <code>E</code> ,那是第 5 个英文字母,代表一天里的第 14 个钟头(于是一天的 0 点到 23 点由数字 0 到 9、以及大写字母 <code>A</code> 到 <code>N</code> 表示);后面两字符串第 1 对相同的英文字母 <code>s</code> 出现在第 4 个位置(从 0 开始计数)上,代表第 4 分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。</p>
<h3 id="-">输入格式:</h3>
<p>输入在 4 行中分别给出 4 个非空、不包含空格、且长度不超过 60 的字符串。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出约会的时间,格式为 <code>DAY HH:MM</code>,其中 <code>DAY</code> 是某星期的 3 字符缩写,即 <code>MON</code> 表示星期一,<code>TUE</code> 表示星期二,<code>WED</code> 表示星期三,<code>THU</code> 表示星期四,<code>FRI</code> 表示星期五,<code>SAT</code> 表示星期六,<code>SUN</code> 表示星期日。题目输入保证每个测试存在唯一解。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&amp;hgsfdk
d&amp;Hyscvnm
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">THU 14:04
</code></pre>
</div>{% endraw %}
大侦探福尔摩斯接到一张奇怪的字条:`我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk
d&Hyscvnm`。大侦探很快就明白了,字条上奇怪的乱码实际上就是约会的时间`星期四 14:04`,因为前面两字符串中第 1
对相同的大写英文字母(大小写有区分)是第 4 个字母 `D`,代表星期四;第 2 对相同的字符是 `E` ,那是第 5 个英文字母,代表一天里的第 14
个钟头(于是一天的 0 点到 23 点由数字 0 到 9、以及大写字母 `A` 到 `N` 表示);后面两字符串第 1 对相同的英文字母 `s` 出现在第
4 个位置(从 0 开始计数)上,代表第 4 分钟。现给定两对字符串,请帮助福尔摩斯解码得到约会的时间。
### 输入格式:
输入在 4 行中分别给出 4 个非空、不包含空格、且长度不超过 60 的字符串。
### 输出格式:
在一行中输出约会的时间,格式为 `DAY HH:MM`,其中 `DAY` 是某星期的 3 字符缩写,即 `MON` 表示星期一,`TUE`
表示星期二,`WED` 表示星期三,`THU` 表示星期四,`FRI` 表示星期五,`SAT` 表示星期六,`SUN`
表示星期日。题目输入保证每个测试存在唯一解。
### 输入样例:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
### 输出样例:
THU 14:04
## 思路
+61 -40
View File
@@ -9,46 +9,67 @@ permalink: Basic/1015.html
## 题目
{% raw %}<div class="ques-view"><p>宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”</p>
<p>现给出一批考生的德才分数,请根据司马光的理论给出录取排名。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出 3 个正整数,分别为:<span>$N$</span>(<span>$\le 10^5$</span>),即考生总数;<span>$L$</span>(<span>$\ge 60$</span>),为录取最低分数线,即德分和才分均不低于 <span>$L$</span> 的考生才有资格被考虑录取;<span>$H$</span>(<span>$&lt; 100$</span>),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于 <span>$H$</span>,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 <span>$L$</span> 的考生也按总分排序,但排在第三类考生之后。</p>
<p>随后 <span>$N$</span> 行,每行给出一位考生的信息,包括:<code>准考证号 德分 才分</code>,其中<code>准考证号</code>为 8 位整数,德才分为区间 [0, 100] 内的整数。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>输出第一行首先给出达到最低分数线的考生人数 <span>$M$</span>,随后 <span>$M$</span> 行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
</code></pre>
</div>{% endraw %}
宋代史学家司马光在《资治通鉴》中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人。凡取人之术,苟不得圣人,君子而与之,与其得小人,不若得愚人。”
现给出一批考生的德才分数,请根据司马光的理论给出录取排名。
### 输入格式:
输入第一行给出 3 个正整数,分别为: $N$ ( $\le 10^5$ ),即考生总数; $L$ ( $\ge 60$
),为录取最低分数线,即德分和才分均不低于 $L$ 的考生才有资格被考虑录取; $H$ ( $< 100$
),为优先录取线——德分和才分均不低于此线的被定义为“才德全尽”,此类考生按德才总分从高到低排序;才分不到但德分到线的一类考生属于“德胜才”,也按总分排序,但排在第一类考生之后;德才分均低于
$H$ ,但是德分不低于才分的考生属于“才德兼亡”但尚有“德胜才”者,按总分排序,但排在第二类考生之后;其他达到最低线 $L$
的考生也按总分排序,但排在第三类考生之后。
随后 $N$ 行,每行给出一位考生的信息,包括:`准考证号 德分 才分`,其中`准考证号`为 8 位整数,德才分为区间 [0, 100]
内的整数。数字间以空格分隔。
### 输出格式:
输出第一行首先给出达到最低分数线的考生人数 $M$ ,随后 $M$
行,每行按照输入格式输出一位考生的信息,考生按输入中说明的规则从高到低排序。当某类考生中有多人总分相同时,按其德分降序排列;若德分也并列,则按准考证号的升序输出。
### 输入样例:
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
### 输出样例:
12
10000013 90 99
10000012 80 100
10000003 85 80
10000011 85 80
10000004 80 85
10000007 90 78
10000006 83 76
10000005 82 77
10000002 90 60
10000014 66 60
10000008 75 79
10000001 64 90
## 思路
+42 -19
View File
@@ -9,25 +9,48 @@ permalink: Basic/1016.html
## 题目
{% raw %}<div class="ques-view"><p>正整数 <span>$A$</span> 的“<span>$D_A$</span>(为 1 位整数)部分”定义为由 <span>$A$</span> 中所有 <span>$D_A$</span> 组成的新整数 <span>$P_A$</span>。例如:给定 <span>$A = 3862767$</span>,<span>$D_A = 6$</span>,则 <span>$A$</span> 的“6 部分”<span>$P_A$</span> 是 66,因为 <span>$A$</span> 中有 2 个 6。</p>
<p>现给定 <span>$A$</span>、<span>$D_A$</span>、<span>$B$</span>、<span>$D_B$</span>,请编写程序计算 <span>$P_A + P_B$</span>。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中依次给出 <span>$A$</span>、<span>$D_A$</span>、<span>$B$</span>、<span>$D_B$</span>,中间以空格分隔,其中 <span>$0 &lt; A, B &lt; 10^{10}$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出 <span>$P_A + P_B$</span> 的值。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">3862767 6 13530293 3
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">399
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">3862767 1 13530293 8
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">0
</code></pre>
</div>{% endraw %}
正整数 $A$ 的“ $D_A$ (为 1 位整数)部分”定义为由 $A$ 中所有 $D_A$ 组成的新整数 $P_A$ 。例如:给定 $A =
3862767$ , $D_A = 6$ ,则 $A$ 的“6 部分” $P_A$ 是 66,因为 $A$ 中有 2 个 6。
现给定 $A$ 、 $D_A$ 、 $B$ 、 $D_B$ ,请编写程序计算 $P_A + P_B$ 。
### 输入格式:
输入在一行中依次给出 $A$ 、 $D_A$ 、 $B$ 、 $D_B$ ,中间以空格分隔,其中 $0 < A, B < 10^{10}$ 。
### 输出格式:
在一行中输出 $P_A + P_B$ 的值。
### 输入样例 1:
3862767 6 13530293 3
### 输出样例 1:
399
### 输入样例 2:
3862767 1 13530293 8
### 输出样例 2:
0
## 思路
+26 -12
View File
@@ -9,18 +9,32 @@ permalink: Basic/1017.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求计算 <span>$A/B$</span>,其中 <span>$A$</span> 是不超过 1000 位的正整数,<span>$B$</span> 是 1 位正整数。你需要输出商数 <span>$Q$</span> 和余数 <span>$R$</span>,使得 <span>$A = B \times Q + R$</span> 成立。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中依次给出 <span>$A$</span> 和 <span>$B$</span>,中间以 1 空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中依次输出 <span>$Q$</span> 和 <span>$R$</span>,中间以 1 空格分隔。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">123456789050987654321 7
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">17636684150141093474 3
</code></pre>
</div>{% endraw %}
本题要求计算 $A/B$ ,其中 $A$ 是不超过 1000 位的正整数, $B$ 是 1 位正整数。你需要输出商数 $Q$ 和余数 $R$ ,使得 $A
= B \times Q + R$ 成立。
### 输入格式:
输入在一行中依次给出 $A$ 和 $B$ ,中间以 1 空格分隔。
### 输出格式:
在一行中依次输出 $Q$ 和 $R$ ,中间以 1 空格分隔。
### 输入样例:
123456789050987654321 7
### 输出样例:
17636684150141093474 3
## 思路
+44 -26
View File
@@ -9,32 +9,50 @@ permalink: Basic/1018.html
## 题目
{% raw %}<div class="ques-view"><p>大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:</p>
<p><img alt="FigCJB.jpg" src="https://images.ptausercontent.com/724da598-b37f-4f1f-99b4-71459654ce3a.jpg"/></p>
<p>现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。</p>
<h3 id="-">输入格式:</h3>
<p>输入第 1 行给出正整数 <span>$N$</span>(<span>$\le 10^5$</span>),即双方交锋的次数。随后 <span>$N$</span> 行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。<code>C</code> 代表“锤子”、<code>J</code> 代表“剪刀”、<code>B</code> 代表“布”,第 1 个字母代表甲方,第 2 个代表乙方,中间有 1 个空格。</p>
<h3 id="-">输出格式:</h3>
<p>输出第 1、2 行分别给出甲、乙的胜、平、负次数,数字间以 1 个空格分隔。第 3 行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有 1 个空格。如果解不唯一,则输出按字母序最小的解。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5 3 2
2 3 5
B B
</code></pre>
</div>{% endraw %}
大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:
![FigCJB.jpg](https://images.ptausercontent.com/724da598-b37f-4f1f-99b4-71459654ce3a.jpg)
现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
### 输入格式:
输入第 1 行给出正整数 $N$ ( $\le 10^5$ ),即双方交锋的次数。随后 $N$
行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。`C` 代表“锤子”、`J` 代表“剪刀”、`B` 代表“布”,第 1 个字母代表甲方,第 2
个代表乙方,中间有 1 个空格。
### 输出格式:
输出第 1、2 行分别给出甲、乙的胜、平、负次数,数字间以 1 个空格分隔。第 3 行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有 1
个空格。如果解不唯一,则输出按字母序最小的解。
### 输入样例:
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
### 输出样例:
5 3 2
2 3 5
B B
## 思路
+58 -29
View File
@@ -9,35 +9,64 @@ permalink: Basic/1019.html
## 题目
{% raw %}<div class="ques-view"><p>给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2 个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的 <code>6174</code>,这个神奇的数字也叫 Kaprekar 常数。</p>
<p>例如,我们从<code>6767</code>开始,将得到</p>
<pre><code>7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
7641 - 1467 = 6174
... ...
</code></pre><p>现给定任意 4 位正整数,请编写程序演示到达黑洞的过程。</p>
<h3 id="-">输入格式:</h3>
<p>输入给出一个 <span>$(0, 10^4)$</span> 区间内的正整数 <span>$N$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>如果 <span>$N$</span> 的 4 位数字全相等,则在一行内输出 <code>N - N = 0000</code>;否则将计算的每一步在一行内输出,直到 <code>6174</code> 作为差出现,输出格式见样例。注意每个数字按 <code>4</code> 位数格式输出。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">6767
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">2222
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">2222 - 2222 = 0000
</code></pre>
</div>{% endraw %}
给定任一个各位数字不完全相同的 4 位正整数,如果我们先把 4 个数字按非递增排序,再按非递减排序,然后用第 1 个数字减第 2
个数字,将得到一个新的数字。一直重复这样做,我们很快会停在有“数字黑洞”之称的 `6174`,这个神奇的数字也叫 Kaprekar 常数。
例如,我们从`6767`开始,将得到
7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
7641 - 1467 = 6174
... ...
现给定任意 4 位正整数,请编写程序演示到达黑洞的过程。
### 输入格式:
输入给出一个 $(0, 10^4)$ 区间内的正整数 $N$ 。
### 输出格式:
如果 $N$ 的 4 位数字全相等,则在一行内输出 `N - N = 0000`;否则将计算的每一步在一行内输出,直到 `6174`
作为差出现,输出格式见样例。注意每个数字按 `4` 位数格式输出。
### 输入样例 1:
6767
### 输出样例 1:
7766 - 6677 = 1089
9810 - 0189 = 9621
9621 - 1269 = 8352
8532 - 2358 = 6174
### 输入样例 2:
2222
### 输出样例 2:
2222 - 2222 = 0000
## 思路
+33 -15
View File
@@ -9,21 +9,39 @@ permalink: Basic/1020.html
## 题目
{% raw %}<div class="ques-view"><p>月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。</p>
<p>注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45 亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 + 45/2 = 94.5(亿元)。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含一个测试用例。每个测试用例先给出一个不超过 1000 的正整数 <span>$N$</span> 表示月饼的种类数、以及不超过 500(以万吨为单位)的正整数 <span>$D$</span> 表示市场最大需求量。随后一行给出 <span>$N$</span> 个正数表示每种月饼的库存量(以万吨为单位);最后一行给出 <span>$N$</span> 个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后 2 位。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3 20
18 15 10
75 72 45
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">94.50
</code></pre>
</div>{% endraw %}
月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。
注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有 3 种月饼,其库存量分别为 18、15、10 万吨,总售价分别为 75、72、45
亿元。如果市场的最大需求量只有 20 万吨,那么我们最大收益策略应该是卖出全部 15 万吨第 2 种月饼、以及 5 万吨第 3 种月饼,获得 72 +
45/2 = 94.5(亿元)。
### 输入格式:
每个输入包含一个测试用例。每个测试用例先给出一个不超过 1000 的正整数 $N$ 表示月饼的种类数、以及不超过 500(以万吨为单位)的正整数 $D$
表示市场最大需求量。随后一行给出 $N$ 个正数表示每种月饼的库存量(以万吨为单位);最后一行给出 $N$
个正数表示每种月饼的总售价(以亿元为单位)。数字间以空格分隔。
### 输出格式:
对每组测试用例,在一行中输出最大收益,以亿元为单位并精确到小数点后 2 位。
### 输入样例:
3 20
18 15 10
75 72 45
### 输出样例:
94.50
## 思路
+29 -14
View File
@@ -9,20 +9,35 @@ permalink: Basic/1021.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个 <span>$k$</span> 位整数 <span>$N = d_{k-1}10^{k-1} + \cdots + d_1 10^1 + d_0$</span> (<span>$0\le d_i \le 9$</span>, <span>$i=0,\cdots ,k-1$</span>, <span>$d_{k-1}&gt;0$</span>),请编写程序统计每种不同的个位数字出现的次数。例如:给定 <span>$N = 100311$</span>,则有 2 个 0,3 个 1,和 1 个 3。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例,即一个不超过 1000 位的正整数 <span>$N$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>对 <span>$N$</span> 中每一种不同的个位数字,以 <code>D:M</code> 的格式在一行中输出该位数字 <code>D</code> 及其在 <span>$N$</span> 中出现的次数 <code>M</code>。要求按 <code>D</code> 的升序输出。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">100311
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">0:2
1:3
3:1
</code></pre>
</div>{% endraw %}
给定一个 $k$ 位整数 $N = d_{k-1}10^{k-1} + \cdots + d_1 10^1 + d_0$ ( $0\le d_i \le
9$ , $i=0,\cdots ,k-1$ , $d_{k-1}>0$ ),请编写程序统计每种不同的个位数字出现的次数。例如:给定 $N =
100311$ ,则有 2 个 0,3 个 1,和 1 个 3。
### 输入格式:
每个输入包含 1 个测试用例,即一个不超过 1000 位的正整数 $N$ 。
### 输出格式:
对 $N$ 中每一种不同的个位数字,以 `D:M` 的格式在一行中输出该位数字 `D` 及其在 $N$ 中出现的次数 `M`。要求按 `D` 的升序输出。
### 输入样例:
100311
### 输出样例:
0:2
1:3
3:1
## 思路
+26 -12
View File
@@ -9,18 +9,32 @@ permalink: Basic/1022.html
## 题目
{% raw %}<div class="ques-view"><p>输入两个非负 10 进制整数 <span>$A$</span> 和 <span>$B$</span> (<span>$\le 2^{30} -1$</span>),输出 <span>$A+B$</span> 的 <span>$D$</span> (<span>$1 &lt; D \le 10$</span>)进制数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中依次给出 3 个整数 <span>$A$</span>、<span>$B$</span> 和 <span>$D$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>输出 <span>$A+B$</span> 的 <span>$D$</span> 进制数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">123 456 8
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">1103
</code></pre>
</div>{% endraw %}
输入两个非负 10 进制整数 $A$ 和 $B$ ( $\le 2^{30} -1$ ),输出 $A+B$ 的 $D$ ( $1 < D \le 10$
)进制数。
### 输入格式:
输入在一行中依次给出 3 个整数 $A$ 、 $B$ 和 $D$ 。
### 输出格式:
输出 $A+B$ 的 $D$ 进制数。
### 输入样例:
123 456 8
### 输出样例:
1103
## 思路
+29 -13
View File
@@ -9,19 +9,35 @@ permalink: Basic/1023.html
## 题目
{% raw %}<div class="ques-view"><p>给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个 1,三个 5,一个 8,我们得到的最小的数就是 10015558。</p>
<p>现给定数字,请编写程序输出能够组成的最小的数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过 50,且至少拥有 1 个非 0 的数字。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出能够组成的最小的数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">2 2 0 0 0 3 0 0 1 0
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">10015558
</code></pre>
</div>{% endraw %}
给定数字 0-9 各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意 0 不能做首位)。例如:给定两个 0,两个
1,三个 5,一个 8,我们得到的最小的数就是 10015558。
现给定数字,请编写程序输出能够组成的最小的数。
### 输入格式:
输入在一行中给出 10 个非负整数,顺序表示我们拥有数字 0、数字 1、……数字 9 的个数。整数间用一个空格分隔。10 个数字的总个数不超过
50,且至少拥有 1 个非 0 的数字。
### 输出格式:
在一行中输出能够组成的最小的数。
### 输入样例:
2 2 0 0 0 3 0 0 1 0
### 输出样例:
10015558
## 思路
+43 -19
View File
@@ -9,25 +9,49 @@ permalink: Basic/1024.html
## 题目
{% raw %}<div class="ques-view"><p>科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式 [+-][1-9]<code>.</code>[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1 位,该数字及其指数部分的正负号即使对正数也必定明确给出。</p>
<p>现以科学计数法的格式给出实数 <span>$A$</span>,请编写程序按普通数字表示法输出 <span>$A$</span>,并保证所有有效位都被保留。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 <span>$A$</span>。该数字的存储长度不超过 9999 字节,且其指数的绝对值不超过 9999。</p>
<h3 id="-">输出格式:</h3>
<p>对每个测试用例,在一行中按普通数字表示法输出 <span>$A$</span>,并保证所有有效位都被保留,包括末尾的 0。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">+1.23400E-03
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">0.00123400
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">-1.2E+10
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">-12000000000
</code></pre>
</div>{% endraw %}
科学计数法是科学家用来表示很大或很小的数字的一种方便的方法,其满足正则表达式
[+-][1-9]`.`[0-9]+E[+-][0-9]+,即数字的整数部分只有 1 位,小数部分至少有 1
位,该数字及其指数部分的正负号即使对正数也必定明确给出。
现以科学计数法的格式给出实数 $A$ ,请编写程序按普通数字表示法输出 $A$ ,并保证所有有效位都被保留。
### 输入格式:
每个输入包含 1 个测试用例,即一个以科学计数法表示的实数 $A$ 。该数字的存储长度不超过 9999 字节,且其指数的绝对值不超过 9999。
### 输出格式:
对每个测试用例,在一行中按普通数字表示法输出 $A$ ,并保证所有有效位都被保留,包括末尾的 0。
### 输入样例 1:
+1.23400E-03
### 输出样例 1:
0.00123400
### 输入样例 2:
-1.2E+10
### 输出样例 2:
-12000000000
## 思路
+47 -26
View File
@@ -9,32 +9,53 @@ permalink: Basic/1025.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个常数 <span>$K$</span> 以及一个单链表 <span>$L$</span>,请编写程序将 <span>$L$</span> 中每 <span>$K$</span> 个结点反转。例如:给定 <span>$L$</span> 为 1→2→3→4→5→6,<span>$K$</span> 为 3,则输出应该为 3→2→1→6→5→4;如果 <span>$K$</span> 为 4,则输出应该为 4→3→2→1→5→6,即最后不到 <span>$K$</span> 个元素不反转。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例。每个测试用例第 1 行给出第 1 个结点的地址、结点总个数正整数 <span>$N$</span> (<span>$\le 10^5$</span>)、以及正整数 <span>$K$</span> (<span>$\le N$</span>),即要求反转的子链结点的个数。结点的地址是 5 位非负整数,NULL 地址用 <span>$-1$</span> 表示。</p>
<p>接下来有 <span>$N$</span> 行,每行格式为:</p>
<pre><code>Address Data Next
</code></pre><p>其中 <code>Address</code> 是结点地址,<code>Data</code> 是该结点保存的整数数据,<code>Next</code> 是下一结点的地址。</p>
<h3 id="-">输出格式:</h3>
<p>对每个测试用例,顺序输出反转后的链表,其上每个结点占一行,格式与输入相同。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1
</code></pre>
</div>{% endraw %}
给定一个常数 $K$ 以及一个单链表 $L$ ,请编写程序将 $L$ 中每 $K$ 个结点反转。例如:给定 $L$ 为 1→2→3→4→5→6, $K$ 为
3,则输出应该为 3→2→1→6→5→4;如果 $K$ 为 4,则输出应该为 4→3→2→1→5→6,即最后不到 $K$ 个元素不反转。
### 输入格式:
每个输入包含 1 个测试用例。每个测试用例第 1 行给出第 1 个结点的地址、结点总个数正整数 $N$ ( $\le 10^5$ )、以及正整数 $K$ (
$\le N$ ),即要求反转的子链结点的个数。结点的地址是 5 位非负整数,NULL 地址用 $-1$ 表示。
接下来有 $N$ 行,每行格式为:
Address Data Next
其中 `Address` 是结点地址,`Data` 是该结点保存的整数数据,`Next` 是下一结点的地址。
### 输出格式:
对每个测试用例,顺序输出反转后的链表,其上每个结点占一行,格式与输入相同。
### 输入样例:
00100 6 4
00000 4 99999
00100 1 12309
68237 6 -1
33218 3 00000
99999 5 68237
12309 2 33218
### 输出样例:
00000 4 33218
33218 3 12309
12309 2 00100
00100 1 99999
99999 5 68237
68237 6 -1
## 思路
+31 -13
View File
@@ -9,19 +9,37 @@ permalink: Basic/1026.html
## 题目
{% raw %}<div class="ques-view"><p>要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 <span>$f$</span> 的运行时间,我们只要在调用 <span>$f$</span> 之前先调用 clock(),获得一个时钟打点数 C1;在 <span>$f$</span> 执行完成后再调用 clock(),获得另一个时钟打点数 C2;两次获得的时钟打点数之差 (C2-C1) 就是 <span>$f$</span> 运行所消耗的时钟打点数,再除以常数 CLK_TCK,就得到了以秒为单位的运行时间。</p>
<p>这里不妨简单假设常数 CLK_TCK 为 100。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中顺序给出 2 个整数 C1 和 C2。注意两次获得的时钟打点数肯定不相同,即 C1 <span>$&lt;$</span> C2,并且取值在 <span>$[0, 10^7]$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出被测函数运行的时间。运行时间必须按照 <code>hh:mm:ss</code>(即2位的 <code>时:分:秒</code>)格式输出;不足 1 秒的时间四舍五入到秒。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">123 4577973
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">12:42:59
</code></pre>
</div>{% endraw %}
要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock()
被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数
CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 $f$ 的运行时间,我们只要在调用 $f$ 之前先调用
clock(),获得一个时钟打点数 C1;在 $f$ 执行完成后再调用 clock(),获得另一个时钟打点数 C2;两次获得的时钟打点数之差 (C2-C1)
就是 $f$ 运行所消耗的时钟打点数,再除以常数 CLK_TCK,就得到了以秒为单位的运行时间。
这里不妨简单假设常数 CLK_TCK 为 100。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。
### 输入格式:
输入在一行中顺序给出 2 个整数 C1 和 C2。注意两次获得的时钟打点数肯定不相同,即 C1 $<$ C2,并且取值在 $[0, 10^7]$ 。
### 输出格式:
在一行中输出被测函数运行的时间。运行时间必须按照 `hh:mm:ss`(即2位的 `时:分:秒`)格式输出;不足 1 秒的时间四舍五入到秒。
### 输入样例:
123 4577973
### 输出样例:
12:42:59
## 思路
+54 -31
View File
@@ -9,30 +9,49 @@ permalink: Basic/1027.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印</p>
<pre><code>*****
***
*
***
*****
</code></pre><p>所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。</p>
<p>给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行给出1个正整数N(<span>$\le$</span>1000)和一个符号,中间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">19 *
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">*****
***
*
***
*****
2
</code></pre>
</div>{% endraw %}
本题要求你写个程序把给定的符号打印成沙漏的形状。例如给定17个“*”,要求按下列格式打印
*****
***
*
***
*****
所谓“沙漏形状”,是指每行输出奇数个符号;各行符号中心对齐;相邻两行符号数差2;符号数先从大到小顺序递减到1,再从小到大顺序递增;首尾符号数相等。
给定任意N个符号,不一定能正好组成一个沙漏。要求打印出的沙漏能用掉尽可能多的符号。
### 输入格式:
输入在一行给出1个正整数N( $\le$ 1000)和一个符号,中间以空格分隔。
### 输出格式:
首先打印出由给定符号组成的最大的沙漏形状,最后在一行中输出剩下没用掉的符号数。
### 输入样例:
19 *
### 输出样例:
*****
***
*
***
*****
2
## 思路
@@ -54,17 +73,21 @@ int main()
char c;
int N, M;
scanf("%d %c", &N, &c);
for(M = 1; 2 * M * M - 1 <= N; M++) ; M--; /* determine the size */
for(M = 1; 2 * M * M - 1 <= N; M++) ;
M--; /* determine the size */
/* draw the sandglass */
for(int i = 0; i < 2 * M - 1; i ++){
for(int j = 0; j < M - 1 - ABS(M - 1 - i); j++) putchar(' ');
for(int j = 0; j < 2 * ABS(M - 1 - i) + 1; j++) putchar(c);
for(int i = 0; i < 2 * M - 1; i ++)
{
for(int j = 0; j < M - 1 - ABS(M - 1 - i); j++)
putchar(' ');
for(int j = 0; j < 2 * ABS(M - 1 - i) + 1; j++)
putchar(c);
putchar('\n');
}
printf("%d", N - 2 * M * M + 1);
return 0;
}
{% endraw %}
+34 -18
View File
@@ -9,24 +9,40 @@ permalink: Basic/1028.html
## 题目
{% raw %}<div class="ques-view"><p>某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。</p>
<p>这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 年 9 月 6 日,所以超过 200 岁的生日和未出生的生日都是不合理的,应该被过滤掉。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出正整数 <span>$N$</span>,取值在<span>$(0, 10^5]$</span>;随后 <span>$N$</span> 行,每行给出 1 个人的姓名(由不超过 5 个英文字母组成的字符串)、以及按 <code>yyyy/mm/dd</code>(即年/月/日)格式给出的生日。题目保证最年长和最年轻的人没有并列。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3 Tom John
</code></pre>
</div>{% endraw %}
某城镇进行人口普查,得到了全体居民的生日。现请你写个程序,找出镇上最年长和最年轻的人。
这里确保每个输入的日期都是合法的,但不一定是合理的——假设已知镇上没有超过 200 岁的老人,而今天是 2014 年 9 月 6 日,所以超过 200
岁的生日和未出生的生日都是不合理的,应该被过滤掉。
### 输入格式:
输入在第一行给出正整数 $N$ ,取值在 $(0, 10^5]$ ;随后 $N$ 行,每行给出 1 个人的姓名(由不超过 5
个英文字母组成的字符串)、以及按 `yyyy/mm/dd`(即年/月/日)格式给出的生日。题目保证最年长和最年轻的人没有并列。
### 输出格式:
在一行中顺序输出有效生日的个数、最年长人和最年轻人的姓名,其间以空格分隔。
### 输入样例:
5
John 2001/05/12
Tom 1814/09/06
Ann 2121/01/30
James 1814/09/05
Steve 1967/11/20
### 输出样例:
3 Tom John
## 思路
+31 -17
View File
@@ -9,19 +9,33 @@ permalink: Basic/1029.html
## 题目
{% raw %}<div class="ques-view"><p>旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。</p>
<h3 id="-">输入格式:</h3>
<p>输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 <code>_</code>(代表空格)组成。题目保证 2 个字符串均非空。</p>
<h3 id="-">输出格式:</h3>
<p>按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">7_This_is_a_test
_hs_s_a_es
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">7TI
</code></pre>
</div>{% endraw %}
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。
### 输入格式:
输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线
`_`(代表空格)组成。题目保证 2 个字符串均非空。
### 输出格式:
按照发现顺序,在一行中输出坏掉的键。其中英文字母只输出大写,每个坏键只输出一次。题目保证至少有 1 个坏键。
### 输入样例:
7_This_is_a_test
_hs_s_a_es
### 输出样例:
7TI
## 思路
@@ -44,12 +58,12 @@ _hs_s_a_es
int main()
{
int printed[128] = {0};
char c, line[80];
gets(line); /* the newline was replaced with '\0' */
char c, line[82];
fgets(line, 82, stdin);
while((c = getchar()) != '\n')
printed[toupper(c)]++;
for(char *p = line; *p; p++)
{
c = toupper(*p);
+29 -14
View File
@@ -9,20 +9,35 @@ permalink: Basic/1030.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个正整数数列,和正整数 <span>$p$</span>,设这个数列中的最大值是 <span>$M$</span>,最小值是 <span>$m$</span>,如果 <span>$M \le mp$</span>,则称这个数列是完美数列。</p>
<p>现在给定参数 <span>$p$</span> 和一些正整数,请你从中选择尽可能多的数构成一个完美数列。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出两个正整数 <span>$N$</span> 和 <span>$p$</span>,其中 <span>$N$</span>(<span>$\le 10^5$</span>)是输入的正整数的个数,<span>$p$</span>(<span>$\le 10^9$</span>)是给定的参数。第二行给出 <span>$N$</span> 个正整数,每个数不超过 <span>$10^9$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10 8
2 3 20 4 5 1 6 7 8 9
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">8
</code></pre>
</div>{% endraw %}
给定一个正整数数列,和正整数 $p$ ,设这个数列中的最大值是 $M$ ,最小值是 $m$ ,如果 $M \le mp$ ,则称这个数列是完美数列。
现在给定参数 $p$ 和一些正整数,请你从中选择尽可能多的数构成一个完美数列。
### 输入格式:
输入第一行给出两个正整数 $N$ 和 $p$ ,其中 $N$ ( $\le 10^5$ )是输入的正整数的个数, $p$ ( $\le 10^9$
)是给定的参数。第二行给出 $N$ 个正整数,每个数不超过 $10^9$ 。
### 输出格式:
在一行中输出最多可以选择多少个数可以用它们组成一个完美数列。
### 输入样例:
10 8
2 3 20 4 5 1 6 7 8 9
### 输出样例:
8
## 思路
+60 -29
View File
@@ -9,35 +9,66 @@ permalink: Basic/1031.html
## 题目
{% raw %}<div class="ques-view"><p>一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:</p>
<p>首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值<code>Z</code>;最后按照以下关系对应<code>Z</code>值与校验码<code>M</code>的值:</p>
<pre><code>Z:0 1 2 3 4 5 6 7 8 9 10
M:1 0 X 9 8 7 6 5 4 3 2
</code></pre><p>现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出正整数<span>$N$</span>(<span>$\le 100$</span>)是输入的身份证号码的个数。随后<span>$N$</span>行,每行给出1个18位身份证号码。</p>
<h3 id="-">输出格式:</h3>
<p>按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出<code>All passed</code>。</p>
<h3 id="-1-">输入样例1:</h3>
<pre><code class="lang-in">4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
</code></pre>
<h3 id="-1-">输出样例1:</h3>
<pre><code class="lang-out">12010X198901011234
110108196711301866
37070419881216001X
</code></pre>
<h3 id="-2-">输入样例2:</h3>
<pre><code>2
320124198808240056
110108196711301862
</code></pre><h3 id="-2-">输出样例2:</h3>
<pre><code>All passed
</code></pre><p><strong>鸣谢阜阳师范学院范建中老师补充数据</strong></p>
</div>{% endraw %}
一个合法的身份证号码由17位地区、日期编号和顺序编号加1位校验码组成。校验码的计算规则如下:
首先对前17位数字加权求和,权重分配为:{7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};然后将计算的和对11取模得到值`Z`;最后按照以下关系对应`Z`值与校验码`M`的值:
Z:0 1 2 3 4 5 6 7 8 9 10
M:1 0 X 9 8 7 6 5 4 3 2
现在给定一些身份证号码,请你验证校验码的有效性,并输出有问题的号码。
### 输入格式:
输入第一行给出正整数 $N$ ( $\le 100$ )是输入的身份证号码的个数。随后 $N$ 行,每行给出1个18位身份证号码。
### 输出格式:
按照输入的顺序每行输出1个有问题的身份证号码。这里并不检验前17位是否合理,只检查前17位是否全为数字且最后1位校验码计算准确。如果所有号码都正常,则输出`All
passed`。
### 输入样例1:
4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X
### 输出样例1:
12010X198901011234
110108196711301866
37070419881216001X
### 输入样例2:
2
320124198808240056
110108196711301862
### 输出样例2:
All passed
**鸣谢阜阳师范学院范建中老师补充数据**
## 思路
+32 -18
View File
@@ -9,24 +9,38 @@ permalink: Basic/1032.html
## 题目
{% raw %}<div class="ques-view"><p>为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第 1 行给出不超过 <span>$10^5$</span> 的正整数 <span>$N$</span>,即参赛人数。随后 <span>$N$</span> 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1 开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6
3 65
2 80
1 100
2 70
3 40
3 0
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">2 150
</code></pre>
</div>{% endraw %}
为了用事实说明挖掘机技术到底哪家强,PAT 组织了一场挖掘机技能大赛。现请你根据比赛结果统计出技术最强的那个学校。
### 输入格式:
输入在第 1 行给出不超过 $10^5$ 的正整数 $N$ ,即参赛人数。随后 $N$ 行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从 1
开始连续编号)、及其比赛成绩(百分制),中间以空格分隔。
### 输出格式:
在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。
### 输入样例:
6
3 65
2 80
1 100
2 70
3 40
3 0
### 输出样例:
2 150
## 思路
+30 -14
View File
@@ -9,20 +9,36 @@ permalink: Basic/1033.html
## 题目
{% raw %}<div class="ques-view"><p>旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?</p>
<h3 id="-">输入格式:</h3>
<p>输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 <span>$10^5$</span> 个字符的串。可用的字符包括字母 [<code>a</code>-<code>z</code>, <code>A</code>-<code>Z</code>]、数字 <code>0</code>-<code>9</code>、以及下划线 <code>_</code>(代表空格)、<code>,</code>、<code>.</code>、<code>-</code>、<code>+</code>(代表上档键)。题目保证第 2 行输入的文字串非空。</p>
<p>注意:如果上档键坏掉了,那么大写的英文字母无法被打出。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">7+IE.
7_This_is_a_test.
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">_hs_s_a_tst
</code></pre>
</div>{% endraw %}
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?
### 输入格式:
输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 $10^5$ 个字符的串。可用的字符包括字母
[`a`-`z`, `A`-`Z`]、数字 `0`-`9`、以及下划线 `_`(代表空格)、`,`、`.`、`-`、`+`(代表上档键)。题目保证第 2
行输入的文字串非空。
注意:如果上档键坏掉了,那么大写的英文字母无法被打出。
### 输出格式:
在一行中输出能够被打出的结果文字。如果没有一个字符能被打出,则输出空行。
### 输入样例:
7+IE.
7_This_is_a_test.
### 输出样例:
_hs_s_a_tst
## 思路
+47 -24
View File
@@ -9,30 +9,53 @@ permalink: Basic/1034.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求编写程序,计算 2 个有理数的和、差、积、商。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中按照 <code>a1/b1 a2/b2</code> 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为 0。</p>
<h3 id="-">输出格式:</h3>
<p>分别在 4 行中按照 <code>有理数1 运算符 有理数2 = 结果</code> 的格式顺序输出 2 个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式 <code>k a/b</code>,其中 <code>k</code> 是整数部分,<code>a/b</code> 是最简分数部分;若为负数,则须加括号;若除法分母为 0,则输出 <code>Inf</code>。题目保证正确的输出中没有超过整型范围的整数。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">2/3 -4/2
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">2/3 + (-2) = (-1 1/3)
2/3 - (-2) = 2 2/3
2/3 * (-2) = (-1 1/3)
2/3 / (-2) = (-1/3)
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">5/3 0/6
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">1 2/3 + 0 = 1 2/3
1 2/3 - 0 = 1 2/3
1 2/3 * 0 = 0
1 2/3 / 0 = Inf
</code></pre>
</div>{% endraw %}
本题要求编写程序,计算 2 个有理数的和、差、积、商。
### 输入格式:
输入在一行中按照 `a1/b1 a2/b2` 的格式给出两个分数形式的有理数,其中分子和分母全是整型范围内的整数,负号只可能出现在分子前,分母不为 0。
### 输出格式:
分别在 4 行中按照 `有理数1 运算符 有理数2 = 结果` 的格式顺序输出 2 个有理数的和、差、积、商。注意输出的每个有理数必须是该有理数的最简形式
`k a/b`,其中 `k` 是整数部分,`a/b` 是最简分数部分;若为负数,则须加括号;若除法分母为 0,则输出
`Inf`。题目保证正确的输出中没有超过整型范围的整数。
### 输入样例 1:
2/3 -4/2
### 输出样例 1:
2/3 + (-2) = (-1 1/3)
2/3 - (-2) = 2 2/3
2/3 * (-2) = (-1 1/3)
2/3 / (-2) = (-1/3)
### 输入样例 2:
5/3 0/6
### 输出样例 2:
1 2/3 + 0 = 1 2/3
1 2/3 - 0 = 1 2/3
1 2/3 * 0 = 0
1 2/3 / 0 = Inf
## 思路
+55 -27
View File
@@ -9,33 +9,61 @@ permalink: Basic/1035.html
## 题目
{% raw %}<div class="ques-view"><p>根据维基百科的定义:</p>
<p><strong>插入排序</strong>是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从输入序列中取出一元素,将之插入有序序列中正确的位置。如此迭代直到全部元素有序。</p>
<p><strong>归并排序</strong>进行如下迭代操作:首先将原始序列看成 N 个只包含 1 个元素的有序子序列,然后每次迭代归并两个相邻的有序子序列,直到最后只剩下 1 个有序的序列。</p>
<p>现给定原始序列和由某排序算法产生的中间序列,请你判断该算法究竟是哪种排序算法?</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出正整数 N (<span>$\le$</span>100);随后一行给出原始序列的 N 个整数;最后一行给出由某排序算法产生的中间序列。这里假设排序的目标序列是升序。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>首先在第 1 行中输出<code>Insertion Sort</code>表示插入排序、或<code>Merge Sort</code>表示归并排序;然后在第 2 行中输出用该排序算法再迭代一轮的结果序列。题目保证每组测试的结果是唯一的。数字间以空格分隔,且行首尾不得有多余空格。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">Insertion Sort
1 2 3 5 7 8 9 4 6 0
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">10
3 1 2 8 7 5 9 4 0 6
1 3 2 8 5 7 4 9 0 6
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">Merge Sort
1 2 3 8 4 5 7 9 0 6
</code></pre>
</div>{% endraw %}
根据维基百科的定义:
**插入排序**
是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从输入序列中取出一元素,将之插入有序序列中正确的位置。如此迭代直到全部元素有序。
**归并排序** 进行如下迭代操作:首先将原始序列看成 N 个只包含 1 个元素的有序子序列,然后每次迭代归并两个相邻的有序子序列,直到最后只剩下 1
个有序的序列。
现给定原始序列和由某排序算法产生的中间序列,请你判断该算法究竟是哪种排序算法?
### 输入格式:
输入在第一行给出正整数 N ( $\le$ 100);随后一行给出原始序列的 N
个整数;最后一行给出由某排序算法产生的中间序列。这里假设排序的目标序列是升序。数字间以空格分隔。
### 输出格式:
首先在第 1 行中输出`Insertion Sort`表示插入排序、或`Merge Sort`表示归并排序;然后在第 2
行中输出用该排序算法再迭代一轮的结果序列。题目保证每组测试的结果是唯一的。数字间以空格分隔,且行首尾不得有多余空格。
### 输入样例 1:
10
3 1 2 8 7 5 9 4 6 0
1 2 3 7 8 5 9 4 6 0
### 输出样例 1:
Insertion Sort
1 2 3 5 7 8 9 4 6 0
### 输入样例 2:
10
3 1 2 8 7 5 9 4 0 6
1 3 2 8 5 7 4 9 0 6
### 输出样例 2:
Merge Sort
1 2 3 8 4 5 7 9 0 6
## 思路
+30 -16
View File
@@ -9,22 +9,36 @@ permalink: Basic/1036.html
## 题目
{% raw %}<div class="ques-view"><p>美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014 年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出正方形边长 <span>$N$</span>(<span>$3\le N\le 20$</span>)和组成正方形边的某种字符 C,间隔一个空格。</p>
<h3 id="-">输出格式:</h3>
<p>输出由给定字符 C 画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的 50%(四舍五入取整)。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10 a
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">aaaaaaaaaa
a a
a a
a a
aaaaaaaaaa
</code></pre>
</div>{% endraw %}
美国总统奥巴马不仅呼吁所有人都学习编程,甚至以身作则编写代码,成为美国历史上首位编写计算机代码的总统。2014
年底,为庆祝“计算机科学教育周”正式启动,奥巴马编写了很简单的计算机代码:在屏幕上画一个正方形。现在你也跟他一起画吧!
### 输入格式:
输入在一行中给出正方形边长 $N$ ( $3\le N\le 20$ )和组成正方形边的某种字符 C,间隔一个空格。
### 输出格式:
输出由给定字符 C 画出的正方形。但是注意到行间距比列间距大,所以为了让结果看上去更像正方形,我们输出的行数实际上是列数的 50%(四舍五入取整)。
### 输入样例:
10 a
### 输出样例:
aaaaaaaaaa
a a
a a
a a
aaaaaaaaaa
## 思路
+42 -18
View File
@@ -9,24 +9,48 @@ permalink: Basic/1037.html
## 题目
{% raw %}<div class="ques-view"><p>如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱 <span>$P$</span> 和他实付的钱 <span>$A$</span>,你的任务是写一个程序来计算他应该被找的零钱。</p>
<h3 id="-">输入格式:</h3>
<p>输入在 1 行中分别给出 <span>$P$</span> 和 <span>$A$</span>,格式为 <code>Galleon.Sickle.Knut</code>,其间用 1 个空格分隔。这里 <code>Galleon</code> 是 [0, <span>$10^7$</span>] 区间内的整数,<code>Sickle</code> 是 [0, 17) 区间内的整数,<code>Knut</code> 是 [0, 29) 区间内的整数。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">10.16.27 14.1.28
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">3.2.1
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">14.1.28 10.16.27
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">-3.2.1
</code></pre>
</div>{% endraw %}
如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 ——
就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱
$P$ 和他实付的钱 $A$ ,你的任务是写一个程序来计算他应该被找的零钱。
### 输入格式:
输入在 1 行中分别给出 $P$ 和 $A$ ,格式为 `Galleon.Sickle.Knut`,其间用 1 个空格分隔。这里 `Galleon` 是
[0, $10^7$ ] 区间内的整数,`Sickle` 是 [0, 17) 区间内的整数,`Knut` 是 [0, 29) 区间内的整数。
### 输出格式:
在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。
### 输入样例 1:
10.16.27 14.1.28
### 输出样例 1:
3.2.1
### 输入样例 2:
14.1.28 10.16.27
### 输出样例 2:
-3.2.1
## 思路
+28 -14
View File
@@ -9,20 +9,34 @@ permalink: Basic/1038.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求读入 <span>$N$</span> 名学生的成绩,将获得某一给定分数的学生人数输出。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第 1 行给出不超过 <span>$10^5$</span> 的正整数 <span>$N$</span>,即学生总人数。随后一行给出 <span>$N$</span> 名学生的百分制整数成绩,中间以空格分隔。最后一行给出要查询的分数个数 <span>$K$</span>(不超过 <span>$N$</span> 的正整数),随后是 <span>$K$</span> 个分数,中间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10
60 75 90 55 75 99 82 90 75 50
3 75 90 88
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3 2 0
</code></pre>
</div>{% endraw %}
本题要求读入 $N$ 名学生的成绩,将获得某一给定分数的学生人数输出。
### 输入格式:
输入在第 1 行给出不超过 $10^5$ 的正整数 $N$ ,即学生总人数。随后一行给出 $N$
名学生的百分制整数成绩,中间以空格分隔。最后一行给出要查询的分数个数 $K$ (不超过 $N$ 的正整数),随后是 $K$ 个分数,中间以空格分隔。
### 输出格式:
在一行中按查询顺序给出得分等于指定分数的学生人数,中间以空格分隔,但行末不得有多余空格。
### 输入样例:
10
60 75 90 55 75 99 82 90 75 50
3 75 90 88
### 输出样例:
3 2 0
## 思路
+47 -23
View File
@@ -9,29 +9,53 @@ permalink: Basic/1039.html
## 题目
{% raw %}<div class="ques-view"><p>小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。</p>
<p>为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。</p>
<p><img alt="figbuy.jpg" src="https://images.ptausercontent.com/b7e2ffa6-8819-436d-ad79-a41263abe914.jpg"/></p>
<p>图 1</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例。每个测试用例分别在 2 行中先后给出摊主的珠串和小红想做的珠串,两串都不超过 1000 个珠子。</p>
<h3 id="-">输出格式:</h3>
<p>如果可以买,则在一行中输出 <code>Yes</code> 以及有多少多余的珠子;如果不可以买,则在一行中输出 <code>No</code> 以及缺了多少珠子。其间以 1 个空格分隔。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">ppRYYGrrYBR2258
YrR8RrY
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">Yes 8
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">ppRYYGrrYB225
YrR8RrY
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">No 2
</code></pre>
</div>{% endraw %}
小红想买些珠子做一串自己喜欢的珠串。卖珠子的摊主有很多串五颜六色的珠串,但是不肯把任何一串拆散了卖。于是小红要你帮忙判断一下,某串珠子里是否包含了全部自己想要的珠子?如果是,那么告诉她有多少多余的珠子;如果不是,那么告诉她缺了多少珠子。
为方便起见,我们用[0-9]、[a-z]、[A-Z]范围内的字符来表示颜色。例如在图1中,第3串是小红想做的珠串;那么第1串可以买,因为包含了全部她想要的珠子,还多了8颗不需要的珠子;第2串不能买,因为没有黑色珠子,并且少了一颗红色的珠子。
![figbuy.jpg](https://images.ptausercontent.com/b7e2ffa6-8819-436d-ad79-a41263abe914.jpg)
图 1
### 输入格式:
每个输入包含 1 个测试用例。每个测试用例分别在 2 行中先后给出摊主的珠串和小红想做的珠串,两串都不超过 1000 个珠子。
### 输出格式:
如果可以买,则在一行中输出 `Yes` 以及有多少多余的珠子;如果不可以买,则在一行中输出 `No` 以及缺了多少珠子。其间以 1 个空格分隔。
### 输入样例 1:
ppRYYGrrYBR2258
YrR8RrY
### 输出样例 1:
Yes 8
### 输入样例 2:
ppRYYGrrYB225
YrR8RrY
### 输出样例 2:
No 2
## 思路
+28 -13
View File
@@ -9,19 +9,34 @@ permalink: Basic/1040.html
## 题目
{% raw %}<div class="ques-view"><p>字符串 <code>APPAPT</code> 中包含了两个单词 <code>PAT</code>,其中第一个 <code>PAT</code> 是第 2 位(<code>P</code>),第 4 位(<code>A</code>),第 6 位(<code>T</code>);第二个 <code>PAT</code> 是第 3 位(<code>P</code>),第 4 位(<code>A</code>),第 6 位(<code>T</code>)。</p>
<p>现给定字符串,问一共可以形成多少个 <code>PAT</code>?</p>
<h3 id="-">输入格式:</h3>
<p>输入只有一行,包含一个字符串,长度不超过<span>$10^5$</span>,只包含 <code>P</code>、<code>A</code>、<code>T</code> 三种字母。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出给定字符串中包含多少个 <code>PAT</code>。由于结果可能比较大,只输出对 1000000007 取余数的结果。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">APPAPT
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">2
</code></pre>
</div>{% endraw %}
字符串 `APPAPT` 中包含了两个单词 `PAT`,其中第一个 `PAT` 是第 2 位(`P`),第 4 位(`A`),第 6 位(`T`);第二个
`PAT` 是第 3 位(`P`),第 4 位(`A`),第 6 位(`T`)。
现给定字符串,问一共可以形成多少个 `PAT`?
### 输入格式:
输入只有一行,包含一个字符串,长度不超过 $10^5$ ,只包含 `P`、`A`、`T` 三种字母。
### 输出格式:
在一行中输出给定字符串中包含多少个 `PAT`。由于结果可能比较大,只输出对 1000000007 取余数的结果。
### 输入样例:
APPAPT
### 输出样例:
2
## 思路
+37 -20
View File
@@ -9,26 +9,43 @@ permalink: Basic/1041.html
## 题目
{% raw %}<div class="ques-view"><p>每个 PAT 考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 <span>$N$</span>(<span>$\le 1000$</span>),随后 <span>$N$</span> 行,每行给出一个考生的信息:<code>准考证号 试机座位号 考试座位号</code>。其中<code>准考证号</code>由 14 位数字组成,座位从 1 到 <span>$N$</span> 编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。</p>
<p>考生信息之后,给出一个正整数 <span>$M$</span>(<span>$\le N$</span>),随后一行中给出 <span>$M$</span> 个待查询的试机座位号码,以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">10120150912002 2
10120150912119 1
</code></pre>
</div>{% endraw %}
每个 PAT
考生在参加考试时都会被分配两个座位号,一个是试机座位,一个是考试座位。正常情况下,考生在入场时先得到试机座位号码,入座进入试机状态后,系统会显示该考生的考试座位号码,考试时考生需要换到考试座位就座。但有些考生迟到了,试机已经结束,他们只能拿着领到的试机座位号码求助于你,从后台查出他们的考试座位号码。
### 输入格式:
输入第一行给出一个正整数 $N$ ( $\le 1000$ ),随后 $N$ 行,每行给出一个考生的信息:`准考证号 试机座位号
考试座位号`。其中`准考证号`由 14 位数字组成,座位从 1 到 $N$
编号。输入保证每个人的准考证号都不同,并且任何时候都不会把两个人分配到同一个座位上。
考生信息之后,给出一个正整数 $M$ ( $\le N$ ),随后一行中给出 $M$ 个待查询的试机座位号码,以空格分隔。
### 输出格式:
对应每个需要查询的试机座位号码,在一行中输出对应考生的准考证号和考试座位号码,中间用 1 个空格分隔。
### 输入样例:
4
10120150912233 2 4
10120150912119 4 1
10120150912126 1 3
10120150912002 3 2
2
3 4
### 输出样例:
10120150912002 2
10120150912119 1
## 思路
+26 -12
View File
@@ -9,18 +9,32 @@ permalink: Basic/1042.html
## 题目
{% raw %}<div class="ques-view"><p>请编写程序,找出一段给定文字中出现最频繁的那个英文字母。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出一个长度不超过 1000 的字符串。字符串由 ASCII 码表中任意可见字符及空格组成,至少包含 1 个英文字母,以回车结束(回车不算在内)。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔。如果有并列,则输出按字母序最小的那个字母。统计时不区分大小写,输出小写字母。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">This is a simple TEST. There ARE numbers and other symbols 1&amp;2&amp;3...........
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">e 7
</code></pre>
</div>{% endraw %}
请编写程序,找出一段给定文字中出现最频繁的那个英文字母。
### 输入格式:
输入在一行中给出一个长度不超过 1000 的字符串。字符串由 ASCII 码表中任意可见字符及空格组成,至少包含 1
个英文字母,以回车结束(回车不算在内)。
### 输出格式:
在一行中输出出现频率最高的那个英文字母及其出现次数,其间以空格分隔。如果有并列,则输出按字母序最小的那个字母。统计时不区分大小写,输出小写字母。
### 输入样例:
This is a simple TEST. There ARE numbers and other symbols 1&2&3...........
### 输出样例:
e 7
## 思路
+27 -12
View File
@@ -9,18 +9,33 @@ permalink: Basic/1043.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个长度不超过 <span>$10^4$</span> 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 <code>PATestPATest....</code> 这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest 的顺序打印,直到所有字符都被输出。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出一个长度不超过 <span>$10^4$</span> 的、仅由英文字母构成的非空字符串。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中按题目要求输出排序后的字符串。题目保证输出非空。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">redlesPayBestPATTopTeePHPereatitAPPT
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">PATestPATestPTetPTePePee
</code></pre>
</div>{% endraw %}
给定一个长度不超过 $10^4$ 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 `PATestPATest....`
这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按 PATest
的顺序打印,直到所有字符都被输出。
### 输入格式:
输入在一行中给出一个长度不超过 $10^4$ 的、仅由英文字母构成的非空字符串。
### 输出格式:
在一行中按题目要求输出排序后的字符串。题目保证输出非空。
### 输入样例:
redlesPayBestPATTopTeePHPereatitAPPT
### 输出样例:
PATestPATestPTetPTePePee
## 思路
+39 -25
View File
@@ -9,31 +9,45 @@ permalink: Basic/1044.html
## 题目
{% raw %}<div class="ques-view"><p>火星人是以 13 进制计数的:</p>
<ul>
<li>地球人的 0 被火星人称为 tret。</li>
<li>地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。</li>
<li>火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。</li>
</ul>
<p>例如地球人的数字 <code>29</code> 翻译成火星文就是 <code>hel mar</code>;而火星文 <code>elo nov</code> 对应地球数字 <code>115</code>。为了方便交流,请你编写程序实现地球和火星数字之间的互译。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 <span>$N$</span>(<span>$&lt;100$</span>),随后 <span>$N$</span> 行,每行给出一个 [0, 169) 区间内的数字 —— 或者是地球文,或者是火星文。</p>
<h3 id="-">输出格式:</h3>
<p>对应输入的每一行,在一行中输出翻译后的另一种语言的数字。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">4
29
5
elo nov
tam
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">hel mar
may
115
13
</code></pre>
</div>{% endraw %}
火星人是以 13 进制计数的:
* 地球人的 0 被火星人称为 tret。
* 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。
* 火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jou。
例如地球人的数字 `29` 翻译成火星文就是 `hel mar`;而火星文 `elo nov` 对应地球数字
`115`。为了方便交流,请你编写程序实现地球和火星数字之间的互译。
### 输入格式:
输入第一行给出一个正整数 $N$ ( $<100$ ),随后 $N$ 行,每行给出一个 [0, 169) 区间内的数字 —— 或者是地球文,或者是火星文。
### 输出格式:
对应输入的每一行,在一行中输出翻译后的另一种语言的数字。
### 输入样例:
4
29
5
elo nov
tam
### 输出样例:
hel mar
may
115
13
## 思路
+37 -22
View File
@@ -9,28 +9,43 @@ permalink: Basic/1045.html
## 题目
{% raw %}<div class="ques-view"><p>著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的 <span>$N$</span> 个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?</p>
<p>例如给定 $N = 5$, 排列是1、3、2、4、5。则:</p>
<ul>
<li>1 的左边没有元素,右边的元素都比它大,所以它可能是主元;</li>
<li>尽管 3 的左边元素都比它小,但其右边的 2 比它小,所以它不能是主元;</li>
<li>尽管 2 的右边元素都比它大,但其左边的 3 比它大,所以它不能是主元;</li>
<li>类似原因,4 和 5 都可能是主元。</li>
</ul>
<p>因此,有 3 个元素可能是主元。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第 1 行中给出一个正整数 <span>$N$</span>(<span>$\le 10^5$</span>); 第 2 行是空格分隔的 <span>$N$</span> 个不同的正整数,每个数不超过 <span>$10^9$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在第 1 行中输出有可能是主元的元素个数;在第 2 行中按递增顺序输出这些元素,其间以 1 个空格分隔,行首尾不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5
1 3 2 4 5
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3
1 4 5
</code></pre>
</div>{% endraw %}
著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。
给定划分后的 $N$ 个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?
例如给定 $N = 5$, 排列是1、3、2、4、5。则:
* 1 的左边没有元素,右边的元素都比它大,所以它可能是主元;
* 尽管 3 的左边元素都比它小,但其右边的 2 比它小,所以它不能是主元;
* 尽管 2 的右边元素都比它大,但其左边的 3 比它大,所以它不能是主元;
* 类似原因,4 和 5 都可能是主元。
因此,有 3 个元素可能是主元。
### 输入格式:
输入在第 1 行中给出一个正整数 $N$ ( $\le 10^5$ ); 第 2 行是空格分隔的 $N$ 个不同的正整数,每个数不超过 $10^9$ 。
### 输出格式:
在第 1 行中输出有可能是主元的元素个数;在第 2 行中按递增顺序输出这些元素,其间以 1 个空格分隔,行首尾不得有多余空格。
### 输入样例:
5
1 3 2 4 5
### 输出样例:
3
1 4 5
## 思路
+39 -20
View File
@@ -9,26 +9,45 @@ permalink: Basic/1046.html
## 题目
{% raw %}<div class="ques-view"><p>划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。</p>
<p>下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行先给出一个正整数 <span>$N$</span>(<span>$\le 100$</span>),随后 <span>$N$</span> 行,每行给出一轮划拳的记录,格式为:</p>
<pre><code>甲喊 甲划 乙喊 乙划
</code></pre><p>其中<code>喊</code>是喊出的数字,<code>划</code>是划出的数字,均为不超过 100 的正整数(两只手一起划)。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">1 2
</code></pre>
</div>{% endraw %}
划拳是古老中国酒文化的一个有趣的组成部分。酒桌上两人划拳的方法为:每人口中喊出一个数字,同时用手比划出一个数字。如果谁比划出的数字正好等于两人喊出的数字之和,谁就赢了,输家罚一杯酒。两人同赢或两人同输则继续下一轮,直到唯一的赢家出现。
下面给出甲、乙两人的划拳记录,请你统计他们最后分别喝了多少杯酒。
### 输入格式:
输入第一行先给出一个正整数 $N$ ( $\le 100$ ),随后 $N$ 行,每行给出一轮划拳的记录,格式为:
甲喊 甲划 乙喊 乙划
其中`喊`是喊出的数字,`划`是划出的数字,均为不超过 100 的正整数(两只手一起划)。
### 输出格式:
在一行中先后输出甲、乙两人喝酒的杯数,其间以一个空格分隔。
### 输入样例:
5
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
### 输出样例:
1 2
## 思路
+34 -19
View File
@@ -9,25 +9,40 @@ permalink: Basic/1047.html
## 题目
{% raw %}<div class="ques-view"><p>编程团体赛的规则为:每个参赛队由若干队员组成;所有队员独立比赛;参赛队的成绩为所有队员的成绩和;成绩最高的队获胜。</p>
<p>现给定所有队员的比赛成绩,请你编写程序找出冠军队。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 <span>$N$</span>(<span>$\le 10^4$</span>),即所有参赛队员总数。随后 <span>$N$</span> 行,每行给出一位队员的成绩,格式为:<code>队伍编号-队员编号 成绩</code>,其中<code>队伍编号</code>为 1 到 1000 的正整数,<code>队员编号</code>为 1 到 10 的正整数,<code>成绩</code>为 0 到 100 的整数。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出冠军队的编号和总成绩,其间以一个空格分隔。注意:题目保证冠军队是唯一的。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">11 176
</code></pre>
</div>{% endraw %}
编程团体赛的规则为:每个参赛队由若干队员组成;所有队员独立比赛;参赛队的成绩为所有队员的成绩和;成绩最高的队获胜。
现给定所有队员的比赛成绩,请你编写程序找出冠军队。
### 输入格式:
输入第一行给出一个正整数 $N$ ( $\le 10^4$ ),即所有参赛队员总数。随后 $N$ 行,每行给出一位队员的成绩,格式为:`队伍编号-队员编号
成绩`,其中`队伍编号`为 1 到 1000 的正整数,`队员编号`为 1 到 10 的正整数,`成绩`为 0 到 100 的整数。
### 输出格式:
在一行中输出冠军队的编号和总成绩,其间以一个空格分隔。注意:题目保证冠军队是唯一的。
### 输入样例:
6
3-10 99
11-5 87
102-1 0
102-3 100
11-9 89
3-2 61
### 输出样例:
11 176
## 思路
+27 -12
View File
@@ -9,18 +9,33 @@ permalink: Basic/1048.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A 的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B 的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中依次给出 A 和 B,均为不超过 100 位的正整数,其间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出加密后的结果。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">1234567 368782971
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3695Q8118
</code></pre>
</div>{% endraw %}
本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A
的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B
的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。
### 输入格式:
输入在一行中依次给出 A 和 B,均为不超过 100 位的正整数,其间以空格分隔。
### 输出格式:
在一行中输出加密后的结果。
### 输入样例:
1234567 368782971
### 输出样例:
3695Q8118
## 思路
+32 -14
View File
@@ -9,20 +9,38 @@ permalink: Basic/1049.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列 { 0.1, 0.2, 0.3, 0.4 },我们有 (0.1) (0.1, 0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4) (0.3) (0.3, 0.4) (0.4) 这 10 个片段。</p>
<p>给定正整数数列,求出全部片段包含的所有的数之和。如本例中 10 个片段总和是 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9 + 0.3 + 0.7 + 0.4 = 5.0。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个不超过 <span>$10^5$</span> 的正整数 <span>$N$</span>,表示数列中数的个数,第二行给出 <span>$N $</span> 个不超过 1.0 的正数,是数列中的数,其间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出该序列所有片段包含的数之和,精确到小数点后 2 位。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">4
0.1 0.2 0.3 0.4
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5.00
</code></pre>
</div>{% endraw %}
给定一个正数数列,我们可以从中截取任意的连续的几个数,称为片段。例如,给定数列 { 0.1, 0.2, 0.3, 0.4 },我们有 (0.1) (0.1,
0.2) (0.1, 0.2, 0.3) (0.1, 0.2, 0.3, 0.4) (0.2) (0.2, 0.3) (0.2, 0.3, 0.4)
(0.3) (0.3, 0.4) (0.4) 这 10 个片段。
给定正整数数列,求出全部片段包含的所有的数之和。如本例中 10 个片段总和是 0.1 + 0.3 + 0.6 + 1.0 + 0.2 + 0.5 + 0.9
+ 0.3 + 0.7 + 0.4 = 5.0。
### 输入格式:
输入第一行给出一个不超过 $10^5$ 的正整数 $N$ ,表示数列中数的个数,第二行给出 $N $ 个不超过 1.0
的正数,是数列中的数,其间以空格分隔。
### 输出格式:
在一行中输出该序列所有片段包含的数之和,精确到小数点后 2 位。
### 输入样例:
4
0.1 0.2 0.3 0.4
### 输出样例:
5.00
## 思路
+30 -16
View File
@@ -9,22 +9,36 @@ permalink: Basic/1050.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求将给定的 <span>$N$</span> 个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第 1 个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为 <span>$m$</span> 行 <span>$n$</span> 列,满足条件:<span>$m\times n$</span> 等于 <span>$N$</span>;<span>$m\ge n$</span>;且 <span>$m-n$</span> 取所有可能值中的最小值。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第 1 行中给出一个正整数 <span>$N$</span>,第 2 行给出 <span>$N$</span> 个待填充的正整数。所有数字不超过 <span>$10^4$</span>,相邻数字以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>输出螺旋矩阵。每行 <span>$n$</span> 个数字,共 <span>$m$</span> 行。相邻数字以 1 个空格分隔,行末不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">12
37 76 20 98 76 42 53 95 60 81 58 93
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">98 95 93
42 37 81
53 20 76
58 60 76
</code></pre>
</div>{% endraw %}
本题要求将给定的 $N$ 个正整数按非递增的顺序,填入“螺旋矩阵”。所谓“螺旋矩阵”,是指从左上角第 1 个格子开始,按顺时针螺旋方向填充。要求矩阵的规模为
$m$ 行 $n$ 列,满足条件: $m\times n$ 等于 $N$ ; $m\ge n$ ;且 $m-n$ 取所有可能值中的最小值。
### 输入格式:
输入在第 1 行中给出一个正整数 $N$ ,第 2 行给出 $N$ 个待填充的正整数。所有数字不超过 $10^4$ ,相邻数字以空格分隔。
### 输出格式:
输出螺旋矩阵。每行 $n$ 个数字,共 $m$ 行。相邻数字以 1 个空格分隔,行末不得有多余空格。
### 输入样例:
12
37 76 20 98 76 42 53 95 60 81 58 93
### 输出样例:
98 95 93
42 37 81
53 20 76
58 60 76
## 思路
+29 -13
View File
@@ -9,19 +9,35 @@ permalink: Basic/1051.html
## 题目
{% raw %}<div class="ques-view"><p>复数可以写成 <span>$(A + Bi)$</span> 的常规形式,其中 <span>$A$</span> 是实部,<span>$B$</span> 是虚部,<span>$i$</span> 是虚数单位,满足 <span>$i^2 = -1$</span>;也可以写成极坐标下的指数形式 <span>$(R\times e^{(Pi)})$</span>,其中 <span>$R$</span> 是复数模,<span>$P$</span> 是辐角,<span>$i$</span> 是虚数单位,其等价于三角形式 <span>$(R(\cos (P) + i \sin (P))$</span>。</p>
<p>现给定两个复数的 <span>$R$</span> 和 <span>$P$</span>,要求输出两数乘积的常规形式。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中依次给出两个复数的 <span>$R_1$</span>, <span>$P_1$</span>, <span>$R_2$</span>, <span>$P_2$</span>,数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中按照 <code>A+Bi</code> 的格式输出两数乘积的常规形式,实部和虚部均保留 2 位小数。注意:如果 <code>B</code> 是负数,则应该写成 <code>A-|B|i</code> 的形式。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">2.3 3.5 5.2 0.4
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">-8.68-8.23i
</code></pre>
</div>{% endraw %}
复数可以写成 $(A + Bi)$ 的常规形式,其中 $A$ 是实部, $B$ 是虚部, $i$ 是虚数单位,满足 $i^2 = -1$
;也可以写成极坐标下的指数形式 $(R\times e^{(Pi)})$ ,其中 $R$ 是复数模, $P$ 是辐角, $i$ 是虚数单位,其等价于三角形式
$(R(\cos (P) + i \sin (P))$ 。
现给定两个复数的 $R$ 和 $P$ ,要求输出两数乘积的常规形式。
### 输入格式:
输入在一行中依次给出两个复数的 $R_1$ , $P_1$ , $R_2$ , $P_2$ ,数字间以空格分隔。
### 输出格式:
在一行中按照 `A+Bi` 的格式输出两数乘积的常规形式,实部和虚部均保留 2 位小数。注意:如果 `B` 是负数,则应该写成 `A-|B|i` 的形式。
### 输入样例:
2.3 3.5 5.2 0.4
### 输出样例:
-8.68-8.23i
## 思路
+46 -25
View File
@@ -9,31 +9,52 @@ permalink: Basic/1052.html
## 题目
{% raw %}<div class="ques-view"><p>萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:</p>
<pre><code>[左手]([左眼][口][右眼])[右手]
</code></pre><p>现给出可选用的符号集合,请你按用户的要求输出表情。</p>
<h3 id="-">输入格式:</h3>
<p>输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号 <code>[]</code>内。题目保证每个集合都至少有一个符号,并不超过 10 个符号;每个符号包含 1 到 4 个非空字符。</p>
<p>之后一行给出一个正整数 K,为用户请求的个数。随后 K 行,每行给出一个用户的符号选择,顺序为左手、左眼、口、右眼、右手——这里只给出符号在相应集合中的序号(从 1 开始),数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对每个用户请求,在一行中输出生成的表情。若用户选择的序号不存在,则输出 <code>Are you kidding me? @\/@</code>。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">[╮][╭][o][~\][/~] [&lt;][&gt;]
[╯][╰][^][-][=][&gt;][&lt;][@][⊙]
[Д][▽][_][ε][^] ...
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">╮(╯▽╰)╭
&lt;(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@
</code></pre>
</div>{% endraw %}
萌萌哒表情符号通常由“手”、“眼”、“口”三个主要部分组成。简单起见,我们假设一个表情符号是按下列格式输出的:
[左手]([左眼][口][右眼])[右手]
现给出可选用的符号集合,请你按用户的要求输出表情。
### 输入格式:
输入首先在前三行顺序对应给出手、眼、口的可选符号集。每个符号括在一对方括号 `[]`内。题目保证每个集合都至少有一个符号,并不超过 10
个符号;每个符号包含 1 到 4 个非空字符。
之后一行给出一个正整数 K,为用户请求的个数。随后 K
行,每行给出一个用户的符号选择,顺序为左手、左眼、口、右眼、右手——这里只给出符号在相应集合中的序号(从 1 开始),数字间以空格分隔。
### 输出格式:
对每个用户请求,在一行中输出生成的表情。若用户选择的序号不存在,则输出 `Are you kidding me? @\/@`。
### 输入样例:
[╮][╭][o][~\][/~] [<][>]
[╯][╰][^][-][=][>][<][@][⊙]
[Д][▽][_][ε][^] ...
4
1 1 2 2 2
6 8 1 5 5
3 3 4 3 3
2 10 3 9 3
### 输出样例:
╮(╯▽╰)╭
<(@Д=)/~
o(^ε^)o
Are you kidding me? @\/@
## 思路
+43 -27
View File
@@ -9,33 +9,49 @@ permalink: Basic/1053.html
## 题目
{% raw %}<div class="ques-view"><p>在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断。判断方法如下:</p>
<ul>
<li><p>在观察期内,若存在超过一半的日子用电量低于某给定的阈值 <span>$e$</span>,则该住房为“可能空置”;</p>
</li>
<li><p>若观察期超过某给定阈值 <span>$D$</span> 天,且满足上一个条件,则该住房为“空置”。</p>
</li>
</ul>
<p>现给定某居民区的住户用电量数据,请你统计“可能空置”的比率和“空置”比率,即以上两种状态的住房占居民区住房总套数的百分比。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出正整数 <span>$N$</span>(<span>$\le 1000$</span>),为居民区住房总套数;正实数 <span>$e$</span>,即低电量阈值;正整数 <span>$D$</span>,即观察期阈值。随后 <span>$N$</span> 行,每行按以下格式给出一套住房的用电量数据:</p>
<p><span>$K$</span> <span>$E_1$</span> <span>$E_2$</span> ... <span>$E_K$</span></p>
<p>其中 <span>$K$</span> 为观察的天数,<span>$E_i$</span> 为第 <span>$i$</span> 天的用电量。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出“可能空置”的比率和“空置”比率的百分比值,其间以一个空格分隔,保留小数点后 1 位。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5 0.5 10
6 0.3 0.4 0.5 0.2 0.8 0.6
10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5
5 0.4 0.3 0.5 0.1 0.7
11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">40.0% 20.0%
</code></pre>
<p>(样例解释:第2、3户为“可能空置”,第4户为“空置”,其他户不是空置。)</p>
</div>{% endraw %}
在不打扰居民的前提下,统计住房空置率的一种方法是根据每户用电量的连续变化规律进行判断。判断方法如下:
* 在观察期内,若存在超过一半的日子用电量低于某给定的阈值 $e$ ,则该住房为“可能空置”;
* 若观察期超过某给定阈值 $D$ 天,且满足上一个条件,则该住房为“空置”。
现给定某居民区的住户用电量数据,请你统计“可能空置”的比率和“空置”比率,即以上两种状态的住房占居民区住房总套数的百分比。
### 输入格式:
输入第一行给出正整数 $N$ ( $\le 1000$ ),为居民区住房总套数;正实数 $e$ ,即低电量阈值;正整数 $D$ ,即观察期阈值。随后 $N$
行,每行按以下格式给出一套住房的用电量数据:
$K$ $E_1$ $E_2$ ... $E_K$
其中 $K$ 为观察的天数, $E_i$ 为第 $i$ 天的用电量。
### 输出格式:
在一行中输出“可能空置”的比率和“空置”比率的百分比值,其间以一个空格分隔,保留小数点后 1 位。
### 输入样例:
5 0.5 10
6 0.3 0.4 0.5 0.2 0.8 0.6
10 0.0 0.1 0.2 0.3 0.0 0.8 0.6 0.7 0.0 0.5
5 0.4 0.3 0.5 0.1 0.7
11 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1
11 2 2 2 1 1 0.1 1 0.1 0.1 0.1 0.1
### 输出样例:
40.0% 20.0%
(样例解释:第2、3户为“可能空置”,第4户为“空置”,其他户不是空置。)
## 思路
+51 -26
View File
@@ -9,32 +9,57 @@ permalink: Basic/1054.html
## 题目
{% raw %}<div class="ques-view"><p>本题的基本要求非常简单:给定 <span>$N$</span> 个实数,计算它们的平均值。但复杂的是有些输入数据可能是非法的。一个“合法”的输入是 [<span>$-1000, 1000$</span>] 区间内的实数,并且最多精确到小数点后 2 位。当你计算平均值的时候,不能把那些非法的数据算在内。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出正整数 <span>$N$</span>(<span>$\le 100$</span>)。随后一行给出 <span>$N$</span> 个实数,数字间以一个空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>对每个非法输入,在一行中输出 <code>ERROR: X is not a legal number</code>,其中 <code>X</code> 是输入。最后在一行中输出结果:<code>The average of K numbers is Y</code>,其中 <code>K</code> 是合法输入的个数,<code>Y</code> 是它们的平均值,精确到小数点后 2 位。如果平均值无法计算,则用 <code>Undefined</code> 替换 <code>Y</code>。如果 <code>K</code> 为 1,则输出 <code>The average of 1 number is Y</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">7
5 -3.2 aaa 9999 2.3.4 7.123 2.35
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">ERROR: aaa is not a legal number
ERROR: 9999 is not a legal number
ERROR: 2.3.4 is not a legal number
ERROR: 7.123 is not a legal number
The average of 3 numbers is 1.38
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">2
aaa -9999
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">ERROR: aaa is not a legal number
ERROR: -9999 is not a legal number
The average of 0 numbers is Undefined
</code></pre>
</div>{% endraw %}
本题的基本要求非常简单:给定 $N$ 个实数,计算它们的平均值。但复杂的是有些输入数据可能是非法的。一个“合法”的输入是 [ $-1000, 1000$ ]
区间内的实数,并且最多精确到小数点后 2 位。当你计算平均值的时候,不能把那些非法的数据算在内。
### 输入格式:
输入第一行给出正整数 $N$ ( $\le 100$ )。随后一行给出 $N$ 个实数,数字间以一个空格分隔。
### 输出格式:
对每个非法输入,在一行中输出 `ERROR: X is not a legal number`,其中 `X` 是输入。最后在一行中输出结果:`The
average of K numbers is Y`,其中 `K` 是合法输入的个数,`Y` 是它们的平均值,精确到小数点后 2
位。如果平均值无法计算,则用 `Undefined` 替换 `Y`。如果 `K` 为 1,则输出 `The average of 1 number is
Y`。
### 输入样例 1:
7
5 -3.2 aaa 9999 2.3.4 7.123 2.35
### 输出样例 1:
ERROR: aaa is not a legal number
ERROR: 9999 is not a legal number
ERROR: 2.3.4 is not a legal number
ERROR: 7.123 is not a legal number
The average of 3 numbers is 1.38
### 输入样例 2:
2
aaa -9999
### 输出样例 2:
ERROR: aaa is not a legal number
ERROR: -9999 is not a legal number
The average of 0 numbers is Undefined
## 思路
+50 -37
View File
@@ -9,43 +9,56 @@ permalink: Basic/1055.html
## 题目
{% raw %}<div class="ques-view"><p>拍集体照时队形很重要,这里对给定的 <span>$N$</span> 个人 <span>$K$</span> 排的队形设计排队规则如下:</p>
<ul>
<li><p>每排人数为 <span>$N/K$</span>(向下取整),多出来的人全部站在最后一排;</p>
</li>
<li><p>后排所有人的个子都不比前排任何人矮;</p>
</li>
<li><p>每排中最高者站中间(中间位置为 <span>$m/2+1$</span>,其中 <span>$m$</span> 为该排人数,除法向下取整);</p>
</li>
<li><p>每排其他人以中间人为轴,按身高非增序,先右后左交替入队站在中间人的两侧(例如5人身高为190、188、186、175、170,则队形为175、188、190、186、170。这里假设你面对拍照者,所以你的左边是中间人的右边);</p>
</li>
<li><p>若多人身高相同,则按名字的字典序升序排列。这里保证无重名。</p>
</li>
</ul>
<p>现给定一组拍照人,请编写程序输出他们的队形。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例。每个测试用例第 1 行给出两个正整数 <span>$N$</span>(<span>$\le 10^4$</span>,总人数)和 <span>$K$</span>(<span>$\le 10$</span>,总排数)。随后 <span>$N$</span> 行,每行给出一个人的名字(不包含空格、长度不超过 8 个英文字母)和身高([30, 300] 区间内的整数)。</p>
<h3 id="-">输出格式:</h3>
<p>输出拍照的队形。即K排人名,其间以空格分隔,行末不得有多余空格。注意:假设你面对拍照者,后排的人输出在上方,前排输出在下方。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John
</code></pre>
</div>{% endraw %}
拍集体照时队形很重要,这里对给定的 $N$ 个人 $K$ 排的队形设计排队规则如下:
* 每排人数为 $N/K$ (向下取整),多出来的人全部站在最后一排;
* 后排所有人的个子都不比前排任何人矮;
* 每排中最高者站中间(中间位置为 $m/2+1$ ,其中 $m$ 为该排人数,除法向下取整);
* 每排其他人以中间人为轴,按身高非增序,先右后左交替入队站在中间人的两侧(例如5人身高为190、188、186、175、170,则队形为175、188、190、186、170。这里假设你面对拍照者,所以你的左边是中间人的右边);
* 若多人身高相同,则按名字的字典序升序排列。这里保证无重名。
现给定一组拍照人,请编写程序输出他们的队形。
### 输入格式:
每个输入包含 1 个测试用例。每个测试用例第 1 行给出两个正整数 $N$ ( $\le 10^4$ ,总人数)和 $K$ ( $\le 10$
,总排数)。随后 $N$ 行,每行给出一个人的名字(不包含空格、长度不超过 8 个英文字母)和身高([30, 300] 区间内的整数)。
### 输出格式:
输出拍照的队形。即K排人名,其间以空格分隔,行末不得有多余空格。注意:假设你面对拍照者,后排的人输出在上方,前排输出在下方。
### 输入样例:
10 3
Tom 188
Mike 170
Eva 168
Tim 160
Joe 190
Ann 168
Bob 175
Nick 186
Amy 160
John 159
### 输出样例:
Bob Tom Joe Nick
Ann Mike Eva
Tim Amy John
## 思路
+27 -13
View File
@@ -9,19 +9,33 @@ permalink: Basic/1056.html
## 题目
{% raw %}<div class="ques-view"><p>给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字。要求所有可能组合出来的 2 位数字的和。例如给定 2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行中给出 N(1 <span>$&lt;$</span> N <span>$&lt;$</span> 10),随后一行给出 N 个不同的非 0 个位数字。数字间以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>输出所有可能组合出来的2位数字的和。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3
2 8 5
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">330
</code></pre>
</div>{% endraw %}
给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字。要求所有可能组合出来的 2 位数字的和。例如给定
2、5、8,则可以组合出:25、28、52、58、82、85,它们的和为330。
### 输入格式:
输入在第一行中给出 N(1 $<$ N $<$ 10),随后一行给出 N 个不同的非 0 个位数字。数字间以空格分隔。
### 输出格式:
输出所有可能组合出来的2位数字的和。
### 输入样例:
3
2 8 5
### 输出样例:
330
## 思路
+27 -12
View File
@@ -9,18 +9,33 @@ permalink: Basic/1057.html
## 题目
{% raw %}<div class="ques-view"><p>给定一串长度不超过 <span>$10^5$</span> 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有多少 0、多少 1。例如给定字符串 <code>PAT (Basic)</code>,其字母序号之和为:16+1+20+2+1+19+9+3=71,而 71 的二进制是 1000111,即有 3 个 0、4 个 1。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出长度不超过 <span>$10^5$</span>、以回车结束的字符串。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中先后输出 0 的个数和 1 的个数,其间以空格分隔。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">PAT (Basic)
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3 4
</code></pre>
</div>{% endraw %}
给定一串长度不超过 $10^5$ 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数
N,然后再分析一下 N 的二进制表示中有多少 0、多少 1。例如给定字符串 `PAT
(Basic)`,其字母序号之和为:16+1+20+2+1+19+9+3=71,而 71 的二进制是 1000111,即有 3 个 0、4 个 1。
### 输入格式:
输入在一行中给出长度不超过 $10^5$ 、以回车结束的字符串。
### 输出格式:
在一行中先后输出 0 的个数和 1 的个数,其间以空格分隔。
### 输入样例:
PAT (Basic)
### 输出样例:
3 4
## 思路
+41 -22
View File
@@ -9,28 +9,47 @@ permalink: Basic/1058.html
## 题目
{% raw %}<div class="ques-view"><p>批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出两个正整数 N(<span>$\le$</span> 1000)和 M(<span>$\le$</span> 100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 <code>(选中的选项个数 选项1 ……)</code>,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。</p>
<h3 id="-">输出格式:</h3>
<p>按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从 1 开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 <code>Too simple</code>。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">3
6
5
2 2 3 4
</code></pre>
</div>{% endraw %}
批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多。
### 输入格式:
输入在第一行给出两个正整数 N( $\le$ 1000)和 M( $\le$ 100),分别是学生人数和多选题的个数。随后 M
行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5
的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N
行,每行给出一个学生的答题情况,其每题答案格式为 `(选中的选项个数 选项1
……)`,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
### 输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行。注意判题时只有选择全部正确才能得到该题的分数。最后一行输出错得最多的题目的错误次数和编号(题目按照输入的顺序从
1 开始编号)。如果有并列,则按编号递增顺序输出。数字间用空格分隔,行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 `Too
simple`。
### 输入样例:
3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (2 b d) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (2 b c) (4 a b c d)
### 输出样例:
3
6
5
2 2 3 4
## 思路
+52 -36
View File
@@ -9,42 +9,58 @@ permalink: Basic/1059.html
## 题目
{% raw %}<div class="ques-view"><p>C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽:</p>
<ul>
<li>0、冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。</li>
<li>1、排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!</li>
<li>2、其他人将得到巧克力。</li>
</ul>
<p>给定比赛的最终排名以及一系列参赛者的 ID,你要给出这些参赛者应该获得的奖品。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 <span>$N$</span>(<span>$\le 10^4$</span>),是参赛者人数。随后 <span>$N$</span> 行给出最终排名,每行按排名顺序给出一位参赛者的 ID(4 位数字组成)。接下来给出一个正整数 <span>$K$</span> 以及 <span>$K$</span> 个需要查询的 ID。</p>
<h3 id="-">输出格式:</h3>
<p>对每个要查询的 ID,在一行中输出 <code>ID: 奖品</code>,其中奖品或者是 <code>Mystery Award</code>(神秘大奖)、或者是 <code>Minion</code>(小黄人)、或者是 <code>Chocolate</code>(巧克力)。如果所查 ID 根本不在排名里,打印 <code>Are you kidding?</code>(耍我呢?)。如果该 ID 已经查过了(即奖品已经领过了),打印 <code>ID: Checked</code>(不能多吃多占)。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6
1111
6666
8888
1234
5555
0001
6
8888
0001
1111
2222
8888
2222
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?
</code></pre>
</div>{% endraw %}
C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛。既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽:
* 0、冠军将赢得一份“神秘大奖”(比如很巨大的一本学生研究论文集……)。
* 1、排名为素数的学生将赢得最好的奖品 —— 小黄人玩偶!
* 2、其他人将得到巧克力。
给定比赛的最终排名以及一系列参赛者的 ID,你要给出这些参赛者应该获得的奖品。
### 输入格式:
输入第一行给出一个正整数 $N$ ( $\le 10^4$ ),是参赛者人数。随后 $N$ 行给出最终排名,每行按排名顺序给出一位参赛者的 ID(4
位数字组成)。接下来给出一个正整数 $K$ 以及 $K$ 个需要查询的 ID。
### 输出格式:
对每个要查询的 ID,在一行中输出 `ID: 奖品`,其中奖品或者是 `Mystery Award`(神秘大奖)、或者是 `Minion`(小黄人)、或者是
`Chocolate`(巧克力)。如果所查 ID 根本不在排名里,打印 `Are you kidding?`(耍我呢?)。如果该 ID
已经查过了(即奖品已经领过了),打印 `ID: Checked`(不能多吃多占)。
### 输入样例:
6
1111
6666
8888
1234
5555
0001
6
8888
0001
1111
2222
8888
2222
### 输出样例:
8888: Minion
0001: Chocolate
1111: Mystery Award
2222: Are you kidding?
8888: Checked
2222: Are you kidding?
## 思路
+29 -14
View File
@@ -9,20 +9,35 @@ permalink: Basic/1060.html
## 题目
{% raw %}<div class="ques-view"><p>英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” <span>$E$</span> ,即满足有 <span>$E$</span> 天骑车超过 <span>$E$</span> 英里的最大整数 <span>$E$</span>。据说爱丁顿自己的 <span>$E$</span> 等于87。</p>
<p>现给定某人 <span>$N$</span> 天的骑车距离,请你算出对应的爱丁顿数 <span>$E$</span>(<span>$\le N$</span>)。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 <span>$N$</span> (<span>$\le 10^5$</span>),即连续骑车的天数;第二行给出 <span>$N$</span> 个非负整数,代表每天的骑车距离。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中给出 <span>$N$</span> 天的爱丁顿数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">10
6 7 6 9 3 10 8 2 7 8
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">6
</code></pre>
</div>{% endraw %}
英国天文学家爱丁顿很喜欢骑车。据说他为了炫耀自己的骑车功力,还定义了一个“爱丁顿数” $E$ ,即满足有 $E$ 天骑车超过 $E$ 英里的最大整数 $E$
。据说爱丁顿自己的 $E$ 等于87。
现给定某人 $N$ 天的骑车距离,请你算出对应的爱丁顿数 $E$ ( $\le N$ )。
### 输入格式:
输入第一行给出一个正整数 $N$ ( $\le 10^5$ ),即连续骑车的天数;第二行给出 $N$ 个非负整数,代表每天的骑车距离。
### 输出格式:
在一行中给出 $N$ 天的爱丁顿数。
### 输入样例:
10
6 7 6 9 3 10 8 2 7 8
### 输出样例:
6
## 思路
+33 -19
View File
@@ -9,25 +9,39 @@ permalink: Basic/1061.html
## 题目
{% raw %}<div class="ques-view"><p>判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出两个不超过 100 的正整数 N 和 M,分别是学生人数和判断题数量。第二行给出 M 个不超过 5 的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0 代表“非”,1 代表“是”。随后 N 行,每行给出一个学生的解答。数字间均以空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>按照输入的顺序输出每个学生的得分,每个分数占一行。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3 6
2 1 3 3 4 5
0 0 1 0 1 1
0 1 1 0 0 1
1 0 1 0 1 0
1 1 0 0 1 1
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">13
11
12
</code></pre>
</div>{% endraw %}
判断题的评判很简单,本题就要求你写个简单的程序帮助老师判题并统计学生们判断题的得分。
### 输入格式:
输入在第一行给出两个不超过 100 的正整数 N 和 M,分别是学生人数和判断题数量。第二行给出 M 个不超过 5
的正整数,是每道题的满分值。第三行给出每道题对应的正确答案,0 代表“非”,1 代表“是”。随后 N 行,每行给出一个学生的解答。数字间均以空格分隔。
### 输出格式:
按照输入的顺序输出每个学生的得分,每个分数占一行。
### 输入样例:
3 6
2 1 3 3 4 5
0 0 1 0 1 1
0 1 1 0 0 1
1 0 1 0 1 0
1 1 0 0 1 1
### 输出样例:
13
11
12
## 思路
+28 -13
View File
@@ -9,19 +9,34 @@ permalink: Basic/1062.html
## 题目
{% raw %}<div class="ques-view"><p>一个分数一般写成两个整数相除的形式:<span>$N/M$</span>,其中 <span>$M$</span> 不为0。最简分数是指分子和分母没有公约数的分数表示形式。</p>
<p>现给定两个不相等的正分数 <span>$N_1/M_1$</span> 和 <span>$N_2/M_2$</span>,要求你按从小到大的顺序列出它们之间分母为 <span>$K$</span> 的最简分数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中按 <span>$N/M$</span> 的格式给出两个正分数,随后是一个正整数分母 <span>$K$</span>,其间以空格分隔。题目保证给出的所有整数都不超过 1000。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中按 <span>$N/M$</span> 的格式列出两个给定分数之间分母为 <span>$K$</span> 的所有最简分数,按从小到大的顺序,其间以 1 个空格分隔。行首尾不得有多余空格。题目保证至少有 1 个输出。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">7/18 13/20 12
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5/12 7/12
</code></pre>
</div>{% endraw %}
一个分数一般写成两个整数相除的形式: $N/M$ ,其中 $M$ 不为0。最简分数是指分子和分母没有公约数的分数表示形式。
现给定两个不相等的正分数 $N_1/M_1$ 和 $N_2/M_2$ ,要求你按从小到大的顺序列出它们之间分母为 $K$ 的最简分数。
### 输入格式:
输入在一行中按 $N/M$ 的格式给出两个正分数,随后是一个正整数分母 $K$ ,其间以空格分隔。题目保证给出的所有整数都不超过 1000。
### 输出格式:
在一行中按 $N/M$ 的格式列出两个给定分数之间分母为 $K$ 的所有最简分数,按从小到大的顺序,其间以 1
个空格分隔。行首尾不得有多余空格。题目保证至少有 1 个输出。
### 输入样例:
7/18 13/20 12
### 输出样例:
5/12 7/12
## 思路
+34 -18
View File
@@ -9,24 +9,40 @@ permalink: Basic/1063.html
## 题目
{% raw %}<div class="ques-view"><p>在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界。换言之,对于给定的 <span>$n$</span> 个复数空间的特征值 { <span>$a_1+b_1i, \cdots , a_n+b_ni$</span> },它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模。</p>
<p>现在给定一些复数空间的特征值,请你计算并输出这些特征值的谱半径。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出正整数 N(<span>$\le$</span> 10 000)是输入的特征值的个数。随后 N 行,每行给出 1 个特征值的实部和虚部,其间以空格分隔。注意:题目保证实部和虚部均为绝对值不超过 1000 的整数。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出谱半径,四舍五入保留小数点后 2 位。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5
0 1
2 0
-1 0
3 3
0 -3
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">4.24
</code></pre>
</div>{% endraw %}
在数学中,矩阵的“谱半径”是指其特征值的模集合的上确界。换言之,对于给定的 $n$ 个复数空间的特征值 { $a_1+b_1i, \cdots ,
a_n+b_ni$ },它们的模为实部与虚部的平方和的开方,而“谱半径”就是最大模。
现在给定一些复数空间的特征值,请你计算并输出这些特征值的谱半径。
### 输入格式:
输入第一行给出正整数 N( $\le$ 10 000)是输入的特征值的个数。随后 N 行,每行给出 1
个特征值的实部和虚部,其间以空格分隔。注意:题目保证实部和虚部均为绝对值不超过 1000 的整数。
### 输出格式:
在一行中输出谱半径,四舍五入保留小数点后 2 位。
### 输入样例:
5
0 1
2 0
-1 0
3 3
0 -3
### 输出样例:
4.24
## 思路
+28 -14
View File
@@ -9,20 +9,34 @@ permalink: Basic/1064.html
## 题目
{% raw %}<div class="ques-view"><p>如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如 123 和 51 就是朋友数,因为 1+2+3 = 5+1 = 6,而 6 就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出正整数 N。随后一行给出 N 个正整数,数字间以空格分隔。题目保证所有数字小于 <span>$10^4$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>首先第一行输出给定数字中不同的朋友证号的个数;随后一行按递增顺序输出这些朋友证号,数字间隔一个空格,且行末不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">8
123 899 51 998 27 33 36 12
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">4
3 6 9 26
</code></pre>
</div>{% endraw %}
如果两个整数各位数字的和是一样的,则被称为是“朋友数”,而那个公共的和就是它们的“朋友证号”。例如 123 和 51 就是朋友数,因为 1+2+3 =
5+1 = 6,而 6 就是它们的朋友证号。给定一些整数,要求你统计一下它们中有多少个不同的朋友证号。
### 输入格式:
输入第一行给出正整数 N。随后一行给出 N 个正整数,数字间以空格分隔。题目保证所有数字小于 $10^4$ 。
### 输出格式:
首先第一行输出给定数字中不同的朋友证号的个数;随后一行按递增顺序输出这些朋友证号,数字间隔一个空格,且行末不得有多余空格。
### 输入样例:
8
123 899 51 998 27 33 36 12
### 输出样例:
4
3 6 9 26
## 思路
+33 -18
View File
@@ -9,24 +9,39 @@ permalink: Basic/1065.html
## 题目
{% raw %}<div class="ques-view"><p>“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 N(<span>$\le$</span> 50 000),是已知夫妻/伴侣的对数;随后 N 行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个 ID 号,为 5 位数字(从 00000 到 99999),ID 间以空格分隔;之后给出一个正整数 M(<span>$\le$</span> 10 000),为参加派对的总人数;随后一行给出这 M 位客人的 ID,以空格分隔。题目保证无人重婚或脚踩两条船。</p>
<h3 id="-">输出格式:</h3>
<p>首先第一行输出落单客人的总人数;随后第二行按 ID 递增顺序列出落单的客人。ID 间用 1 个空格分隔,行的首尾不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">5
10000 23333 44444 55555 88888
</code></pre>
</div>{% endraw %}
“单身狗”是中文对于单身人士的一种爱称。本题请你从上万人的大型派对中找出落单的客人,以便给予特殊关爱。
### 输入格式:
输入第一行给出一个正整数 N( $\le$ 50 000),是已知夫妻/伴侣的对数;随后 N 行,每行给出一对夫妻/伴侣——为方便起见,每人对应一个 ID
号,为 5 位数字(从 00000 到 99999),ID 间以空格分隔;之后给出一个正整数 M( $\le$ 10
000),为参加派对的总人数;随后一行给出这 M 位客人的 ID,以空格分隔。题目保证无人重婚或脚踩两条船。
### 输出格式:
首先第一行输出落单客人的总人数;随后第二行按 ID 递增顺序列出落单的客人。ID 间用 1 个空格分隔,行的首尾不得有多余空格。
### 输入样例:
3
11111 22222
33333 44444
55555 66666
7
55555 44444 10000 88888 22222 11111 23333
### 输出样例:
5
10000 23333 44444 55555 88888
## 思路
+33 -17
View File
@@ -9,23 +9,39 @@ permalink: Basic/1066.html
## 题目
{% raw %}<div class="ques-view"><p>图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出一幅图像的分辨率,即两个正整数 <span>$M$</span> 和 <span>$N$</span>(<span>$0 &lt; M, N \le 500$</span>),另外是待过滤的灰度值区间端点 <span>$A$</span> 和 <span>$B$</span>(<span>$0 \le A &lt; B \le 255$</span>)、以及指定的替换灰度值。随后 <span>$M$</span> 行,每行给出 <span>$N$</span> 个像素点的灰度值,其间以空格分隔。所有灰度值都在 [0, 255] 区间内。</p>
<h3 id="-">输出格式:</h3>
<p>输出按要求过滤后的图像。即输出 <span>$M$</span> 行,每行 <span>$N$</span> 个像素灰度值,每个灰度值占 3 位(例如黑色要显示为 <code>000</code>),其间以一个空格分隔。行首尾不得有多余空格。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">003 189 254 000 000
000 233 151 099 000
088 000 000 000 255
</code></pre>
</div>{% endraw %}
图像过滤是把图像中不重要的像素都染成背景色,使得重要部分被凸显出来。现给定一幅黑白图像,要求你将灰度值位于某指定区间内的所有像素颜色都用一种指定的颜色替换。
### 输入格式:
输入在第一行给出一幅图像的分辨率,即两个正整数 $M$ 和 $N$ ( $0 < M, N \le 500$ ),另外是待过滤的灰度值区间端点 $A$ 和
$B$ ( $0 \le A < B \le 255$ )、以及指定的替换灰度值。随后 $M$ 行,每行给出 $N$
个像素点的灰度值,其间以空格分隔。所有灰度值都在 [0, 255] 区间内。
### 输出格式:
输出按要求过滤后的图像。即输出 $M$ 行,每行 $N$ 个像素灰度值,每个灰度值占 3 位(例如黑色要显示为
`000`),其间以一个空格分隔。行首尾不得有多余空格。
### 输入样例:
3 5 100 150 0
3 189 254 101 119
150 233 151 99 100
88 123 149 0 255
### 输出样例:
003 189 254 000 000
000 233 151 099 000
088 000 000 000 255
## 思路
+57 -33
View File
@@ -9,39 +9,63 @@ permalink: Basic/1067.html
## 题目
{% raw %}<div class="ques-view"><p>当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死。本题就请你实现这个小功能。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出一个密码(长度不超过 20 的、不包含空格、Tab、回车的非空字符串)和一个正整数 N(<span>$\le$</span> 10),分别是正确的密码和系统允许尝试的次数。随后每行给出一个以回车结束的非空字符串,是用户尝试输入的密码。输入保证至少有一次尝试。当读到一行只有单个 # 字符时,输入结束,并且这一行不是用户的输入。</p>
<h3 id="-">输出格式:</h3>
<p>对用户的每个输入,如果是正确的密码且尝试次数不超过 N,则在一行中输出 <code>Welcome in</code>,并结束程序;如果是错误的,则在一行中按格式输出 <code>Wrong password: 用户输入的错误密码</code>;当错误尝试达到 N 次时,再输出一行 <code>Account locked</code>,并结束程序。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">Correct%pw 3
correct%pw
Correct@PW
whatisthepassword!
Correct%pw
#
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">Wrong password: correct%pw
Wrong password: Correct@PW
Wrong password: whatisthepassword!
Account locked
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">cool@gplt 3
coolman@gplt
coollady@gplt
cool@gplt
try again
#
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">Wrong password: coolman@gplt
Wrong password: coollady@gplt
Welcome in
</code></pre>
</div>{% endraw %}
当你试图登录某个系统却忘了密码时,系统一般只会允许你尝试有限多次,当超出允许次数时,账号就会被锁死。本题就请你实现这个小功能。
### 输入格式:
输入在第一行给出一个密码(长度不超过 20 的、不包含空格、Tab、回车的非空字符串)和一个正整数 N( $\le$
10),分别是正确的密码和系统允许尝试的次数。随后每行给出一个以回车结束的非空字符串,是用户尝试输入的密码。输入保证至少有一次尝试。当读到一行只有单个 #
字符时,输入结束,并且这一行不是用户的输入。
### 输出格式:
对用户的每个输入,如果是正确的密码且尝试次数不超过 N,则在一行中输出 `Welcome in`,并结束程序;如果是错误的,则在一行中按格式输出
`Wrong password: 用户输入的错误密码`;当错误尝试达到 N 次时,再输出一行 `Account locked`,并结束程序。
### 输入样例 1:
Correct%pw 3
correct%pw
Correct@PW
whatisthepassword!
Correct%pw
#
### 输出样例 1:
Wrong password: correct%pw
Wrong password: Correct@PW
Wrong password: whatisthepassword!
Account locked
### 输入样例 2:
cool@gplt 3
coolman@gplt
coollady@gplt
cool@gplt
try again
#
### 输出样例 2:
Wrong password: coolman@gplt
Wrong password: coollady@gplt
Welcome in
## 思路
+70 -38
View File
@@ -9,44 +9,76 @@ permalink: Basic/1068.html
## 题目
{% raw %}<div class="ques-view"><p>对于计算机而言,颜色不过是像素点对应的一个 24 位的数值。现给定一幅分辨率为 <span>$M\times N$</span> 的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围 8 个相邻像素的颜色差充分大。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出三个正整数,分别是 <span>$M$</span> 和 <span>$N$</span>(<span>$\le$</span> 1000),即图像的分辨率;以及 TOL,是所求像素点与相邻点的颜色差阈值,色差超过 TOL 的点才被考虑。随后 <span>$N$</span> 行,每行给出 <span>$M$</span> 个像素的颜色值,范围在 <span>$[0, 2^{24})$</span> 内。所有同行数字间用空格或 TAB 分开。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中按照 <code>(x, y): color</code> 的格式输出所求像素点的位置以及颜色值,其中位置 <code>x</code> 和 <code>y</code> 分别是该像素在图像矩阵中的列、行编号(从 1 开始编号)。如果这样的点不唯一,则输出 <code>Not Unique</code>;如果这样的点不存在,则输出 <code>Not Exist</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">8 6 200
0 0 0 0 0 0 0 0
65280 65280 65280 16711479 65280 65280 65280 65280
16711479 65280 65280 65280 16711680 65280 65280 65280
65280 65280 65280 65280 65280 65280 165280 165280
65280 65280 16777015 65280 65280 165280 65480 165280
16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">(5, 3): 16711680
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">4 5 2
0 0 0 0
0 0 3 0
0 0 0 0
0 5 0 0
0 0 0 0
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">Not Unique
</code></pre>
<h3 id="-3-">输入样例 3:</h3>
<pre><code class="lang-in">3 3 5
1 2 3
3 4 5
5 6 7
</code></pre>
<h3 id="-3-">输出样例 3:</h3>
<pre><code class="lang-out">Not Exist
</code></pre>
</div>{% endraw %}
对于计算机而言,颜色不过是像素点对应的一个 24 位的数值。现给定一幅分辨率为 $M\times N$
的画,要求你找出万绿丛中的一点红,即有独一无二颜色的那个像素点,并且该点的颜色与其周围 8 个相邻像素的颜色差充分大。
### 输入格式:
输入第一行给出三个正整数,分别是 $M$ 和 $N$ ( $\le$ 1000),即图像的分辨率;以及 TOL,是所求像素点与相邻点的颜色差阈值,色差超过
TOL 的点才被考虑。随后 $N$ 行,每行给出 $M$ 个像素的颜色值,范围在 $[0, 2^{24})$ 内。所有同行数字间用空格或 TAB 分开。
### 输出格式:
在一行中按照 `(x, y): color` 的格式输出所求像素点的位置以及颜色值,其中位置 `x` 和 `y` 分别是该像素在图像矩阵中的列、行编号(从
1 开始编号)。如果这样的点不唯一,则输出 `Not Unique`;如果这样的点不存在,则输出 `Not Exist`。
### 输入样例 1:
8 6 200
0 0 0 0 0 0 0 0
65280 65280 65280 16711479 65280 65280 65280 65280
16711479 65280 65280 65280 16711680 65280 65280 65280
65280 65280 65280 65280 65280 65280 165280 165280
65280 65280 16777015 65280 65280 165280 65480 165280
16777215 16777215 16777215 16777215 16777215 16777215 16777215 16777215
### 输出样例 1:
(5, 3): 16711680
### 输入样例 2:
4 5 2
0 0 0 0
0 0 3 0
0 0 0 0
0 5 0 0
0 0 0 0
### 输出样例 2:
Not Unique
### 输入样例 3:
3 3 5
1 2 3
3 4 5
5 6 7
### 输出样例 3:
Not Exist
## 思路
+55 -32
View File
@@ -9,38 +9,61 @@ permalink: Basic/1069.html
## 题目
{% raw %}<div class="ques-view"><p>小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包。请你编写程序帮助他确定中奖名单。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出三个正整数 M(<span>$\le$</span> 1000)、N 和 S,分别是转发的总量、小明决定的中奖间隔、以及第一位中奖者的序号(编号从 1 开始)。随后 M 行,顺序给出转发微博的网友的昵称(不超过 20 个字符、不包含空格回车的非空字符串)。</p>
<p>注意:可能有人转发多次,但不能中奖多次。所以如果处于当前中奖位置的网友已经中过奖,则跳过他顺次取下一位。</p>
<h3 id="-">输出格式:</h3>
<p>按照输入的顺序输出中奖名单,每个昵称占一行。如果没有人中奖,则输出 <code>Keep going...</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">9 3 2
Imgonnawin!
PickMe
PickMeMeMeee
LookHere
Imgonnawin!
TryAgainAgain
TryAgainAgain
Imgonnawin!
TryAgainAgain
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">PickMe
Imgonnawin!
TryAgainAgain
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">2 3 5
Imgonnawin!
PickMe
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">Keep going...
</code></pre>
</div>{% endraw %}
小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包。请你编写程序帮助他确定中奖名单。
### 输入格式:
输入第一行给出三个正整数 M( $\le$ 1000)、N 和 S,分别是转发的总量、小明决定的中奖间隔、以及第一位中奖者的序号(编号从 1 开始)。随后
M 行,顺序给出转发微博的网友的昵称(不超过 20 个字符、不包含空格回车的非空字符串)。
注意:可能有人转发多次,但不能中奖多次。所以如果处于当前中奖位置的网友已经中过奖,则跳过他顺次取下一位。
### 输出格式:
按照输入的顺序输出中奖名单,每个昵称占一行。如果没有人中奖,则输出 `Keep going...`。
### 输入样例 1:
9 3 2
Imgonnawin!
PickMe
PickMeMeMeee
LookHere
Imgonnawin!
TryAgainAgain
TryAgainAgain
Imgonnawin!
TryAgainAgain
### 输出样例 1:
PickMe
Imgonnawin!
TryAgainAgain
### 输入样例 2:
2 3 5
Imgonnawin!
PickMe
### 输出样例 2:
Keep going...
## 思路
+31 -15
View File
@@ -9,21 +9,37 @@ permalink: Basic/1070.html
## 题目
{% raw %}<div class="ques-view"><p>给定一段一段的绳子,你需要把它们串成一条绳。每次串连的时候,是把两段绳子对折,再如下图所示套接在一起。这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连。每次串连后,原来两段绳子的长度就会减半。</p>
<p><img alt="rope.jpg" src="https://images.ptausercontent.com/46293e57-aa0e-414b-b5c3-7c4b2d5201e2.jpg"/></p>
<p>给定 <span>$N$</span> 段绳子的长度,你需要找出它们能串成的绳子的最大长度。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含 1 个测试用例。每个测试用例第 1 行给出正整数 <span>$N$</span> (<span>$2 \le N \le 10^4$</span>);第 2 行给出 <span>$N$</span> 个正整数,即原始绳段的长度,数字间以空格分隔。所有整数都不超过<span>$10^4$</span>。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出能够串成的绳子的最大长度。结果向下取整,即取为不超过最大长度的最近整数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">8
10 15 12 3 4 13 1 15
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">14
</code></pre>
</div>{% endraw %}
给定一段一段的绳子,你需要把它们串成一条绳。每次串连的时候,是把两段绳子对折,再如下图所示套接在一起。这样得到的绳子又被当成是另一段绳子,可以再次对折去跟另一段绳子串连。每次串连后,原来两段绳子的长度就会减半。
![rope.jpg](https://images.ptausercontent.com/46293e57-aa0e-414b-b5c3-7c4b2d5201e2.jpg)
给定 $N$ 段绳子的长度,你需要找出它们能串成的绳子的最大长度。
### 输入格式:
每个输入包含 1 个测试用例。每个测试用例第 1 行给出正整数 $N$ ( $2 \le N \le 10^4$ );第 2 行给出 $N$
个正整数,即原始绳段的长度,数字间以空格分隔。所有整数都不超过 $10^4$ 。
### 输出格式:
在一行中输出能够串成的绳子的最大长度。结果向下取整,即取为不超过最大长度的最近整数。
### 输入样例:
8
10 15 12 3 4 13 1 15
### 输出样例:
14
## 思路
+69 -40
View File
@@ -9,46 +9,75 @@ permalink: Basic/1071.html
## 题目
{% raw %}<div class="ques-view"><p>常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注 t 个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家 t 个筹码;否则扣除玩家 t 个筹码。</p>
<p>注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数。当玩家输光了全部筹码后,游戏就结束。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出 2 个正整数 T 和 K(<span>$\le$</span> 100),分别是系统在初始状态下赠送给玩家的筹码数、以及需要处理的游戏次数。随后 K 行,每行对应一次游戏,顺序给出 4 个数字:</p>
<pre><code>n1 b t n2
</code></pre><p>其中 <code>n1</code> 和 <code>n2</code> 是计算机先后给出的两个[0, 9]内的整数,保证两个数字不相等。<code>b</code> 为 0 表示玩家赌<code>小</code>,为 1 表示玩家赌<code>大</code>。<code>t</code> 表示玩家下注的筹码数,保证在整型范围内。</p>
<h3 id="-">输出格式:</h3>
<p>对每一次游戏,根据下列情况对应输出(其中 <code>t</code> 是玩家下注量,<code>x</code> 是玩家当前持有的筹码量):</p>
<ul>
<li>玩家赢,输出 <code>Win t! Total = x.</code>;</li>
<li>玩家输,输出 <code>Lose t. Total = x.</code>;</li>
<li>玩家下注超过持有的筹码量,输出 <code>Not enough tokens. Total = x.</code>;</li>
<li>玩家输光后,输出 <code>Game Over.</code> 并结束程序。</li>
</ul>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">100 4
8 0 100 2
3 1 50 1
5 1 200 6
7 0 200 8
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">Win 100! Total = 200.
Lose 50. Total = 150.
Not enough tokens. Total = 150.
Not enough tokens. Total = 150.
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">100 4
8 0 100 2
3 1 200 1
5 1 200 6
7 0 200 8
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">Win 100! Total = 200.
Lose 200. Total = 0.
Game Over.
</code></pre>
</div>{% endraw %}
常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注 t
个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家 t 个筹码;否则扣除玩家 t 个筹码。
注意:玩家下注的筹码数不能超过自己帐户上拥有的筹码数。当玩家输光了全部筹码后,游戏就结束。
### 输入格式:
输入在第一行给出 2 个正整数 T 和 K( $\le$ 100),分别是系统在初始状态下赠送给玩家的筹码数、以及需要处理的游戏次数。随后 K
行,每行对应一次游戏,顺序给出 4 个数字:
n1 b t n2
其中 `n1` 和 `n2` 是计算机先后给出的两个[0, 9]内的整数,保证两个数字不相等。`b` 为 0 表示玩家赌`小`,为 1
表示玩家赌`大`。`t` 表示玩家下注的筹码数,保证在整型范围内。
### 输出格式:
对每一次游戏,根据下列情况对应输出(其中 `t` 是玩家下注量,`x` 是玩家当前持有的筹码量):
* 玩家赢,输出 `Win t! Total = x.`;
* 玩家输,输出 `Lose t. Total = x.`;
* 玩家下注超过持有的筹码量,输出 `Not enough tokens. Total = x.`;
* 玩家输光后,输出 `Game Over.` 并结束程序。
### 输入样例 1:
100 4
8 0 100 2
3 1 50 1
5 1 200 6
7 0 200 8
### 输出样例 1:
Win 100! Total = 200.
Lose 50. Total = 150.
Not enough tokens. Total = 150.
Not enough tokens. Total = 150.
### 输入样例 2:
100 4
8 0 100 2
3 1 200 1
5 1 200 6
7 0 200 8
### 输出样例 2:
Win 100! Total = 200.
Lose 200. Total = 0.
Game Over.
## 思路
+47 -24
View File
@@ -9,30 +9,53 @@ permalink: Basic/1072.html
## 题目
{% raw %}<div class="ques-view"><p>下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其 wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也!</p>
<p><img alt="jiyu.JPG" src="https://images.ptausercontent.com/3b1d9f4a-778b-4942-a9e2-836262f363aa.JPG"/></p>
<p>本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出两个正整数 N(<span>$\le$</span> 1000)和 M(<span>$\le$</span> 6),分别是学生人数和需要被查缴的物品种类数。第二行给出 M 个需要被查缴的物品编号,其中编号为 4 位数字。随后 N 行,每行给出一位学生的姓名缩写(由 1-4 个大写英文字母组成)、个人物品数量 K(0 <span>$\le$</span> K <span>$\le$</span> 10)、以及 K 个物品的编号。</p>
<h3 id="-">输出格式:</h3>
<p>顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息和其需要被查缴的物品的信息(注意行末不得有多余空格):</p>
<pre><code>姓名缩写: 物品编号1 物品编号2 ……
</code></pre><p>最后一行输出存在问题的学生的总人数和被查缴物品的总数。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">4 2
2333 6666
CYLL 3 1234 2345 3456
U 4 9966 6666 8888 6666
GG 2 2333 7777
JJ 3 0012 6666 2333
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">U: 6666 6666
GG: 2333
JJ: 6666 2333
3 5
</code></pre>
</div>{% endraw %}
下图是上海某校的新学期开学寄语:天将降大任于斯人也,必先删其微博,卸其 QQ,封其电脑,夺其手机,收其 ipad,断其
wifi,使其百无聊赖,然后,净面、理发、整衣,然后思过、读书、锻炼、明智、开悟、精进。而后必成大器也!
![jiyu.JPG](https://images.ptausercontent.com/3b1d9f4a-778b-4942-a9e2-836262f363aa.JPG)
本题要求你写个程序帮助这所学校的老师检查所有学生的物品,以助其成大器。
### 输入格式:
输入第一行给出两个正整数 N( $\le$ 1000)和 M( $\le$ 6),分别是学生人数和需要被查缴的物品种类数。第二行给出 M
个需要被查缴的物品编号,其中编号为 4 位数字。随后 N 行,每行给出一位学生的姓名缩写(由 1-4 个大写英文字母组成)、个人物品数量 K(0 $\le$
K $\le$ 10)、以及 K 个物品的编号。
### 输出格式:
顺次检查每个学生携带的物品,如果有需要被查缴的物品存在,则按以下格式输出该生的信息和其需要被查缴的物品的信息(注意行末不得有多余空格):
姓名缩写: 物品编号1 物品编号2 ……
最后一行输出存在问题的学生的总人数和被查缴物品的总数。
### 输入样例:
4 2
2333 6666
CYLL 3 1234 2345 3456
U 4 9966 6666 8888 6666
GG 2 2333 7777
JJ 3 0012 6666 2333
### 输出样例:
U: 6666 6666
GG: 2333
JJ: 6666 2333
3 5
## 思路
+64 -36
View File
@@ -9,42 +9,70 @@ permalink: Basic/1073.html
## 题目
{% raw %}<div class="ques-view"><p>批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50% 分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出两个正整数 N(<span>$\le$</span>1000)和 M(<span>$\le$</span>100),分别是学生人数和多选题的个数。随后 M 行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5 的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N 行,每行给出一个学生的答题情况,其每题答案格式为 <code>(选中的选项个数 选项1 ……)</code>,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。</p>
<h3 id="-">输出格式:</h3>
<p>按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后 1 位。最后输出错得最多的题目选项的信息,格式为:<code>错误次数 题目编号(题目按照输入的顺序从1开始编号)-选项号</code>。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出 <code>Too simple</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">3.5
6.0
2.5
2 2-e
2 3-a
2 3-b
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">2 2
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">5.0
5.0
Too simple
</code></pre>
</div>{% endraw %}
批改多选题是比较麻烦的事情,有很多不同的计分方法。有一种最常见的计分方法是:如果考生选择了部分正确选项,并且没有选择任何错误选项,则得到 50%
分数;如果考生选择了任何一个错误的选项,则不能得分。本题就请你写个程序帮助老师批改多选题,并且指出哪道题的哪个选项错的人最多。
### 输入格式:
输入在第一行给出两个正整数 N( $\le$ 1000)和 M( $\le$ 100),分别是学生人数和多选题的个数。随后 M
行,每行顺次给出一道题的满分值(不超过 5 的正整数)、选项个数(不少于 2 且不超过 5
的正整数)、正确选项个数(不超过选项个数的正整数)、所有正确选项。注意每题的选项从小写英文字母 a 开始顺次排列。各项间以 1 个空格分隔。最后 N
行,每行给出一个学生的答题情况,其每题答案格式为 `(选中的选项个数 选项1
……)`,按题目顺序给出。注意:题目保证学生的答题情况是合法的,即不存在选中的选项数超过实际选项数的情况。
### 输出格式:
按照输入的顺序给出每个学生的得分,每个分数占一行,输出小数点后 1 位。最后输出错得最多的题目选项的信息,格式为:`错误次数
题目编号(题目按照输入的顺序从1开始编号)-选项号`。如果有并列,则每行一个选项,按题目编号递增顺序输出;再并列则按选项号递增顺序输出。行首尾不得有多余空格。如果所有题目都没有人错,则在最后一行输出
`Too simple`。
### 输入样例 1:
3 4
3 4 2 a c
2 5 1 b
5 3 2 b c
1 5 4 a b d e
(2 a c) (3 b d e) (2 a c) (3 a b e)
(2 a c) (1 b) (2 a b) (4 a b d e)
(2 b d) (1 e) (1 c) (4 a b c d)
### 输出样例 1:
3.5
6.0
2.5
2 2-e
2 3-a
2 3-b
### 输入样例 2:
2 2
3 4 2 a c
2 5 1 b
(2 a c) (1 b)
(2 a c) (1 b)
### 输出样例 2:
5.0
5.0
Too simple
## 思路
+36 -15
View File
@@ -9,21 +9,42 @@ permalink: Basic/1074.html
## 题目
{% raw %}<div class="ques-view"><p>地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT 星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10 进制数,等等。每一位的进制 d 或者是 0(表示十进制)、或者是 [2,9] 区间内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT 星人通常只需要记住前 20 位就够用了,以后各位默认为 10 进制。</p>
<p>在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何计算“6203 + 415”呢?我们得首先计算最低位:3 + 5 = 8;因为最低位是 7 进制的,所以我们得到 1 和 1 个进位。第 2 位是:0 + 1 + 1(进位)= 2;因为此位是 2 进制的,所以我们得到 0 和 1 个进位。第 3 位是:2 + 4 + 1(进位)= 7;因为此位是 5 进制的,所以我们得到 2 和 1 个进位。第 4 位是:6 + 1(进位)= 7;因为此位是 10 进制的,所以我们就得到 7。最后我们得到:6203 + 415 = 7201。</p>
<h3 id="-">输入格式:</h3>
<p>输入首先在第一行给出一个 N 位的进制表(0 <span>$&lt;$</span> N <span>$\le$</span> 20),以回车结束。 随后两行,每行给出一个不超过 N 位的非负的 PAT 数。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出两个 PAT 数之和。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">30527
06203
415
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">7201
</code></pre>
</div>{% endraw %}
地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT
星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT
星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10
进制数,等等。每一位的进制 d 或者是 0(表示十进制)、或者是 [2,9] 区间内的整数。理论上这个进制表应该包含无穷多位数字,但从实际应用出发,PAT
星人通常只需要记住前 20 位就够用了,以后各位默认为 10 进制。
在这样的数字系统中,即使是简单的加法运算也变得不简单。例如对应进制表“0527”,该如何计算“6203 + 415”呢?我们得首先计算最低位:3 + 5 =
8;因为最低位是 7 进制的,所以我们得到 1 和 1 个进位。第 2 位是:0 + 1 + 1(进位)= 2;因为此位是 2 进制的,所以我们得到 0 和
1 个进位。第 3 位是:2 + 4 + 1(进位)= 7;因为此位是 5 进制的,所以我们得到 2 和 1 个进位。第 4 位是:6 + 1(进位)=
7;因为此位是 10 进制的,所以我们就得到 7。最后我们得到:6203 + 415 = 7201。
### 输入格式:
输入首先在第一行给出一个 N 位的进制表(0 $<$ N $\le$ 20),以回车结束。 随后两行,每行给出一个不超过 N 位的非负的 PAT 数。
### 输出格式:
在一行中输出两个 PAT 数之和。
### 输入样例:
30527
06203
415
### 输出样例:
7201
## 思路
+55 -32
View File
@@ -9,38 +9,61 @@ permalink: Basic/1075.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而 [0, K] 区间内的元素都排在大于 K 的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K 为 10,则输出应该为 -4→-6→-2→7→0→5→10→18→11。</p>
<h3 id="-">输入格式:</h3>
<p>每个输入包含一个测试用例。每个测试用例第 1 行给出:第 1 个结点的地址;结点总个数,即正整数N (<span>$\le 10^5$</span>);以及正整数K (<span>$\le 10^3$</span>)。结点的地址是 5 位非负整数,NULL 地址用 <span>$-1$</span> 表示。</p>
<p>接下来有 N 行,每行格式为:</p>
<pre><code>Address Data Next
</code></pre><p>其中 <code>Address</code> 是结点地址;<code>Data</code> 是该结点保存的数据,为 <span>$[-10^5, 10^5]$</span> 区间内的整数;<code>Next</code> 是下一结点的地址。题目保证给出的链表不为空。</p>
<h3 id="-">输出格式:</h3>
<p>对每个测试用例,按链表从头到尾的顺序输出重排后的结果链表,其上每个结点占一行,格式与输入相同。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">00100 9 10
23333 10 27777
00000 0 99999
00100 18 12309
68237 -6 23333
33218 -4 00000
48652 -2 -1
99999 5 68237
27777 11 48652
12309 7 33218
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">33218 -4 68237
68237 -6 48652
48652 -2 12309
12309 7 00000
00000 0 99999
99999 5 23333
23333 10 00100
00100 18 27777
27777 11 -1
</code></pre>
</div>{% endraw %}
给定一个单链表,请编写程序将链表元素进行分类排列,使得所有负值元素都排在非负值元素的前面,而 [0, K] 区间内的元素都排在大于 K
的元素前面。但每一类内部元素的顺序是不能改变的。例如:给定链表为 18→7→-4→0→5→-6→10→11→-2,K 为 10,则输出应该为
-4→-6→-2→7→0→5→10→18→11。
### 输入格式:
每个输入包含一个测试用例。每个测试用例第 1 行给出:第 1 个结点的地址;结点总个数,即正整数N ( $\le 10^5$ );以及正整数K ( $\le
10^3$ )。结点的地址是 5 位非负整数,NULL 地址用 $-1$ 表示。
接下来有 N 行,每行格式为:
Address Data Next
其中 `Address` 是结点地址;`Data` 是该结点保存的数据,为 $[-10^5, 10^5]$ 区间内的整数;`Next`
是下一结点的地址。题目保证给出的链表不为空。
### 输出格式:
对每个测试用例,按链表从头到尾的顺序输出重排后的结果链表,其上每个结点占一行,格式与输入相同。
### 输入样例:
00100 9 10
23333 10 27777
00000 0 99999
00100 18 12309
68237 -6 23333
33218 -4 00000
48652 -2 -1
99999 5 68237
27777 11 48652
12309 7 33218
### 输出样例:
33218 -4 68237
68237 -6 48652
48652 -2 12309
12309 7 00000
00000 0 99999
99999 5 23333
23333 10 00100
00100 18 27777
27777 11 -1
## 思路
+38 -21
View File
@@ -9,27 +9,44 @@ permalink: Basic/1076.html
## 题目
{% raw %}<div class="ques-view"><p>下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用 wifi,又怕耽误亲们的学习,现将 wifi 密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日一换。谢谢合作!!~”—— 老师们为了促进学生学习也是拼了…… 本题就要求你写程序把一系列题目的答案按照卷子上给出的对应关系翻译成 wifi 的密码。这里简单假设每道选择题都有 4 个选项,有且只有 1 个正确答案。</p>
<p><img alt="wifi.jpg" src="https://images.ptausercontent.com/7e56be3f-caba-45f1-b9cb-38a96d44de76.jpg"/></p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 N(<span>$\le$</span> 100),随后 N 行,每行按照 <code>编号-答案</code> 的格式给出一道题的 4 个选项,<code>T</code> 表示正确选项,<code>F</code> 表示错误选项。选项间用空格分隔。</p>
<h3 id="-">输出格式:</h3>
<p>在一行中输出 wifi 密码。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">8
A-T B-F C-F D-F
C-T B-F A-F D-F
A-F D-F C-F B-T
B-T A-F C-F D-F
B-F D-T A-F C-F
A-T C-F B-F D-F
D-T B-F C-F A-F
C-T A-F B-F D-F
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">13224143
</code></pre>
</div>{% endraw %}
下面是微博上流传的一张照片:“各位亲爱的同学们,鉴于大家有时需要使用 wifi,又怕耽误亲们的学习,现将 wifi
密码设置为下列数学题答案:A-1;B-2;C-3;D-4;请同学们自己作答,每两日一换。谢谢合作!!~”—— 老师们为了促进学生学习也是拼了……
本题就要求你写程序把一系列题目的答案按照卷子上给出的对应关系翻译成 wifi 的密码。这里简单假设每道选择题都有 4 个选项,有且只有 1 个正确答案。
![wifi.jpg](https://images.ptausercontent.com/7e56be3f-caba-45f1-b9cb-38a96d44de76.jpg)
### 输入格式:
输入第一行给出一个正整数 N( $\le$ 100),随后 N 行,每行按照 `编号-答案` 的格式给出一道题的 4 个选项,`T` 表示正确选项,`F`
表示错误选项。选项间用空格分隔。
### 输出格式:
在一行中输出 wifi 密码。
### 输入样例:
8
A-T B-F C-F D-F
C-T B-F A-F D-F
A-F D-F C-F B-T
B-T A-F C-F D-F
B-F D-T A-F C-F
A-T C-F B-F D-F
D-T B-F C-F A-F
C-T A-F B-F D-F
### 输出样例:
13224143
## 思路
+40 -23
View File
@@ -9,29 +9,46 @@ permalink: Basic/1077.html
## 题目
{% raw %}<div class="ques-view"><p>在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为 <span>$G_1$</span>;老师给这个组的评分记为 <span>$G_2$</span>。该组得分为 <span>$(G_1+G_2)/2$</span>,最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出两个正整数 <span>$N$</span>(<span>$&gt;$</span> 3)和 <span>$M$</span>,分别是分组数和满分,均不超过 100。随后 <span>$N$</span> 行,每行给出该组得到的 <span>$N$</span> 个分数(均保证为整型范围内的整数),其中第 1 个是老师给出的评分,后面 <span>$N-1$</span> 个是其他组给的评分。合法的输入应该是 <span>$[0, M]$</span> 区间内的整数,若不在合法区间内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有 3 个来自同学的合法评分。</p>
<h3 id="-">输出格式:</h3>
<p>为每个组输出其最终得分。每个得分占一行。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">42
33
41
31
37
39
</code></pre>
</div>{% endraw %}
在浙大的计算机专业课中,经常有互评分组报告这个环节。一个组上台介绍自己的工作,其他组在台下为其表现评分。最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一个最高分和一个最低分,剩下的分数取平均分记为
$G_1$ ;老师给这个组的评分记为 $G_2$ 。该组得分为 $(G_1+G_2)/2$
,最后结果四舍五入后保留整数分。本题就要求你写个程序帮助老师计算每个组的互评成绩。
### 输入格式:
输入第一行给出两个正整数 $N$ ( $>$ 3)和 $M$ ,分别是分组数和满分,均不超过 100。随后 $N$ 行,每行给出该组得到的 $N$
个分数(均保证为整型范围内的整数),其中第 1 个是老师给出的评分,后面 $N-1$ 个是其他组给的评分。合法的输入应该是 $[0, M]$
区间内的整数,若不在合法区间内,则该分数须被忽略。题目保证老师的评分都是合法的,并且每个组至少会有 3 个来自同学的合法评分。
### 输出格式:
为每个组输出其最终得分。每个得分占一行。
### 输入样例:
6 50
42 49 49 35 38 41
36 51 50 28 -1 30
40 36 41 33 47 49
30 250 -25 27 45 31
48 0 0 50 50 1234
43 41 36 29 42 29
### 输出样例:
42
33
41
31
37
39
## 思路
+47 -22
View File
@@ -9,28 +9,53 @@ permalink: Basic/1078.html
## 题目
{% raw %}<div class="ques-view"><p>文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 <code>ccccc</code> 就用 <code>5c</code> 来表示。如果字符没有重复,就原样输出。例如 <code>aba</code> 压缩后仍然是 <code>aba</code>。</p>
<p>解压方法就是反过来,把形如 <code>5c</code> 这样的表示恢复为 <code>ccccc</code>。</p>
<p>本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母和空格组成的非空字符串。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个字符,如果是 <code>C</code> 就表示下面的字符串需要被压缩;如果是 <code>D</code> 就表示下面的字符串需要被解压。第二行给出需要被压缩或解压的不超过 1000 个字符的字符串,以回车结尾。题目保证字符重复个数在整型范围内,且输出文件不超过 1MB。</p>
<h3 id="-">输出格式:</h3>
<p>根据要求压缩或解压字符串,并在一行中输出结果。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">C
TTTTThhiiiis isssss a tesssst CAaaa as
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">5T2h4is i5s a3 te4st CA3a as
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">D
5T2h4is i5s a3 te4st CA3a as10Z
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">TTTTThhiiiis isssss a tesssst CAaaa asZZZZZZZZZZ
</code></pre>
</div>{% endraw %}
文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 `ccccc` 就用
`5c` 来表示。如果字符没有重复,就原样输出。例如 `aba` 压缩后仍然是 `aba`。
解压方法就是反过来,把形如 `5c` 这样的表示恢复为 `ccccc`。
本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母和空格组成的非空字符串。
### 输入格式:
输入第一行给出一个字符,如果是 `C` 就表示下面的字符串需要被压缩;如果是 `D` 就表示下面的字符串需要被解压。第二行给出需要被压缩或解压的不超过
1000 个字符的字符串,以回车结尾。题目保证字符重复个数在整型范围内,且输出文件不超过 1MB。
### 输出格式:
根据要求压缩或解压字符串,并在一行中输出结果。
### 输入样例 1:
C
TTTTThhiiiis isssss a tesssst CAaaa as
### 输出样例 1:
5T2h4is i5s a3 te4st CA3a as
### 输入样例 2:
D
5T2h4is i5s a3 te4st CA3a as10Z
### 输出样例 2:
TTTTThhiiiis isssss a tesssst CAaaa asZZZZZZZZZZ
## 思路
+66 -34
View File
@@ -9,40 +9,72 @@ permalink: Basic/1079.html
## 题目
{% raw %}<div class="ques-view"><p>给定一个 <span>$k+1$</span> 位的正整数 <span>$N$</span>,写成 <span>$a_k \cdots a_1 a_0$</span> 的形式,其中对所有 <span>$i$</span> 有 <span>$0 \le a_i &lt; 10$</span> 且 <span>$a_k &gt; 0$</span>。<span>$N$</span> 被称为一个<strong>回文数</strong>,当且仅当对所有 <span>$i$</span> 有 <span>$a_i = a_{k-i}$</span>。零也被定义为一个回文数。</p>
<p>非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非回文数可以变出回文数,就称这个数为<strong>延迟的回文数</strong>。(定义翻译自 <a href="https://en.wikipedia.org/wiki/Palindromic_number">https://en.wikipedia.org/wiki/Palindromic_number</a> )</p>
<p>给定任意一个正整数,本题要求你找到其变出的那个回文数。</p>
<h3 id="-">输入格式:</h3>
<p>输入在一行中给出一个不超过1000位的正整数。</p>
<h3 id="-">输出格式:</h3>
<p>对给定的整数,一行一行输出其变出回文数的过程。每行格式如下</p>
<pre><code>A + B = C
</code></pre><p>其中 <code>A</code> 是原始的数字,<code>B</code> 是 <code>A</code> 的逆转数,<code>C</code> 是它们的和。<code>A</code> 从输入的整数开始。重复操作直到 <code>C</code> 在 10 步以内变成回文数,这时在一行中输出 <code>C is a palindromic number.</code>;或者如果 10 步都没能得到回文数,最后就在一行中输出 <code>Not found in 10 iterations.</code>。</p>
<h3 id="-1-">输入样例 1:</h3>
<pre><code class="lang-in">97152
</code></pre>
<h3 id="-1-">输出样例 1:</h3>
<pre><code class="lang-out">97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.
</code></pre>
<h3 id="-2-">输入样例 2:</h3>
<pre><code class="lang-in">196
</code></pre>
<h3 id="-2-">输出样例 2:</h3>
<pre><code class="lang-out">196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171
Not found in 10 iterations.
</code></pre>
</div>{% endraw %}
给定一个 $k+1$ 位的正整数 $N$ ,写成 $a_k \cdots a_1 a_0$ 的形式,其中对所有 $i$ 有 $0 \le a_i < 10$
且 $a_k > 0$ 。 $N$ 被称为一个 **回文数** ,当且仅当对所有 $i$ 有 $a_i = a_{k-i}$ 。零也被定义为一个回文数。
非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回文数出现。如果一个非回文数可以变出回文数,就称这个数为
**延迟的回文数** 。(定义翻译自 <https://en.wikipedia.org/wiki/Palindromic_number> )
给定任意一个正整数,本题要求你找到其变出的那个回文数。
### 输入格式:
输入在一行中给出一个不超过1000位的正整数。
### 输出格式:
对给定的整数,一行一行输出其变出回文数的过程。每行格式如下
A + B = C
其中 `A` 是原始的数字,`B` 是 `A` 的逆转数,`C` 是它们的和。`A` 从输入的整数开始。重复操作直到 `C` 在 10
步以内变成回文数,这时在一行中输出 `C is a palindromic number.`;或者如果 10 步都没能得到回文数,最后就在一行中输出
`Not found in 10 iterations.`。
### 输入样例 1:
97152
### 输出样例 1:
97152 + 25179 = 122331
122331 + 133221 = 255552
255552 is a palindromic number.
### 输入样例 2:
196
### 输出样例 2:
196 + 691 = 887
887 + 788 = 1675
1675 + 5761 = 7436
7436 + 6347 = 13783
13783 + 38731 = 52514
52514 + 41525 = 94039
94039 + 93049 = 187088
187088 + 880781 = 1067869
1067869 + 9687601 = 10755470
10755470 + 07455701 = 18211171
Not found in 10 iterations.
## 思路
+62 -38
View File
@@ -9,44 +9,68 @@ permalink: Basic/1080.html
## 题目
{% raw %}<div class="ques-view"><p>对于在中国大学MOOC(<a href="http://www.icourse163.org/">http://www.icourse163.org/</a> )学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为 <span>$G = (G_{mid-term}\times 40\% + G_{final}\times 60\%)$</span>,如果 <span>$G_{mid-term} &gt; G_{final}$</span>;否则总评 <span>$G$</span> 就是 <span>$G_{final}$</span>。这里 <span>$G_{mid-term}$</span> 和 <span>$G_{final}$</span> 分别为学生的期中和期末成绩。</p>
<p>现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合为一张。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。</p>
<p>接下来有三块输入。第一块包含 P 个在线编程成绩 <span>$G_p$</span>;第二块包含 M 个期中考试成绩 <span>$G_{mid-term}$</span>;第三块包含 N 个期末考试成绩 <span>$G_{final}$</span>。每个成绩占一行,格式为:<code>学生学号 分数</code>。其中<code>学生学号</code>为不超过20个字符的英文字母和数字;<code>分数</code>是非负整数(编程总分最高为900分,期中和期末的最高分为100分)。</p>
<h3 id="-">输出格式:</h3>
<p>打印出获得合格证书的学生名单。每个学生占一行,格式为:</p>
<p><code>学生学号</code> <span>$G_p$</span> <span>$G_{mid-term}$</span> <span>$G_{final}$</span> <span>$G$</span></p>
<p>如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“<span>$-1$</span>”。输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,且至少存在1个合格的学生。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
</code></pre>
</div>{% endraw %}
对于在中国大学MOOC(<http://www.icourse163.org/>
)学习“数据结构”课程的学生,想要获得一张合格证书,必须首先获得不少于200分的在线编程作业分,然后总评获得不少于60分(满分100)。总评成绩的计算公式为
$G = (G_{mid-term}\times 40\% + G_{final}\times 60\%)$ ,如果 $G_{mid-term} >
G_{final}$ ;否则总评 $G$ 就是 $G_{final}$ 。这里 $G_{mid-term}$ 和 $G_{final}$
分别为学生的期中和期末成绩。
现在的问题是,每次考试都产生一张独立的成绩单。本题就请你编写程序,把不同的成绩单合为一张。
### 输入格式:
输入在第一行给出3个整数,分别是 P(做了在线编程作业的学生数)、M(参加了期中考试的学生数)、N(参加了期末考试的学生数)。每个数都不超过10000。
接下来有三块输入。第一块包含 P 个在线编程成绩 $G_p$ ;第二块包含 M 个期中考试成绩 $G_{mid-term}$ ;第三块包含 N
个期末考试成绩 $G_{final}$ 。每个成绩占一行,格式为:`学生学号
分数`。其中`学生学号`为不超过20个字符的英文字母和数字;`分数`是非负整数(编程总分最高为900分,期中和期末的最高分为100分)。
### 输出格式:
打印出获得合格证书的学生名单。每个学生占一行,格式为:
`学生学号` $G_p$ $G_{mid-term}$ $G_{final}$ $G$
如果有的成绩不存在(例如某人没参加期中考试),则在相应的位置输出“ $-1$
”。输出顺序为按照总评分数(四舍五入精确到整数)递减。若有并列,则按学号递增。题目保证学号没有重复,且至少存在1个合格的学生。
### 输入样例:
6 6 7
01234 880
a1903 199
ydjh2 200
wehu8 300
dx86w 220
missing 400
ydhfu77 99
wehu8 55
ydjh2 98
dx86w 88
a1903 86
01234 39
ydhfu77 88
a1903 66
01234 58
wehu8 84
ydjh2 82
missing 99
dx86w 81
### 输出样例:
missing 400 -1 99 99
ydjh2 200 98 82 88
dx86w 220 88 81 84
wehu8 300 55 84 84
## 思路
+41 -28
View File
@@ -9,34 +9,47 @@ permalink: Basic/1081.html
## 题目
{% raw %}<div class="ques-view"><p>本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点 <code>.</code>,还必须既有字母也有数字。</p>
<h3 id="-">输入格式:</h3>
<p>输入第一行给出一个正整数 N(<span>$\le$</span> 100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。</p>
<h3 id="-">输出格式:</h3>
<p>对每个用户的密码,在一行中输出系统反馈信息,分以下5种:</p>
<ul>
<li>如果密码合法,输出<code>Your password is wan mei.</code>;</li>
<li>如果密码太短,不论合法与否,都输出<code>Your password is tai duan le.</code>;</li>
<li>如果密码长度合法,但存在不合法字符,则输出<code>Your password is tai luan le.</code>;</li>
<li>如果密码长度合法,但只有字母没有数字,则输出<code>Your password needs shu zi.</code>;</li>
<li>如果密码长度合法,但只有数字没有字母,则输出<code>Your password needs zi mu.</code>。</li>
</ul>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.
</code></pre>
</div>{% endraw %}
本题要求你帮助某网站的用户注册模块写一个密码合法性检查的小功能。该网站要求用户设置的密码必须由不少于6个字符组成,并且只能有英文字母、数字和小数点
`.`,还必须既有字母也有数字。
### 输入格式:
输入第一行给出一个正整数 N( $\le$ 100),随后 N 行,每行给出一个用户设置的密码,为不超过 80 个字符的非空字符串,以回车结束。
### 输出格式:
对每个用户的密码,在一行中输出系统反馈信息,分以下5种:
* 如果密码合法,输出`Your password is wan mei.`;
* 如果密码太短,不论合法与否,都输出`Your password is tai duan le.`;
* 如果密码长度合法,但存在不合法字符,则输出`Your password is tai luan le.`;
* 如果密码长度合法,但只有字母没有数字,则输出`Your password needs shu zi.`;
* 如果密码长度合法,但只有数字没有字母,则输出`Your password needs zi mu.`。
### 输入样例:
5
123s
zheshi.wodepw
1234.5678
WanMei23333
pass*word.6
### 输出样例:
Your password is tai duan le.
Your password needs shu zi.
Your password needs zi mu.
Your password is wan mei.
Your password is tai luan le.
## 思路
+36 -17
View File
@@ -9,23 +9,42 @@ permalink: Basic/1082.html
## 题目
{% raw %}<div class="ques-view"><p>本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军;谁差得最远,谁就是菜鸟。本题给出一系列弹洞的平面坐标(x,y),请你编写程序找出冠军和菜鸟。我们假设靶心在原点(0,0)。</p>
<h3 id="-">输入格式:</h3>
<p>输入在第一行中给出一个正整数 N(<span>$\le$</span> 10 000)。随后 N 行,每行按下列格式给出:</p>
<pre><code>ID x y
</code></pre><p>其中 <code>ID</code> 是运动员的编号(由 4 位数字组成);<code>x</code> 和 <code>y</code> 是其打出的弹洞的平面坐标(<code>x</code>,<code>y</code>),均为整数,且 0 <span>$\le$</span> |<code>x</code>|, |<code>y</code>| <span>$\le$</span> 100。题目保证每个运动员的编号不重复,且每人只打 1 枪。</p>
<h3 id="-">输出格式:</h3>
<p>输出冠军和菜鸟的编号,中间空 1 格。题目保证他们是唯一的。</p>
<h3 id="-">输入样例:</h3>
<pre><code class="lang-in">3
0001 5 7
1020 -1 3
0233 0 -1
</code></pre>
<h3 id="-">输出样例:</h3>
<pre><code class="lang-out">0233 0001
</code></pre>
</div>{% endraw %}
本题目给出的射击比赛的规则非常简单,谁打的弹洞距离靶心最近,谁就是冠军;谁差得最远,谁就是菜鸟。本题给出一系列弹洞的平面坐标(x,y),请你编写程序找出冠军和菜鸟。我们假设靶心在原点(0,0)。
### 输入格式:
输入在第一行中给出一个正整数 N( $\le$ 10 000)。随后 N 行,每行按下列格式给出:
ID x y
其中 `ID` 是运动员的编号(由 4 位数字组成);`x` 和 `y` 是其打出的弹洞的平面坐标(`x`,`y`),均为整数,且 0 $\le$
|`x`|, |`y`| $\le$ 100。题目保证每个运动员的编号不重复,且每人只打 1 枪。
### 输出格式:
输出冠军和菜鸟的编号,中间空 1 格。题目保证他们是唯一的。
### 输入样例:
3
0001 5 7
1020 -1 3
0233 0 -1
### 输出样例:
0233 0001
## 思路

Some files were not shown because too many files have changed in this diff Show More