题目:
Description
Input
Output
Sample Input
6 4815 2 1 5716 1 0 7842 1 0 4901 0 0 8585 3 3 8555 3 2 2 4815 0 0 2999 3 3 0
Sample Output
3585 Not sure
想不到什么好的方法了,只能对每一组a,b,c,扫描10000个数,把不满足条件的都删掉。
N行之后,看还有多少满足条件的。
代码:
#include<iostream> using namespace std; int list[10000]; int a, b, c, k; int na[4], nk[4]; void f(int i, int j) { if (na[i] != nk[j] || na[i] < 0 || nk[j] < 0)return; b--; na[i] = -1, nk[j] = -1; } bool ok() { na[0] = a / 1000, na[1] = a / 100 % 10, na[2] = a / 10 % 10, na[3] = a % 10; nk[0] = k / 1000, nk[1] = k / 100 % 10, nk[2] = k / 10 % 10, nk[3] = k % 10; for (int i = 0; i < 4; i++)if (na[i] == nk[i])c--; if (c)return false; for (int i = 0; i < 4; i++)for (int j = 0; j < 4; j++)f(i, j); if (b)return false; return true; } int main() { int n; while (cin >> n) { if (n == 0)break; for (int i = 0; i < 10000; i++)list[i] = 1; while (n--) { cin >> a >> b >> c; int bb = b, cc = c; for (int i = 0; i < 10000; i++) { k = i; if (!ok())list[i] = 0; b = bb, c = cc; } } int sum = 0; for (int i = 0; i < 10000; i++)sum += list[i]; if (sum != 1)cout << "Not sure" << endl; else for (int i = 0; i < 10000; i++)if (list[i])cout << i << endl; } return 0; }