<每日一题> Day8:CodeForces-996A.Hit the Lottery(贪心)
因为数据太水,我直接一发暴力过了......
#include <cstdio> using namespace std; int value[5] = {100, 20, 10, 5, 1}; int main() { int n, ans = 0; scanf("%d", &n); while(n > 0) { for(int i = 0; i < 5; i ++) { if(n >= value[i]) { ans ++; n -= value[i]; break; } } } printf("%d\n", ans); return 0; }
#include <cstdio> using namespace std; int value[5] = {100, 20, 10, 5, 1}; int main() { int n, ans = 0; scanf("%d", &n); for(int i = 0; i < 5; i ++) { if(n >0) { ans += (n / value[i]); n = n % value[i]; } } printf("%d\n", ans); return 0; }
时间并不会因为你的迷茫和迟疑而停留,就在你看这篇文章的同时,不知道有多少人在冥思苦想,在为算法废寝忘食,不知道有多少人在狂热地拍着代码,不知道又有多少提交一遍又一遍地刷新着OJ的status页面……
没有谁生来就是神牛,而千里之行,始于足下!