直接暴力搜
/* ID: yingzho1 LANG: C++ TASK: ratios */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> #include <cstdio> #include <cstdlib> using namespace std; ifstream fin("ratios.in"); ofstream fout("ratios.out"); struct node { int x, y, z; node(int a, int b, int c) : x(a), y(b), z(c) { } node() : x(), y(), z() { } }; ; //int f[101][101][101]; int main() { node target, s[]; fin >> target.x >> target.y >> target.z; ; i < ; i++) fin >> s[i].x >> s[i].y >> s[i].z; /*for (int i = 0; i < 101; i++) for (int j = 0; j < 101; j++) for (int k = 0; k < 101; k++) f[i][j][k] = inf;*/ int minnum = inf; int recx, recy, recz; ; i < ; i++) { ; j < ; j++) { ; k < ; k++) { ].x+j*s[].x+k*s[].x; ].y+j*s[].y+k*s[].y; ].z+j*s[].z+k*s[].z; || xx%target.x == ) && (target.y == || yy%target.y == ) && (target.z == || zz%target.z == ) && xx*target.y == yy*target.x && yy*target.z == zz*target.y) { int tmp = inf; if (target.x && xx) tmp = xx/target.x; else if (target.y && yy) tmp = yy/target.y; else if (target.z && zz) tmp = zz/target.z; if (tmp < minnum) { minnum = tmp; recx = i, recy = j, recz = k; } } } } } if (minnum < inf) fout << recx << " " << recy << " " << recz << " " << minnum << endl; else fout << "NONE" << endl; ; }