EXTRA 方程求解

Luogu
IDLGB3641
Time1000ms
Memory128MB
DifficultyP3
数学枚举
给定二元一次方程组,要求解出 $x, y$. 方程以 `ax+by=c` 的形式提供。其中 $a, b, c$ 都是整数,可能为负数。方程的解也一定为整数。 下面举一个例子。对于方程组 ```plaintext -2x+3y=4 x-y=-1 ``` 您应该解出 $x=1, y=2$。 ## Input 两行,表示两个方程。 每个方程可能是这样的形式: - `ax+by=c` - `ax-by=c` - `-ax+by=c` - `-ax-by=c` 其中,`c` 可能是正数、负数或 0。可能出现形如 `x` 或 `-x` 的项。 ## Output 两行,两个整数,分别表示 $x, y$。 [samples] ## Background 本题是**附加题**,供有兴趣的同学挑战。 **请尽量在 40min 之内写完题目。这是指「写代码」的时间;「读题」时间不计算在内。** ## Note **数据规模与约定** 对于 $100\%$ 的数据,系数的绝对值不超过 $100$,$x, y$ 的绝对值不超过 $100$。保证方程有唯一解。 **提示** 分类讨论越复杂,程序出 bug 的可能性越大。
Samples
Input #1
-2x+3y=4
x-y=-1
Output #1
1
2
Input #2
3x-5y=-21
-5x+20y=70
Output #2
-2
3
Input #3
6x+7y=30
-x-y=-5
Output #3
5
0
API Response (JSON)
{
  "problem": {
    "name": "EXTRA 方程求解",
    "description": {
      "content": "给定二元一次方程组,要求解出 $x, y$. 方程以 `ax+by=c` 的形式提供。其中 $a, b, c$ 都是整数,可能为负数。方程的解也一定为整数。 下面举一个例子。对于方程组 ```plaintext -2x+3y=4 x-y=-1 ``` 您应该解出 $x=1, y=2$。",
      "description_type": "Markdown"
    },
    "platform": "Luogu",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 131072
    },
    "difficulty": {
      "LuoguStyle": "P3"
    },
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "LGB3641"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "给定二元一次方程组,要求解出 $x, y$.\n\n方程以 `ax+by=c` 的形式提供。其中 $a, b, c$ 都是整数,可能为负数。方程的解也一定为整数。\n\n下面举一个例子。对于方程组\n```plaintext\n-2x+3y=4\nx-y=-1\n```\n\n您应该解出 $x=1, y=2$。\n\n## Input\n\n两行,表示两个方程。\n\n每个方程可能是这样的形式:\n\n- `ax+by=c`\n- `...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments