yukicoder-11

从 Trac 迁移的文章

这是从旧校内 Wiki 迁移的文章,可能存在一些样式问题,您可以向 memset0 反馈。

原文章内容如下:

{{{
#!html
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}});</script>
<script type="text/javascript" async src="http://10.71.10.90/sfiction/tool/MathJax/MathJax-master/MathJax.js?config=TeX-MML-AM_CHTML"></script>
<style>
.input, pre {
    display: block;
    padding: 9.5px;
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.42857143;
    color: #333;
    word-break: break-all;
    word-wrap: break-word;
    background-color: #f5f5f5;
    border: 1px solid #ccc;
    border-radius: 4px;
}
</style>
}}}

== [https://yukicoder.me/problems/no/11 No.11 カードマッチ] ==

=== Description ===

{{{
#!html
<p>有$W \times H$张牌,其中有$W$种花色,每种有$H$张,从$1$到$H$标号。如果两张牌的花色或者标号一样,那么就算匹配。现在你有$N$张牌,第$i$张的花色和标号分别是$S_i$和$K_i$。求剩下$W \times H - N$张牌中有多少张可以和你手中任意一张牌匹配。</p>
}}}

=== Input ===

{{{
#!html
<p class="input">
$W$<br>
$H$<br>
$N$<br>
$S_1$ $K_1$<br>
$S_2$ $K_2$<br>
$\dots$<br>
$S_N$ $K_N$<br>
</p>

<p>$1 \le W, H \le 1000000, 1 \le N \le \min(W\times H, 100), 1 \le S_i \le W, 1 \le K_i \le H$。</p>
}}}

=== Output ===

{{{
#!html
<p>输出匹配数目。</p>
}}}

=== Sample ===

==== Sample 1 ====
输入
{{{
#!html
<pre>
2
5
1
1 1
</pre>
}}}
输出
{{{
#!html
<pre>
5
</pre>
}}}

==== Sample 2 ====
输入
{{{
#!html
<pre>
4
13
3
1 1
2 1
2 5
</pre>
}}}
输出
{{{
#!html
<pre>
27
</pre>
}}}

==== Sample 3 ====
输入
{{{
#!html
<pre>
4
13
4
1 5
2 6
3 7
4 8
</pre>
}}}
输出
{{{
#!html
<pre>
48
</pre>
}}}

==== Sample 4 ====
输入
{{{
#!html
<pre>
3
2
2
1 1
2 1
</pre>
}}}
输出
{{{
#!html
<pre>
3
</pre>
}}}

No.11 カードマッチ

Description

有$W \times H$张牌,其中有$W$种花色,每种有$H$张,从$1$到$H$标号。如果两张牌的花色或者标号一样,那么就算匹配。现在你有$N$张牌,第$i$张的花色和标号分别是$S_i$和$K_i$。求剩下$W \times H - N$张牌中有多少张可以和你手中任意一张牌匹配。

Input

$W$
$H$
$N$
$S_1$ $K_1$
$S_2$ $K_2$
$\dots$
$S_N$ $K_N$

$1 \le W, H \le 1000000, 1 \le N \le \min(W\times H, 100), 1 \le S_i \le W, 1 \le K_i \le H$。

Output

输出匹配数目。

Sample

Sample 1

输入

2511 1

输出

5
Sample 2

输入

41331 12 12 5

输出

27
Sample 3

输入

41341 52 63 74 8

输出

48
Sample 4

输入

3221 12 1

输出

3