誤差ãé¢é£ããåé¡ã§äººã
ãæå¥ãè¨ã£ã¦ãããã³ã«ããããæ°æã¡ã«ãªãã¾ãã
â ãããããã·ãªã¼ãºã¨å¼ãã§ãããã® â
rsk0315.hatenablog.com
rsk0315.hatenablog.com
ã¾ããã
ã誤差 WAãã§ãã¤ã¼ãæ¤ç´¢ãããã¨ããWA ãåºãã誤差ãåå ãï¼ãããã¶ã誤差ã®ããã ããããã©ãããã¨ãã«è½ã¡ãã®ãããããªããã®ãããªãµãã£ã¨ããæè¦ã®äººãããããè¦ã¤ããã¾ããã
æ´æ°ã®ãªã¼ãã¼ããã¼ãªã©ã¯ãã¨ãããã大ããå¤ãå
¥ãã¦ç¢ºããã¦ã¿ããã¿ãããªããæ¹ãããã®ã§ãï¼ãªã¼ãã¼ããã¼ã¨ããæ¦å¿µãç¥ã£ã¦ããããã°ï¼ä¿®æ£ã®ä½å°ã¯ããã¾ãã
ä¸æ¹ãæµ®åå°æ°ç¹æ°ã®èª¤å·®ã«é¢ãã¦ã¯ãã¨ããããéé²ã«ãã¡ããã¡ããã£ã¦ã¿ã¦ã誤差ã§è½ã¡ãã±ã¼ã¹ã¯è¦å½ãããªãããæ¬å½ã«èª¤å·®ã®ãããï¼ èå¯ã§å¥éãªã«ãééã£ã¦ããã®ã§ã¯ï¼ãã®ãããªæ°æã¡ã«ãªã人ãå¤ããã§ãã
競ããããã£ã¦ãã¦ãè¨ç®éãªãã¦éæ¬è³ªãããªã¼ãã¼ããã¼ããã®ã¯æ´æ°åãæªãããªã©ã¨è¨ã£ã¦ããåå¿è
ãããããã¾ã ã¾ã çµé¨ãæµ
ããã ãããã¨ããæ°æã¡ã«ãªãã¨æãã¾ããã誤差ã®è©±ã«ãªãã¨çµé¨ãæµ
ãå´ã«ãªã£ã¦ãã¾ã人ãå¤æ°æ´¾ãªæ°ããã¾ã*1ã
ãã®è¨äºãéãã¦ãããããããã¨ãããã°èª¤å·®ã大ãããªãã±ã¼ã¹ãä½ããã®ãããã¨ãããã¨ãããã£ã¦ããã£ã¦ãèªåã§è§£æ±ºã§ãã人ãå¢ããããããããªãã¨ããæ°æã¡ã§ãã
ç¥èãã¾ã ååã§ãªã人ã¯ãä¸è¨ã®è¨äºã«ç®ãéãã¦ã¿ããã¨ããããããã¾ãã
証æã®æ°å¼ãã¼ããå
¨é¨è¿½ãã¿ãããªãã¨ãããå¿
è¦ã¯ãªãã¦ããããã¯ããã£ã¨èªã¿æµããããã§ãããããªã¨æãã¾ãã
rsk0315.hatenablog.com
è¨æ³
ä¸è¨ã®è¨äºããã®æµç¨ã§ããã次ã®è¡¨ã«ãããã®ãã¡ã使ãã¾ãã
丸ãã«é¢ãã¦ã¯ããããã double
ã®ããã©ã«ãã®æåï¼53-bit ä»®æ°é¨ãroundTiesToEvenï¼ãåæã¨ãã¾ãã
è¨æ³ |
æå³ |
ä¾ |
$\roundp x$ |
å®æ° $x$ ãæµ®åå°æ°ç¹æ°ã«ä¸¸ãããã® |
$\roundp 1 = 1$, $\roundp{0.1} = \tfrac1{10}(1+2^{-54})$ |
$x\oplus y$ |
æµ®åå°æ°ç¹æ° $x$, $y$ ã«å¯¾ã㦠$\roundp{x+y}$ |
$1\oplus 2 = 3$, $\roundp{0.1}+\roundp{0.2} = \tfrac1{10}(3+2^{-51})$ |
$x\ominus y$ |
æµ®åå°æ°ç¹æ° $x$, $y$ ã«å¯¾ã㦠$\roundp{x-y}$ |
$1\ominus 2 = -1$, $\roundp{0.3}-\roundp{0.2} = \tfrac1{10}(1-2^{-52})$ |
$x\otimes y$ |
æµ®åå°æ°ç¹æ° $x$, $y$ ã«å¯¾ã㦠$\roundp{x\times y}$ |
$2\otimes 3 = 6$, $\roundp{0.1}\otimes\roundp{0.2} = \tfrac2{100}(1+2^{-50})$ |
$x\oslash y$ |
æµ®åå°æ°ç¹æ° $x$, $y$ ã«å¯¾ã㦠$\roundp{x\div y}$ |
$12\oslash 3 = 4$, $\roundp{0.3}\oslash\roundp{0.1} = 3+2^{-51}$ |
$\hfloor x$ |
æ£ã®å®æ° $x$ ã«å¯¾ãã¦ãæ´æ° $e$ ãç¨ã㦠$2^e=y\le x$ ã¨æ¸ãã $y$ ã®æå¤§å¤ |
$\hfloor 1=1$, $\hfloor{0.3} = 0.25$, $\hfloor{100}=64$ |
ç¹ã«ãæ°å¼ä¸ã§ãã¨ãã° $0.1$ ã®ããã«æ¸ããã¨ãã«æé»ã«ä¸¸ãã®å¯¾è±¡ã«ãããã¨ã¯ããã$0.1 = 0.1000{\dots}000{\dots}$ ãæå³ãã¾ãã丸ããè¡ãé㯠$\roundp{\bullet}$ ãç¨ãã¦æ示ãã¾ãã
ä¾ã¨ãã¦ãä¸è¨ã§æãã $\roundp{0.1} = \tfrac1{10}(1+2^{-54})$ ã¨ããçå¼ããè¨ç®æ©å´ã®è§£éã¨ä¸è´ãã¦ãããã¨ï¼ããªãã¡ããã³ã¡ãããé©å½ãªå¤ãå°å
¥ãã¦ããããã§ã¯ãªããã¨ï¼ã確ããã¦ããã¦ã¿ã¾ãããã
>>> from decimal import Decimal, getcontext
>>> getcontext().prec = 100
>>> Decimal(0.1)
Decimal('0.1000000000000000055511151231257827021181583404541015625')
>>> (1+Decimal(2)**-54)/10
Decimal('0.1000000000000000055511151231257827021181583404541015625')
warning: ããã§ã¯ $\roundp{0.1}$ ãï¼ã¨ããã 2 é²ã®æµ®åå°æ°ç¹æ°ãï¼ååãªæ¡æ°ã® 10 é²æ³ã§è¡¨ãããã¨ãªã©ãã Decimal
ã使ã£ã¦ç¢ºèªãã¦ããã ãã§ããDecimal
ã使ãã°ã©ããªæèã§ãæ£ç¢ºãªæ¤è¨¼ãã§ããããªã©ã¨ã¯è§£éããªãã§ãã ããã
ããããåå¿è
ãæåã«æèãã¹ããã¨ã¯ä¸è¨ãªããããªãããªã¨æã£ã¦ãã¾ãã
- æµ®åå°æ°ç¹æ°*2ã®æ¼ç®ã«ã¯åç¾æ§ãããã
- å
¥åã丸ãã¢ã¼ãããåããªãããå®è¡ãããã³ã«èª¤å·®ãåºããåºãªãã£ãããããã誤差ã®å¤§ãããé½åº¦å¤ãããã®ãããªãã¨ã«ã¯ãªããªãã
- 誤差ã¯æå³ä¸æãªãã®ã§ã¯ãªããåæãæ´çããã°æ°å¼ã§æ±ãã対象ã«ãªãã
å®æ°ã®æ¼ç®ã¨ã®å·®ç°
ããæ§è³ªãå®æ°ã®æ¼ç®ã§æãç«ã¤ããã¨ãã£ã¦ãæµ®åå°æ°ç¹æ°ã®æ¼ç®ã§æãç«ã¤ã¨ã¯éãã¾ããã
ãã¨ãã°ã$y\ne 0$ ã«å¯¾ã㦠$\tfrac xy\times y=x$ ã§ããã$(x\oslash y)\otimes y\ne x$ ã¨ãªããã¨ã¯ããã¾ãã
ããããä¾ã¨ãã¦ã¯ã$y$ ã®é¨åãï¼ããããç°ãªãï¼é·ãã®å¼ã§ããåæ¯ã® $y$ ã¨æãã¦ããæ¹ã® $y$ ãä¸è´ããã¨ãã¯æã¡æ¶ãåã£ã¦ãããã ãããã¨æå¾
ããããå®éã«ã¯ $x$ ãããããå¤ã«ãªã£ã¦ãã¾ãã¨ãããã®ã§ãã
å°ããå¤ã®ä¾ã¨ãã¦ã¯ã次ã®ãããªãã®ã§ãã
$$
\begin{aligned}
(1\oslash 49)\otimes 49 &= 1 - 2^{-53} \lt 1, \\
(3\oslash 187)\otimes 187 &= 3 + 2^{-51} \gt 3.
\end{aligned}
$$
ã¾ããããç¨åº¦å¤§ããå¤ã®ä¾ã¨ãã¦ã¯ã次ã®ãããªãã®ã§ãã
$$
\begin{aligned}
(10^9\oslash 29)\otimes 29 &= 10^9 - 2^{-23} \lt 10^9, \\
(10^9\oslash 45)\otimes 45 &= 10^9 + 2^{-23} \gt 10^9.
\end{aligned}
$$
ããã ãã ã¨ç¸å¯¾èª¤å·®ã¯ååå°ããï¼ã¨è¦ãªããåé¡è¨å®ãå¤ãï¼ã®ã§èãã¾ãããhack ã®éã«ã¯ããããå
¥åãå½¹ã«ç«ã¡ããã§ãã
ãªããååã® $x$ ãåºå®ã㦠$y$ ãå
¨æ¢ç´¢ããã¨ç°¡åã«è¦ã¤ãããã¨ãã§ãã¾ãã
ãªãããã®ãã¯ããã¯*3èªä½ã¯ double
ã«éãã long double
ã Decimal
ãªã©ã«å¯¾ãã¦ãæå¹ã§ããåã«ãã£ã¦èª¤å·®ãåºãå
¥åãç°ãªãã®ã§ãçããã解æ³ã«å¿ãã¦æ§ç¯ããå¿
è¦ã¯ããã¾ããä»®æ°é¨ã 24-bit, 53-bit, 64-bit, 113-bit ã® 2 é²ã®æµ®åå°æ°ç¹åã«é¢ãã¦ã¯ãããããä¸è¨ãæãç«ã¡ã¾ã*4ã
- $(1\oslash 3027)\otimes 3027\lt 1$,
- $(3\oslash 10767)\otimes 10767\gt 3$.
ãããã¯ãä¸è¨ 4 ã¤ã«å ããPython ã® Decimal
ã®ããã©ã«ãã®è¨å®å¤ï¼ç²¾åº¦ã丸ãã¢ã¼ãï¼ã«ããã¦ãããããä¸è¨ãæãç«ã¡ã¾ãã
- $(1\oslash 7814)\otimes 7814\lt 1$,
float
: $1-2^{-24}$
double
: $1-2^{-53}$
long double
(64-bit): $1-2^{-64}$
long double
(113-bit): $1-2^{-113}$
Decimal
: $1-2\cdot 10^{-28}$
- $(3\oslash 175337)\otimes 175337\gt 3$.
float
: $3+2^{-22}$
double
: $3+2^{-51}$
long double
(64-bit): $3+2^{-62}$
long double
(113-bit): $3+2^{-111}$
Decimal
: $3+10^{-27}$
ä¸è¬ã«ãå®æ° $x\ne0$ ã丸ããã¨ãã®èª¤å·®ã¯æ¬¡ã®ããã«è©ä¾¡ã§ãã¾ãã
$$
\begin{aligned}
|{x-\roundp x}|
&\le \hfloor{|x|}\cdot 2^{-53}
\end{aligned}
$$
ä¸è¨ã®ä¾ãè©ä¾¡ãã¦ã¿ã¾ãã
$$
\begin{aligned}
|\tfrac{10^9}{29}-(10^9\oslash 29)|
&\le \hfloor{\tfrac{10^9}{29}}\cdot 2^{-53} = 2^{25-53} \\
|(\tfrac{10^9}{29}\cdot 29)-( (10^9\oslash 29)\cdot 29)|
&\le 29\cdot 2^{25-53}
\end{aligned}
$$
ããã³
$$
\begin{aligned}
|( (10^9\oslash 29)\cdot 29) - ( (10^9\oslash 29)\otimes 29)|
&\le \hfloor{(10^9\oslash 29)\cdot 29}\cdot 2^{-53} = 2^{29-53}
\end{aligned}
$$
ãããä¸è§ä¸çå¼ãã
$$
|10^9 - ( (10^9\oslash 29)\otimes 29)|
\le (29\cdot 2^{25}+2^{29})\cdot 2^{-53}
\approx 1.67\times 10^{-7}
$$
ã¨ãªãã¾ãã$2^{-23} \approx 1.19\times 10^{-7}$ ãªã®ã§ããã®ç¯å²ã«åã¾ã£ã¦ãããã¨ããä¸çã¨æ¦ãåãç¨åº¦ã®èª¤å·®ãåºã¦ãããã¨ã確ããããã¾ãã
exercise: $10^9$ 以ä¸ã®æ£æ´æ° $x$, $y$ ã§ãã£ã¦ã$|x - ( (x\oslash y)\otimes y)|$ ã $2^{-23}$ ãã大ãããã®ã¯åå¨ãããï¼ ããã°ä¾ãæ§ç¯ãããªããã°ãããæ大ã§ãããã¨ã示ãã
ããããä¾ã®æå¢
note: AC ã¨æããã¦ããã³ã¼ãã«å¯¾ãã¦ãAC ã¨ãªããªãå
¥åãä¸ãããã¨ããhackããchallengeããæå¢ããªã©ã¨å¼ã³ã¾ããCodeforces ã Topcoder ã«ç±æ¥ããç¨èªã§ãã
ä¸æ¬¡é¢æ° (1)
ç¸ç°ãªã 2 ç¹ $(x_0, y_0)$, $(x_1, y_1)$ ãéãä¸æ¬¡é¢æ°
$$ y = \frac{y_1-y_0}{x_1-x_0}\cdot (x-x_0) + y_0 $$
ãèããããã®ç´ç·ã® $x=0$ ã§ã® $y$ 座æ¨
$$ y = \frac{y_1-y_0}{x_1-x_0}\cdot (-x_0) + y_0 $$
ãæ±ãããå
¥å㯠$10^9$ 以ä¸ã®æ£æ´æ°ã§ã許容誤差㯠$10^{-9}$ ã¨ããã
use proconio::input;
fn main() {
input! {
(x0, y0, x1, y1): (f64, f64, f64, f64),
}
let res = ((y1 - y0) / (x1 - x0)) * (-x0) + y0;
println!("{res}");
}
è¨ç®ãã¦ãããã®ã¯
$$
( ( (y_1\ominus y_0)\oslash(x_1\ominus x_0) )\otimes (-x_0) ) \oplus y_0
$$
ã§ãããå
¥å㯠$10^9$ 以ä¸ã®æ´æ°ãªã®ã§ã$y_1\ominus y_0 = y_1-y_0$ ã $x_1\ominus x_0 = x_1-x_0$ ãæãç«ã¡ã¾ãï¼æ¼ç®åä¸ã¤ä¸ã¤ãæèããã®ã大äºã§ãããï¼ã
å
ã®è°è«ããã$(x_1-x_0)$ ã§å²ã£ã¦ãã $(-x_0)$ ãæããé¨åãæ»ãããããã§ãã
ç°¡åã®ããã$y_1-y_0 = y_0$, $x_1-x_0 = x_0$ ã¨ãã¦ãã¾ãã¾ããããããªãã¡ã$(x_1, y_1) = (2x_0, 2y_0)$ ã§ãã
誤差ã大ãããããã㪠$x_0$, $y_0$ ã $5\cdot 10^8$ 以ä¸ã®æ£æ´æ°ã®ç¯å²ã§æ¢ãã°ããã§ãã
ãã®ã³ã¼ãã¯ããã¨ãã°ä¸è¨ã®ã±ã¼ã¹ã§æå¢ãããã¨ãã§ãã¾ãã
- $(x_0, y_0) = (45, 500000000)$
- $(x_0, y_0) = (29, 500000000)$
ãããã $-2^{-24}$ 㨠$2^{-24}$ ãåºåãã¾ããã$2^{-24} \approx 5.96\times 10^{-8}$ ãªã®ã§è¨±å®¹èª¤å·®ã $60$ åã»ã©ä¸åã£ã¦ãã¾ãã
åè
ã®ã±ã¼ã¹ã§ã¯ã$(500000000\oslash 45)\otimes 45 = 500000000 + 2^{-24}$ ã¨ãã¦èª¤å·®ãåºããã¦ã$500000000$ ããå¼ããã¨ã§ã誤差㮠$2^{-24}$ ã®é¨åã主è¦é
ã«ããã¦ãã¾ãã
ä¸è¬ã«ãå®æ° $x$, $y$ ã«å¯¾ãã¦ã$(\roundp x, \roundp y)\ne (x, y)$ ã㤠$\roundp x\approx \roundp y$ ã®ã¨ãã$\roundp x\ominus \roundp y$ 㯠$x-y$ ã¨å¤§ããç°ãªãå¾ã¾ã*5ã
ããã«ãã£ã¦å¤§ããªèª¤å·®ãåºãï¼èª¤å·®é
ã ã£ãé¨åã主è¦é
ã«ãªã£ã¦ãã¾ãï¼ãã¨ããæ¡è½ã¡ ã catastrophic cancellation ãªã©ã¨å¼ã³ã¾ãã
ã¾ããçã®å¤ã¯ $1$ 以ä¸ã§ãã£ã¦ã»ãããããªç¶æ³ã«ã¤ãã¦ãèãã¦ã¿ã¾ãã
$x_1-x_0 = x_0$ ããã³ $y_1-y_0 = y_0-1$ ã¨ãã¦ã¿ã¾ããããããªãã¡ $(x_1, y_1) = (2x_0, 2y_0-1)$ ã§ãã
ä»å㯠$5\cdot 10^8-1$ 以ä¸ã§ãã¤ãã®ãã¢ãæ¢ãå¿
è¦ãããã¾ããããã¯ãç°¡åã«è¦ã¤ããã¾ãã
$$
\begin{aligned}
(499999999\oslash 11)\otimes 11 &= 499999999 - 2^{-24} \lt 499999999, \\
(499999999\oslash 39)\otimes 39 &= 499999999 + 2^{-24} \gt 499999999.
\end{aligned}
$$
ãããç¨ãã¦ã次ã®ã±ã¼ã¹ã§æå¢ã§ãã¾ãã
- $(x_0, y_0) = (11, 500000000)$
- $(x_0, y_0) = (39, 500000000)$
ãããã $1-2^{-24}$ 㨠$1+2^{-24}$ ãåºåãã¾ãã
ä¸æ¬¡é¢æ° (2)
ç¸ç°ãªã 2 ç¹ $(x_0, y_0)$, $(x_1, y_1)$ ãéãä¸æ¬¡é¢æ°ã® $x=0$ ã§ã® $y$ 座æ¨
$$
\begin{aligned}
y &= \frac{y_1-y_0}{x_1-x_0}\cdot (-x_0) + y_0 \\
&= \frac{(-x_0)(y_1-y_0)+(x_1-x_0)y_0}{x_1-x_0} \\
&= \frac{x_0y_1-x_1y_0}{x_0-x_1}
\end{aligned}
$$
ãæ±ãããå
¥å㯠$10^9$ 以ä¸ã®æ£æ´æ°ã§ã許容誤差㯠$10^{-9}$ ã¨ããã
â» çã®å¤ã¨ãã¦ã¯ãä¸æ¬¡é¢æ° (1) ã¨åããã®ã§ããã
use proconio::input;
fn main() {
input! {
(x0, y0, x1, y1): (f64, f64, f64, f64),
}
let res = (x0 * y1 - x1 * y0) / (x0 - x1);
println!("{res}");
}
è¨ç®ãã¦ãããã®ã¯ä¸è¨ã§ãã
$$
( (x_0\otimes y_1)\ominus (x_1\otimes y_0) )\oslash (x_0\ominus x_1).
$$
大åæã¨ãã¦ã$2^{53}+1 \approx 9.00\times 10^{15}$ 以ä¸ã®æ´æ°ã¯ãdouble
ã§æ£ç¢ºã«è¡¨ããã¨ã¯éãã¾ããã$x_0y_1$ 㯠$10^{18}$ ç¨åº¦ã¾ã§å¤§ããã§ããã®ã§ãããããã¾ã使ãã¾ã*6ã
æ¹é 1-1
ç°¡åãªä¾ã¨ãã¦ã$x_0\otimes y_1 = x_1\otimes y_0$ ã¨ãªããã®ãèãã¾ãã
ããªãã¡ãåãæµ®åå°æ°ç¹æ°ã«ä¸¸ãããããããªç°ãªãæ´æ°ãæã£ã¦ãããã§ãã
$2^{53}+1$ 以ä¸ã®æ´æ°ãç´ å æ°å解ãã¦ã$10^9$ ãè¶
ããç´ å æ°ãæããªããã®ãæ¢ãã¾ãããã®ä¸ãããåãæµ®åå°æ°ç¹æ°ã«ä¸¸ãããããã¢ãæ¢ãã¾ãã
$$
\begin{aligned}
2^{53}+12 = 9007199254741004 &= 2^2\times 967\times 3967\times 4547\times 129097, \\
2^{53}+13 = 9007199254741005 &= 3^3\times 5\times 47\times 56311\times 25209539.
\end{aligned}
$$
é©å½ã«ç´ å æ°ãé¸ã³ã次ã®ããã«ãããã¨ãã§ãã¾ãã
$$
\begin{aligned}
2^{53}+12
&= 15344356\times587004059 \\
&= 17587796\times512127799 \\
&= 18037949\times499347196 \\
&= 36075898\times249673598 \\
&= 72151796\times124836799, \\
2^{53}+13
&= 13233085\times680657553 \\
&= 23819553\times378143085 \\
&= 25209539\times357293295 \\
&= 39699255\times226885851 \\
&= 71458659\times126047695 \\
&= 75628617\times119097765.
\end{aligned}
$$
ã¨ãããã¨ã§ã$(x_0y_1, x_1y_0) = (2^{53}+13, 2^{53}+12)$ ã¨ããã°ããã§ãã
ã¾ããååï¼ã®çã®å¤ï¼ã¯ $1$ ã§åºå®ãªã®ã§ãåæ¯ï¼ã®çã®å¤ï¼ã®çµ¶å¯¾å¤ã¯ãªãã¹ãå°ããæ¹ãï¼èª¤å·®ã大ãããã観ç¹ã§ã¯ï¼ããããæ°æã¡ã«ãªãã¾ãã
$$ (x_0, y_0, x_1, y_1) = (71458659, 124836799, 72151796, 126047695) $$
ã¨ããã¨ãçã®å¤ã¯ $-\tfrac1{693137} \approx -1.44\times 10^{-6}$ ã¨ãªãã¾ãã
æ¹é 1-2
â» SB æ¨ = SternâBrocot tree
$(F_0, F_1, \dots, F_n, \dots) = (0, 1, \dots, F_{n-2}+F_{n-1}, \dots)$ ã¨ãã¦å®ç¾©ããã Fibonacci æ°åãèãã¾ãã
ä»»æã® $i\ge 0$ ã«å¯¾ãã$(a, b, c, d) = (F_{i+3}, F_{i+2}, F_{i+1}, F_i)$ ã¨ã㦠$ad-bc = 1$ ãæãç«ã¡ã¾ãã
ãã¨ãã° $F_{39}\otimes F_{42} = F_{40}\otimes F_{41}$ ã㤠$F_{42}\le 10^9$ ã¨ãªãã®ã§ãããã使ãã¾ãã
$$ (x_0, y_0, x_1, y_1) = (F_{39}, F_{41}, F_{40}, F_{42}) $$
ã¨ããã¨ã絶対誤差㯠$\tfrac1{F_{38}} \approx 2.56 \times 10^{-8}$ ã¨ãªãã¾ãã
æ¹é 2
å®éã«ã¯ $x_0\otimes y_1 = x_1\otimes y_0$ ã§ããå¿
è¦ã¯ããã¾ãããããç¨åº¦è¿ãå¤ã§ããã° catastrophic cancellation ã§ã©ãã«ã§ããªãããã§ãã
åºæ¬çã«ã¯æ¹é 1-1 ã§ãã£ãã®ã¨åæ§ã®èãæ¹ã§é²ãã¾ãã
ç¯å²ãåºå®ãããã®ä¸ã®åæ´æ°ã 2 æ´æ°ã®ç©ã¨ãã¦è¡¨ãæ¹æ³ãå
¨é¨è©¦ãã誤差ã大ãããªãçµãæ¢ãã¾ãã*7ã
ç¯å²ã¨ãã¦ã¯ã$[5\cdot10^{17}-2\cdot10^5\lldot 5\cdot 10^{17}+2\cdot10^5]$ ãªã©ã試ãã¾ããã
ãããããã許容誤差 $10^{-9}$ãã¨è¦ã¦ãæ®éã«è¨ç®ãã¦ãããã®ç¨åº¦ã®èª¤å·®ã«åã¾ãã§ããï¼ãã¨ããå®é丸ã誤差ãªã㦠$10^{-16}$ ãããã§ããï¼ãã¨æã£ããããWA ãåºãã¨ãã£ã¦ãããã $10^{-7}$ ãããã®èª¤å·®ãåºã¦ããã§ããï¼ãã¨ã¼ãããæã£ã¦ãã人ãå¤ããã¨ã§ãããããããã人ã次ã®ã±ã¼ã¹ãã¡ãè¦ã¦ååãã¦ããããããããã§ãã
$$
\begin{aligned}
(x_0, y_0, x_1, y_1)_A &= (707085728, 707127834, 707085729, 707127835), \\
(x_0, y_0, x_1, y_1)_R &= (962214805, 931734628, 965940272, 935342083), \\
(x_0, y_0, x_1, y_1)_M &= (999999990, 500000004, 999999992, 500000005).
\end{aligned}
$$
æ·»å |
çã®å¤ |
è¨ç®çµæ |
絶対誤差 |
ç¸å¯¾èª¤å·® |
$A$ |
$42106$ |
$42048$ |
$58$ |
$\approx 1.38\times10^{-3}$ |
$R$ |
$\approx 2.68\times10^{-8}$ |
$\approx 3.44\times 10^{-5}$ |
$\approx 3.41\times 10^{-5}$ |
$\approx 127$ |
$M$ |
$9$ |
$32$ |
$23$ |
$\approx 2.56$ |
è¦ã¤ãã£ããã®ã®ãã¡ã絶対誤差 ($A$)ãç¸å¯¾èª¤å·® ($R$)ããããã®æå°å¤ ($M$) ãä¸çªå¤§ããã£ããã®ãããããè¼ãã¾ãããï¼è¦ã¤ãã次第æ´æ°ãã¾ãï¼
ãã£ããè¦ç©ããçã«ã¯ã$\hfloor{10^{18}}\cdot 2^{-53} = 64$ ãããã®çµ¶å¯¾èª¤å·®ã¯åºãããªã®ã§ããããããã®å¤§ããã®å®ä¾ãåºããã°æºè¶³ãã¦ãããã®ã§ã¯ãªãã§ããããï¼ï¼ï¼
ã¾ãã$(x_i, y_i) \approx (10^9-\varepsilon, 5\cdot 10^8+\varepsilon)$ ã®ç¯å²ã§ããç¹ã«èããã«æ¢ç´¢ãã¾ããã
次ã®ã±ã¼ã¹ã§çµ¶å¯¾èª¤å·® $64$ ãéæã§ãã¾ãããç¸å¯¾èª¤å·®ã¯å°ããã£ãã®ã§ãhack ã«ã¯ä½¿ããªãããã§ãã
$$
(x_0, y_0, x_1, y_1) = (999999000, 500000032, 999999001, 500000004).
$$
ä¸æ¬¡é¢æ° (3)
ç¸ç°ãªã 2 ç¹ $(x_0, y_0)$, $(x_1, y_1)$ ãéãä¸æ¬¡é¢æ°ã® $x=0$ ã§ã® $y$ 座æ¨
$$
\begin{aligned}
y &= \frac{(y_1-y_0)(-x_0)}{x_1-x_0} + y_0
\end{aligned}
$$
ãæ±ãããå
¥å㯠$10^9$ 以ä¸ã®æ£æ´æ°ã§ã許容誤差㯠$10^{-9}$ ã¨ããã
â» çã®å¤ã¨ãã¦ã¯ãä¸æ¬¡é¢æ° (1), (2) ã¨åããã®ã§ããã
use proconio::input;
fn main() {
input! {
(x0, y0, x1, y1): (f64, f64, f64, f64),
}
let res = ((y1 - y0) * (-x0)) / (x1 - x0) + y0;
println!("{res}");
}
ä»åã¯ã(1) ã®è§£æ³ã§ $(y_1-y_0)\otimes(-x_0)$ ã®æ¹ãå
ã«è¨ç®ãããã¼ã¸ã§ã³ã§ãã
$$
( ( (y_1\ominus y_0)\otimes (-x_0) )\oslash (x_1\ominus x_0) )\oplus y_0.
$$
以åè¦ã
$$
71458659 \otimes 126047695 = 72151796 \otimes 124836799
$$
ãå©ç¨ãã¦ã¿ã¾ãããããã¨ãã°ãä¸è¨ãè¨ç®ãããããã«ä»åãããã§ãã
$$
(71458659\otimes -126047695)\oslash 72151796 \oplus 124836799
$$
ããªãã¡ãä¸è¨ãä¸ããã°ããã§ãã
$$
(x_0, y_0, x_1, y_1) = (126047695, 124836799, 198199491, 196295458).
$$
ä»ã®ã±ã¼ã¹ã使ããã¨ã¯æãã¾ãï¼ç¹ã«è©¦ãã¦ãã¾ãããèªè
ã®ãã¦ã¦åããç¨ã«æ®ãã¦ããã¾ãï¼ã
åæ£
æ´æ°å $a = (a_1, a_2, \dots, a_n)$ ã«å¯¾ãã¦ãåæ£
$$ \frac1n\sum_{i=1}^n a_i^2 - \left(\frac1n\sum_{i=1}^n a_i\right)^2 $$
ãæ±ããã$n$ 㯠$15$ 以ä¸ã$a_i$ 㯠$10^8$ 以ä¸ã®æ£æ´æ°ã¨ãã許容誤差㯠$10^{-6}$ ã¨ããã
use proconio::input;
fn main() {
input! {
n: usize,
a: [i64; n],
}
let sum1: i64 = a.iter().sum();
let sum2: i64 = a.iter().map(|ai| ai * ai).sum();
let avg1 = sum1 as f64 / n as f64;
let avg2 = sum2 as f64 / n as f64;
let res = avg2 - avg1 * avg1;
println!("{res}");
}
$(s_1, s_2) = (\sum a_i, \sum a_i^2)$ ã¨ãããããã¯æ´æ°åã§è¨ç®ãã¦ãã¾ãã¾ããã¾ããå¤ã®ç¯å²ãã $\roundp{s_1} = s_1$ ã§ãã
è¨ç®ãããå¤ã¯ã
$$
(\roundp{s_2}\oslash n)\ominus \bigroundp{(s_1\oslash n)^2}
$$
ã¨ãªãã¾ãã
åç´ãªä¾
$15$ åã使ããã¨ãèããã®ã¯å¤§å¤ã§ãã®ã§ãã¨ãããã $n=2$ ã§èãã¦ã¿ã¾ãããã
ä¸è¬ã«ãæ£è¦åæ°ã®ç¯å²ã§ã¯ $x\oslash 2 = \tfrac x2$ ã $x\otimes 2 = 2x$ ãªã®ã§ã
$$
\begin{aligned}
(\roundp{a_1^2+a_2^2}\oslash 2)\ominus \bigroundp{( (a_1+a_2)\oslash 2)^2}
&= \frac{\roundp{a_1^2+a_2^2}}2\ominus \biggroundp{\left(\frac{a_1+a_2}2\right)^2} \\
&= \frac{2\roundp{a_1^2+a_2^2} \ominus \roundp{(a_1+a_2)^2}}4 \\
&= \frac{\roundp{2a_1^2+2a_2^2} \ominus \roundp{a_1^2+2a_1a_2+a_2^2}}4
\end{aligned}
$$
ã¨ãªãã¾ãã
çµå±ã$2a_1^2+2a_2^2$ 㨠$a_1^2+2a_1a_2+a_2^2$ ã誤差ãå«ãè¿ãå¤ã§ããã° catastrophic cancellation ã§è½ã¨ãããã§ãã
åç´ã« $(a_1, a_2) = (10^8, 10^8-1)$ ã§è©¦ããã¨ãããçã®å¤ã $0.25$ ãªã®ã«å¯¾ããè¨ç®çµæ㯠$0$ ã¨ãªã£ã¦ããã¾ããã
ã¾ãã$(a_1, a_2) = (10^8, 10^8-2)$ ã¨ããã¨ãçã®å¤ã $1$ ãªã®ã«å¯¾ããè¨ç®çµæ㯠$2$ ã¨ãªãã¾ããã
å¾è
ã®ã±ã¼ã¹ã§ã¯ã絶対誤差ãç¸å¯¾èª¤å·®ã $1$ ã§ããã許容誤差ã大ããä¸åã£ã¦ãã¾ãã
大ããã®ä¾
DFS ãã¦ã¿ã¾ããã$a_i \approx 10^8-\varepsilon$ ã®ç¯å²ã§é©å½ã«æ¢ç´¢ãã¾ãã
$a = (99999996)\concat(99999995)^8$ ã®ã±ã¼ã¹ã§ãçã®å¤ã $\tfrac8{81}$ ã®ã¨ãã $4$ ã¨ãªãã絶対誤差ã $\tfrac{316}{81} \approx 3.90$ãç¸å¯¾èª¤å·®ã $39.5$ ã¨ãªãã¾ããã
絶対誤差ã大ãããããã¨ã«é¢ãã¦ã§ããã°ã
$$ a = (100000000)^8\concat(99999999)\concat(99999994)\concat(99999990)^4\concat(99999989) $$
ãªã©ã§ $\tfrac{956}{225}\approx 4.25$ ã«ãªãã¾ããã
ä¸ã®ï¼å°ããæ¹ã®èª¤å·®ã $3.90$ ç¨åº¦ã®ï¼ä¾ã«ããã¦ã¯ã$(s_1, s_2) = (899999956, 89999991200000216)$ ã§ãã
$$
\begin{aligned}
899999956\oslash 9 &= \tfrac19(899999956-2^{-24}), \\
\roundp{(899999956\oslash 9)^2} &= \tfrac1{81}(899999956^2 - 172) \\
&= 9999999022222244, \\
\roundp{89999991200000216} &= 89999991200000216 + 8, \\
\roundp{89999991200000216}\oslash 9 &= \tfrac19(89999991200000216 + 16) \\
&= 9999999022222248.
\end{aligned}
$$
æçµçãªçã㯠$9999999022222248 \ominus 9999999022222244 = 4$ ãªã®ã§ããããã« catastrophic cancellation ãèµ·ãã¦ãããªãã¨ããæ°æã¡ã«ãªãã¾ããã
ä¸è¨ã³ã¼ãã®æ¹å
æå¢ãããªãã³ã¼ããæ¸ããªãã¨ãããªãæ°ãããã®ã§ã示ãã¦ããã¾ãããã
ä¸è¨ã®ä¾ã§è¦ã¦ããããã«ãæå¢ããã¨ãã«ã¯ catastrophic cancellation ããããããã®ã§ãé²å¾¡å´ï¼ï¼ï¼ã®ã¨ã㯠catastrophic cancellation ãèµ·ããªãããã«æ°ãã¤ãã¾ãããã
ã¨ã«ããã足ãç®å¼ãç®ããããã³ã«ä¸è¨ã®ãã¨ããã§ãã¯ããããããã¡ããã©ããã§ãããï¼å²ãç®ããããã³ã«åæ¯ã $0$ ã«ãªããã¨ããªãããã§ãã¯ããã®ã¨åæ§ã«*8ï¼ã
ä¸è¨ã¯å¼ãç®ãã¼ã¹ã§æ¸ãã¦ãã¾ããã足ãç®ãªã符å·ã®é¨åã¯éã«ãã¦èªãã§ãã ããã
- ã©ã¡ãã®é
ã誤差ãå«ã¾ãªããªã ok
- ããããå ´å㯠benign cancellation ãªã®ã§å¤§ä¸å¤«ã
- å¼ãç®èªä½ã«ãã£ã¦èª¤å·®ãåºããã¨ã¯ããå¾ãã®ã§ããã®è¨ç®çµæã使ãã¨ãã¯æ³¨æã
- ä¸è¨ã ok ã§ãªãã¦ãã符å·ã常ã«ç°ãªããªã ok
- cancellation ã«ãªããªãããã
- ä¸è¨ã ok ã§ãªãã¦ãã絶対å¤ãåç¨åº¦ã«ãªããªããªã ok
- cancellation ã«ãªããªãããã
- å¤ãã®å ´åãåç¨åº¦ã«ãªãã±ã¼ã¹ãæ§ç¯ã§ããã¯ããªã®ã§æ°ãã¤ããã
ããã ok ã§ãããã¨ã示ããªããªããå¼å¤å½¢ããæ¹éã§èå¯ãé²ããæ¹ãããããã§ãã
ååã¨åæ¯ãããããæ´æ°åã§è¨ç®ã§ããå½¢ã«ãã¦ãã¾ãã®ãããã§ãããã$m/n$ ã®å½¢ã«ãªã£ããã誤差ã¯
$$\gamma_3 = \frac{3\cdot 2^{-53}}{1-3\cdot2^{-53}}\approx3.34\times10^{-16}$$
ãç¨ãã¦
$$ |{{m/n}-(\roundp m\oslash\roundp n)}| \le \hfloor{m/n}\cdot \gamma_3 $$
ç¨åº¦ã§æããããï¼ååã¨åæ¯ã®ä¸¸ã㧠2 åãé¤ç®ã§ 1 åã®èª¤å·®ï¼ã®ã§ãã¾ãåé¡ãªãã¨æãã¾ãã
ãããã¯ãååã»åæ¯ã 64-bit æ´æ°ã§ãªã¼ãã¼ããã¼ããã«è¨ç®ã§ããåæã§ããã°ãååã»åæ¯ã¯ long double
ãç¨ãã¦ã®è¨ç®ã§ catastrophic cancellation ã¯èµ·ããªã*9ã®ã§ãï¼double
ã§è½ã¡ãããã¨ãããã long double
ã«ãã¦ã¿ãã¨ããããããã¡ãªæªè¨¼æ解æ³ã¯ï¼æ£å½ãªè§£æ³ã«ãªãã¨æãã¾ãã
Rust ã Python ãªã©ã® long double
ãæ°è»½ã«ä½¿ããªãè¨èªã§ã¯ï¼BigRational
ã Decimal
ãªã©ãé©åã«ä½¿ãããï¼æ´æ°åãé©åã«ä½¿ãã³ã¼ããæ¸ãå¿
è¦ãããã§ãããã
use proconio::input;
fn main() {
input! {
(x0, y0, x1, y1): (i64, i64, i64, i64),
}
let res = (x0 * y1 - x1 * y0) as f64 / (x0 - x1) as f64;
println!("{res}");
}
åæ£ã®æ¹ã次ã®ããã«å¤å½¢ã§ãã¾ããååã»åæ¯ãæµ®åå°æ°ç¹æ°ã§è¨ç®ããå ´åã¯ãä¸æ¬¡é¢æ° (2) ã®ä¾ã¨åæ§ã«ãã¦æå¢ã§ããã¯ãã§ããç¹ã«è©¦ãã¦ã¯ãã¾ããã
$$
\begin{aligned}
\frac1n\sum_{i=1}^n a_i^2 - \left(\frac1n\sum_{i=1}^n a_i\right)^2
&= \frac1{n^2}\left(n\sum_{i=1}^n a_i^2 - \left(\sum_{i=1}^n a_i\right)^2\right)
\end{aligned}
$$
use proconio::input;
fn main() {
input! {
n: usize,
a: [i64; n],
}
let sum1: i64 = a.iter().sum();
let sum2: i64 = a.iter().map(|ai| ai * ai).sum();
let num = sum2 * n as i64 - sum1 * sum1;
let den = n as i64 * n as i64;
let res = num as f64 / den as f64;
println!("{res}");
}
å½ç¶ãååã®è¨ç®ã«ããã¦ãªã¼ãã¼ããã¼ããªããã¨ã¯ç¢ºèªãã¦ããã¾ãããã
$$
\begin{aligned}
n\sum_{i=1}^n a_i^2
&\le 15\cdot \sum_{i=1}^{15} {(10^8)^2} \\
&= 15\cdot 15\cdot (10^8)^2 \\
&= 225\cdot 10^{16} \\
&= 2.25\cdot 10^{18}\lt 2^{63}, \\
\left(\sum_{i=1}^n a_i\right)^2
&\le \left(\sum_{i=1}^{15} 10^8\right)^2 \\
&= (15\cdot 10^8)^2 \\
&= 2.25\cdot 10^{18}\lt 2^{63}.
\end{aligned}
$$
ååã»åæ¯ã®è¨ç®ã§ãªã¼ãã¼ããã¼ãèµ·ããå ´åã¯ã©ã対å¦ããã°ãããã§ãããã
å ´åã«ãã£ã¦ã¯ã$2^{64}$ï¼ããã㯠$2^{128}$ï¼ã§å²ã£ãã¨ãã®åã¨ãã¾ãã«åãããããªããè¨ç®ï¼ï¼ç°¡æçãªå¤åé·æ´æ°ã£ã½ãæãã§ï¼
ã¸ã£ãã¸
ä¸æ¬¡é¢æ°ã®ä¾ã¯ãABC 385 F ã§è©¦ãã¾ãã$N=2$ ã¨ãã¦èãã¦ãã¾ãã
WA ã«ãªã£ã¦ããæåºãé©å½ã«æ¼ã£ã¦ãhack ã®ç·´ç¿ããã¦ã¿ãã®ãããã§ãããã
ãã®åé¡ã®è¨å®ã«ããã¦ã¯ã$(x_0, y_0, x_1, y_1) = (175337, 3, 2x_0, 2y_0)$ ã¨ãããã¨ã§ã$-2^{-51} \lt 0$ ãªã©ãåºåããã¦æå¢ããããã¨ãã§ãã¾ãï¼long double
ã Decimal
ãªã©ã«ãæå¹ï¼ã
ç´¹ä»ããã±ã¼ã¹ãã¡
2
45 500000000
90 1000000000
2
29 500000000
58 1000000000
2
175337 3
350674 6
2
11 500000000
22 999999999
2
39 500000000
78 999999999
2
71458659 124836799
72151796 126047695
2
707085728 707127834
707085729 707127835
2
962214805 931734628
965940272 935342083
2
999999990 500000004
999999992 500000005
2
126047695 124836799
198199491 196295458
åæ£ã®ä¾ã¯ ABC 332 E ã§è©¦ãã¾ããç°¡åã®ããã« $N=D$ ã¨ãã¦ããã§ãããã
ãã¡ãã WA ã®æåºãã¡ã§éã¶ã¨ããããã§ãã
ç´¹ä»ããã±ã¼ã¹ãã¡
2 2
100000000 99999998
9 9
99999996 99999995 99999995 99999995 99999995 99999995 99999995 99999995 99999995
15 15
100000000 100000000 100000000 100000000 100000000 100000000 100000000 100000000 99999999 99999994 99999990 99999990 99999990 99999990 99999989
ãã WA ãããã£ãå¾ã®è©±ã¨ãã¦ãï¼èª¤å·®é¢é£ã«éããªãã§ãããï¼ãã®ã³ã¼ãã¯æµï¼ï¼ï¼ãæ¸ãããã®ã ã¨æãè¾¼ããã¨ã§ãæå°æªãªã±ã¼ã¹ãèãããããªãã¨ããã®ã¯ããã¨æã£ã¦ãã¾ãã
å³æ¹ï¼ï¼ï¼ãæ¸ããã¨æã£ã¦ãã©ããééã£ã¦ãªããããï¼ãã¨èªãããã¯ãããããã£ã¦ãééã£ã¦ãã ããè½ã¨ãã¦ããããè¦ã¦ãããããã®æ°æã¡ã®æ¹ãç©æ¥µçã«ãªããæ°ããã¾ãã
è½ã¨ãã¨ãã®å®çªã¨ãã¦ã¯ãcatastrophic cancellation ãèµ·ãããããããªå
¥åããããããããã¨ã«ãªãã¨æãã¾ãã
èµ·ããããã«ããã£ã¦ã¯ãè¨äºã§æãããããªã±ã¼ã¹ã®åå¨ãç¥ã£ã¦ããã¨ããããããã¼ã¹ã«ä¼¼ããããªãã¨ã§ãããããã¨ããããããããªãããªã¨ããæ°ããã¾ãã
ããããç·´ç¿ã¨ãã¦ãWA ã«ãªã£ã¦ããï¼å®éã®ä»äººã®ï¼ã³ã¼ããèªãã§å®éã«ã±ã¼ã¹ãæ§ç¯ããéã³ã¨ããã®ã¯æå¹ã ã¨æãã¾ãã
ææ
å
ã
ãABC 385 F ã®è§£èª¬ ã®ç¼ãç´ãç¨åº¦ã®è¨äºã«ãªãäºå®ã ã£ãã®ã§ãããæ¸ãã¦ããéä¸ã«è§£èª¬ã®è¨è¼ãã¹ã«æ°ã¥ãããã解説ã«æ¸ãã¦ãããã®ãã大ãã誤差ã®ã±ã¼ã¹ãæ§ç¯ã§ãããããã®ã§ãããæ°æã¡ã«ãªãã¾ããã
ä»ã«ããããã¡ãªç°¡åãªä¾é¡ãããã°è¿½è¨ãã¦ãããããªã¨æã£ã¦ãã¾ãã
ãããããè¨ç®æ¹æ³ã ã¨ããããã¨ãã«ãããªã«èª¤å·®ãåºã¾ãã^^ãã¨ç¥ã£ã¦ããã¨ããªãã¨ãªãåªè¶æããããã®ãçãã¾ãããã
ãæ°æã¡è¡¨æãã¼ã
ï¼ãããæ¬ç·¨ã ã¨æã£ã¦ãã人ããã¾ãããã¶ãï¼
ããããã以åã®ããè¿ã¥ãã«ãªããã人åãã®è¨äºããæ¸ããã¨ãã«ãæã£ããã¨ã§ãããæµ®åå°æ°ç¹åã¨ä»²ããã®äººãï¼ç«¶ããçéã«éããï¼å°ãªããã¨ããæ°æã¡ãããã¾ãã
ãããã§èª¿ã¹ã¦åºã¦ããè¨äºã®å¤§åã¯æªãããã¨ãæ¸ãã¦ãã¾ãããï¼æ°å¼ãç¨ãã¦ã®è§£æããªãã®ã¯å½ç¶ã¨ãã¦ï¼è§£å度ã®ä½ãèªç¶è¨èªã§ã®ãµãã£ã¨ãã話ãæ¸ããã¦ããã¡ã§ãã
ãããããæµ®åå°æ°ãã¨æ¸ãã¦ãã人ã®ç解度ã«æå¾
ããæ¹ãééã£ã¦ããã¨ããã®ã¯ããã ã¨æã£ã¦ãã¾ãã
æ¦ãä¸è¨ã®è¨äºã§ã«ãã¼ããããããªé¡ã®èª¤è§£ããã¦ããæ¹ãå¤ãããªã®ã§ãèªãã§ã»ããã§ãã
qiita.com
ããéãªã©ãå³å¯ããæ±ããããæèã§æµ®åå°æ°ç¹åãç¨ããã®ã¯ä¸é©åãã¨ããæ¨ã®ä¸»å¼µèªä½ã¯ç¹ã«åè«ã¯ãªãï¼ã¨ãããåæãã¾ãï¼ã®ã§ããããå¤ãã®ç¶æ³ã§æµ®åå°æ°ç¹åãé¿ããã¾ã¾çãã¦ãã¦ãã©ããã¦ãå¿
è¦ã«ãªã£ãæèã§æµ®åå°æ°ç¹åã使ããç¥èããªãããå¤ãªãã¹ããã¦å«ãªå°è±¡ãæ±ããã®ãããªçãæ¹ã®äººãå¤ãæ°ã¯ãã¦ãã¦ãããã¯å¥½ã¾ãããªãããªãã¨ããæ°æã¡ãããã¾ãã
競ããçéã®äººã
ãã誤差ã¯å¦ç²¾ãããæ°åã§æ··ãã¦ãããã®ã§ã人éã¯ã©ãããããã§ããªããã¿ãããªè§£å度ã®ä½ããªã®ããªï¼ã¨æã£ãããã¦ãã¾ãããå®éã©ããªãã§ãããããæè¿ã¯çéã®äººå£å¢å ã«ä¼´ã£ã¦ãæ°å¦ã«æãããªã人ãããããããæ°ã¯ãã¾ãããçéã§å¥½ã¾ããã¡ãªæ°å¦ã®åéï¼çµåãæ°å¦ã¨ãï¼ã¨ãéãæ°ããã¾ãããæ°å¼ã§æããé¨åããã°ãã°ããã®ã§ããã£ã¨ç解ããè¥äººãå¢ãã¦ãããããªãã¨ããæ°ã¯ãã¦ãã¾ãã
æ´æ°ã®è¨¼æåé¡ã«å¼·ã人ã¯æ´»èºã§ãããï¼ã¨ããæ°ããã¦ãã¾ãï¼ææ°é¨ãããããå¾ã¯æ´æ°æ§ã使ã£ã¦è°è«ããã¡ã ã£ãããã¾ããï¼ãæ´»èºããããã¯å¥ã®åé¡ããããã¾ããã
æ¨ä»ã®é¢¨æ½®çã«ã¯æ°ãä¸ãã¨ãæé©åã¨ãã人æ°ãã¡ã§ãå¹¾ä½ã¨ãã¯ä¸ç«ã ã£ãããããã§ãããï¼ æããã誤差ã絡ãã§ããã¸ã£ã³ã«ã¨è¨ãã°å¹¾ä½ãå¹¾ä½ã¨è¨ãã°åä»ãã¿ãããªé¢¨æ½®ã¯ãããã¡ãªæ°ã¯ãã¾ããèªåãæ¦ãããããæãã§ã¯ãã£ãã®ã§ãããåä½å¹´ãç¶ãã¦ããçéã§ãã£ã¨ããããå®æ
ãªã®ã¯å¾®å¦ãããªãï¼ã¨ããæ°æã¡ã¯ããã¾ãã
è»æ¬ã§ã誤差ã«é¢ããé¨åã¯ãã¾ã詳細ã«ã¯æ¸ããã¦ããªãã§ããããããã«ãã¾ã¨ããªææãã»ã¼ãªãã§ããããã¬ã¬ã¨ããæãã§ãã
ããããï¼ã¢ã«ãããã¯çéã§ï¼ï¼âgeometryâ ã¨å¼ã°ããåéã¯ãå½ç¶ã®ããã«å¹³è¡¡æ¨ã使ã£ã¦å¹³é¢èµ°æ»ãããã¨ããããã¡ã§ããã¾ã AtCoder ã®ææ³ã¨ã¯æ²¿ããªãé¨åãããããã§ãããã¾ãæµè¡ããªãã®ãç¡çã¯ãªãããªãã¨ããæ°æã¡ã¯ããã¾ãã
åæ°å¦é¢æ°ãæ£ç¢ºã«ä¸¸ãã (correctly-rounded) ãã®ãè¿ãã¦ãããã¢ã«ã´ãªãºã ãç¥ãããããªãã¨ããæ°æã¡ã¯ããã¤ã¤ãçéç®ç·ã§è¨ãã°ãããããªãã®ã欲ãããããã¾ãã¯ããããåºç¤çãªèª¤å·®ãåé¿ãããã¦ãã¦ãåºããæ¹ãå
ãªããããªãã®ãï¼ãã¨ããæ°æã¡ã«ããªã£ã¦ãã¾ãã
å¥ã«çéã¸ã®è²¢ç®ãæèããå¿
è¦ã¯ãªãã¦ãèªåã®èå³ãã¼ã¹ã§å¥½ããªãã¨ãå¦ã¹ã°ãããã¨ããã®ãåºæ¬ã¹ã¿ã³ã¹ã§ã¯ãããã§ãããï¼åé ã«æãããããªï¼ãã¤ã¼ããã¡ãè¦ãã¨ããããæ°åã«ããªãã¾ãããã
ãèªåã¯ããããèå¯ãï¼ç¡é精度ã®åæã§ï¼ãã¾ããããèªåã¯ããããå®è£
ãï¼ç²¾åº¦ãæ°ã«ããç´ æ´ã«ï¼ãã¾ãããã¨ããã¹ããããè¸ã¿ãã¡ã§ãããã®å®è£
ã ã¨ããããé¨åã§ãããããã®èª¤å·®ãåºããã¨ããã®ãæ°ã«ããå¿
è¦ãããã¨ããæã£ã¦ããªã人ãå¤ãã®ããªï¼ã¨æã£ãããã§ãã©ããã£ã¦æèãã¦ããã£ãããããã§ãããã¨æã£ããã§ãã
è¨ç®éã®æèã«é¢ãã¦ãããã§ãããããããããããæèããªãï¼æ°å¦ã«ãããã¾ã§æãããªãï¼ã¿ã¤ãã®åå¿è
ã«ãã£ã¦ãããã®ã£ã¦é£ãããããã¾ãããã
ãå²ãç®ã®åã«ã¯ 0 ã«ãªããªãããæèãããããã¤ã³ã¿ã使ãåã«ã¯ null ã§ãªããã¨ãæèãããã¨ããããããã®ã£ã¦ã©ããã¦è¦è½ã¨ããã¦ãã¾ãã®ã§ãããã
/
ãã¼ãæ¼ããã³ã«ãå¼æ°ãã§ãã¯ããï¼ãã¨ãããããã¢ãããåºã¦ãã¦ãåæãã¿ã³ãæ¼ããªãã¨é²ããªãã¿ããã«ããæ¹ãå®å
¨ãªããããªãã§ããï¼
ãå¤ãã®å ´åã¯åé¡ãªããããã¨ãã¯ããªã«ãæ°ã«ããªãã¦ããçç±ã«ã¯ãªããªãã¨æããã§ãããã
ã¨ãããç·ã¨ãã®äººã¨ã®é¢ãããæè¿ãã¾ããªããå®æ
ãããããããã®ã§å
¨ã¦ãæ³åã§è©±ãã¦ãããã§ããããæè¿ã®äººã
ã¯å®éã©ãããæããªãã§ããï¼
ã¨ã¯ããããæã®èªåãèªãããããããã£ãã ãããªãã¨ãããããªå
容ãåºãã¦ããã¤ããã§ã¯ããã¾ãããã¶ãæªæ¥ã®èªåãèªãã§ãããç¨åº¦ããããå
容ã«ãªã£ã¦ããæ°ã¯ãã¾ã*10ã
ãããããå®ã¯ç¥ããªãã¦ãã¿ãããªç³»çµ±ã®ãããã¯ã調ã¹ãªããä½çãéãããããªã¨ããæãã§ãã
ããã
ãããã§ãã