{"id":98,"date":"2024-04-26T10:21:30","date_gmt":"2024-04-26T02:21:30","guid":{"rendered":"https:\/\/seanxd.com\/?p=98"},"modified":"2024-04-26T10:21:32","modified_gmt":"2024-04-26T02:21:32","slug":"zerojudge-a410","status":"publish","type":"post","link":"https:\/\/seanxd.com\/en\/zerojudge-a410\/","title":{"rendered":"ZeroJudge A410: Solving Equations"},"content":{"rendered":"<p class=\"translation-block\">The students are currently learning systems of linear equations in two variables. Practice problems for these equations are flooding the students, and they are troubled by the repeated addition, subtraction, transposition, combining like terms, and so on. They know you are very smart and want to ask you to write a program to solve systems of linear equations in two variables for them. We assume the general format of the system of linear equations is as follows (where a, b, c, d, e, f are constants, and x, y are the unknowns):\n\nax+by=c\ndx+ey=f\n\nThe program reads in a, b, c, d, e, and f, then outputs the solution. Of course, the system of equations may have no solution or infinitely many solutions. If there is no corresponding real number pair (x, y) that satisfies the system of equations, then there is no solution. Conversely, if there are multiple real number pairs (x, y) that satisfy the system of equations, then there are infinitely many solutions. If there is no solution, output \"No answer\"; if there are infinitely many solutions, output \"Too many.\"<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Sample Inputs\/Outputs<\/h2>\n\n\n\n<figure class=\"wp-block-table nfd-wb-animate nfd-wb-fade-in-bottom-short\"><table class=\"has-fixed-layout\"><thead><tr><th>Sample Input(s)<\/th><th>Sample Output(s)<\/th><\/tr><\/thead><tbody><tr><td>The input consists of a single line containing six integers (a, b, c, d, e, f). The input data is guaranteed to be correct.<\/td><td class=\"translation-block\">If there is a solution, then output on the first line \"x=\" followed by the value of x, and on the second line \"y=\" followed by the value of y, both rounded to 2 decimal places. Please refer to the sample output. If there is no solution or infinitely many solutions, output \"No answer\" or \"Too many\" as required.<\/td><\/tr><tr><td>1  1  2  1  -1  0<\/td><td>x=1.00<br>y=1.00<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Thought Process<\/h2>\n\n\n\n<p class=\"\">You can use the formulas from the sample code to solve this equation. For the output part, you can use printf(\"%.2f) to only output two decimal places.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sample Code\uff0d<a href=\"https:\/\/zerojudge.tw\/ShowProblem?problemid=a410\" target=\"_blank\" rel=\"noreferrer noopener\">ZeroJudge A410: Solving Equations<\/a><\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-cpp\" data-lang=\"C++\"><code>#include &lt;iostream&gt;\n#include &lt;stdio.h&gt;\nusing namespace std;\n\nint main() {\n  int a1, b1, c1, a2, b2, c2;\n  scanf(&quot;%d%d%d%d%d%d&quot;, &a1, &b1, &c1, &a2, &b2, &c2);\n  int deltax1,deltax2,delta;\n  float x1, x2;\n  deltax1=c1*b2-b1*c2;\n  deltax2=a1*c2-c1*a2;\n  delta=a1*b2-a2*b1;\n  if(delta != 0)\n  {\n    x1=(float)deltax1\/delta;\n    x2=(float)deltax2\/delta;\n    printf(&quot;x=%.2f\\n&quot;, x1);\n    printf(&quot;y=%.2f\\n&quot;, x2);\n  }\n  else\n  {\n    if(deltax1==0 && deltax2==0)\n        cout&lt;&lt;&quot;Too many&quot;&lt;&lt;endl;\n    else\n        cout&lt;&lt;&quot;No answer&quot;&lt;&lt;endl;\n  }\n}\n\n\/\/ZeroJudge A410\n\/\/Dr. SeanXD<\/code><\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>\u8a71\u8aaa\u540c\u5b78\u5011\u6b63\u5728\u5b78\u7fd2\u4e8c\u5143\u4e00\u6b21\u65b9\u7a0b\u7d44\u3002\u4e8c\u5143\u4e00\u6b21\u65b9\u7a0b\u7d44\u7684\u7df4\u7fd2\u984c\u92ea\u5929\u84cb\u5730\u5730\u6e67\u5411\u540c\u5b78\u5011\uff0c\u540c\u5b78\u5011\u6b63\u82e6\u60f1\u65bc\u4e00\u6b21\u6b21\u5730\u56db\u5247\u904b\u7b97\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[6],"tags":[8,13,7],"class_list":["post-98","post","type-post","status-publish","format-standard","hentry","category-6","tag-8","tag-13","tag-7"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/98","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/comments?post=98"}],"version-history":[{"count":1,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/98\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/posts\/98\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/media?parent=98"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/categories?post=98"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/seanxd.com\/en\/wp-json\/wp\/v2\/tags?post=98"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}