HDU 2186 取整小技巧

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2186

题解:(x+9)/10  就可以轻松应对不足10个加1了

代码:

#include
using namespace std;
int main() {
	int num;
	cin >> num;
	while (num--) {
		int n, sum = 0,temp1,temp2,temp3;
		cin >> n;
		temp1 = n / 2;
		sum += (temp1 + 9) / 10;///巧妙的做法!!!!!
		temp2 = n - temp1;
		temp2 = temp2 * 2 / 3;
		sum += (temp2 + 9) / 10;
		temp3 = n - temp1 - temp2;
		sum += (temp3 + 9) / 10;
		cout << sum << endl;
	}
}


你可能感兴趣的:(HDU)