由于题目告诉肯定至少存在一种解,
故只需要根据条件遍历一下,
vector <int> makeExpression(int y) { vector<int> res; for(int i = -1000; i <=1000; ++ i){ for(int j = -1000; j <= 1000; ++ j){ if(i!=0 && i!=1 && j!=0&& j!=1 ){ int k = y-i*j; if(k>=-1000 && k<=1000 && k!=0 && k!=1){ res.push_back(i); res.push_back(j); res.push_back(k); return res; } } } } return res; }
topcoder SRM 625 DIV2 AddMultiply,布布扣,bubuko.com
topcoder SRM 625 DIV2 AddMultiply
原文地址:http://www.cnblogs.com/xiongqiangcs/p/3797992.html