HDU 2186 取整小技巧

来源:互联网 发布:js中获取元素的方法 编辑:程序博客网 时间:2024/05/22 04:44

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

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

代码:

#include<iostream>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;}}


0 0
原创粉丝点击