TOJ 3976.Change(dp或找规律)
来源:互联网 发布:windows bt删不干净 编辑:程序博客网 时间:2024/05/17 20:29
题目链接:http://acm.tju.edu.cn/toj/showp3976.html
Time Limit: 1.0 Seconds Memory Limit: 65536K
Total Runs: 530 Accepted Runs: 244
After Shawn sees the following picture, he decides to give up his career in IT and turn to sell fruits. Since Shawn is a lazy guy, he doesn’t like to do any extra work. When he starts selling fruits, he finds that he always needs to take changes for customers. He wants you to write a program to give the least number of changes. Shawn is also a strange guy, because he takes changes by 6,5,3,1.
Input
The first line of input is an integer T which indicates the sum of test case. Each of the following T lines contains an integer n(1≤n≤105), which is the total money Shawn need to give to the customer.
Output
For each test case, output "Case i: Result" in one line where i is the case number and Result is the least number of changes Shawn need to give customer.
Sample Input
341019
Sample output
Case 1: 2Case 2: 2Case 3: 4
Hint
Case 1: 4=3+1Case 2: 10=5+5Case 3: 19=6+6+6+1
Source: TJU Team Selection 2013
找零钱问题,本以为要用dp,但貌似找规律也是一个办法,不过规律不好找,1~6比较特殊单独考虑,随后从7开始进入规律的循环了,自己推一下:从7开始每6个是一个循环,也就是加了个6,知道这些写起来就非常简单了。
#include <stdio.h>int a[12]={1,2,1,2,1,1,2,2,2,2,2,2};int main(){int t,n,sum;scanf("%d",&t);for(int i=0;i<t;i++){scanf("%d",&n);sum=0;while(n>12){n-=6;sum++;}sum+=a[n-1];printf("Case %d: %d\n",i+1,sum); }}
- TOJ 3976.Change(dp或找规律)
- 找规律:String Change
- 历届试题 买不到的数目 (数论+找规律或DP)
- 【杭电oj】2277 - Change the ball(找规律)
- HDU 2277 Change the ball(找规律)
- hdoj 2277 Change the ball 【找规律】
- hdu 2277 Change the ball(找规律)
- hdoj 2277 Change the ball 【找规律】
- hdoj 2277 Change the ball 【找规律】
- TOJ3976 Change 完全背包 || 找规律
- HDU 4722 Good Numbers 数位dp或找规律枚举 数位dp感悟
- HDU 5366 The mook jong (排列组合 或 找规律)
- HDU 5969 最大的位或 (找规律)
- hdu 5969 最大的位或(找规律)
- hdu5389 Zero Escape(模拟+找规律+DP)
- RPG难题(找规律,也开看作DP)
- HDOJ1021(找规律)
- POJ1740(找规律)
- 针对于Velocity官方翻译简单了解Velocity
- 浅谈源码--“造轮子”与“拆轮子”之间的关系
- scrapy笔记(2) - 小试牛刀 (抓取豆瓣推理小说信息)
- AVL树的旋转
- Transfer data between Activitys
- TOJ 3976.Change(dp或找规律)
- android——活动的启动模式
- 领域驱动设计系列文章(2)——浅析VO、DTO、DO、PO的概念、区别和用处
- 对于application一点理解
- C++面试宝典2011
- HDU5794 A Simple Chess
- php组词算法
- 2016多校联赛7H (hdu5828) Rikka with Sequence
- bzoj 1997 Planar [并查集] [二分图判定] [2-SAT]