# Input

1 <= n <= 100

1 <= b, a <= 100 且a,b都是整数

3
1 3
2 4
5 7

menhera
1 + 3 = 4
2 + 4 = 6
5 + 7 = 12
Hint

# 思路

AC代码

#include <bits/stdc++.h>
using namespace std;
int p[111][11111];  //存答案
bool used[11111];  //标记是否使用
int book[11111];
int x[111], y[111];
bool dfs(int k)
{
int i;
for(i = 1; i <= 10100; i++)
{
if(p[k][i]&&!used[i])
{
used[i] = 1;
if(book[i] == 0||dfs(book[i]))
{
book[i] = k;
//book[k] = i;
return true;
}
}
}
return false;
}

int main()
{
memset(p, 0, sizeof(p));
memset(book, 0, sizeof(book));
int a, b, c, d;
int i, j, n;
scanf("%d", &n);
for(i = 1; i <= n; i++){
scanf("%d %d", &x[i], &y[i]);
a = x[i] + y[i];  //将+ - * /四种运算的结果保存
b = x[i] - y[i];
c = x[i] * y[i];
d = x[i] / y[i];
p[i][a+100] = 1;  //因为可能运算结果可能有负数，所以统一结果+100
p[i][b+100] = 1;
p[i][c+100] = 1;
p[i][d+100] = 1;
}
int sum = 0;
for(i = 1; i <= n; i++)
{
memset(used, 0, sizeof(used));
if(dfs(i))
sum++;
}
if(sum == n)
{
printf("menhera\n");
for(i = 1; i <= n; i++)
{
for(j = 1; j <= 10100; j++)
{
if(book[j] == i)
{
if(x[i]+y[i]==j-100)
printf("%d + %d = %d\n", x[i], y[i], j-100);
else if(x[i]-y[i]==j-100)
printf("%d - %d = %d\n", x[i], y[i], j-100);
else if(x[i]*y[i]==j-100)
printf("%d * %d = %d\n", x[i], y[i], j-100);
else
printf("%d / %d = %d\n", x[i], y[i], j-100);
break;
}
}
}
}
else
printf("QAQ\n");
return 0;
}