![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
oj
CqZtw
coder!
展开
-
hdoj1051 Wooden Sticks(贪心算法+1,排序)
思路:典型的贪心算法思想,先求局部最优解,把问题划分为一个个子问题。我先从第一根木棍开始,从头到尾遍历,求出一个满足题意的序列,并且用flag[i]数组记录第i根木棍是否已经被加入序列。加入序列的flag[i]=1,没有加入的flag[i]=0.筛选完成后,再从头找第一个flag[]=0的木棍,又从这个木棍开始筛选出一个序列。按照这个步骤,直到flag[]数组所有值都为1。原创 2017-06-02 16:26:08 · 413 阅读 · 0 评论 -
hdoj1070 Milk(简单题)
来源http://acm.hdu.edu.cn/showproblem.php?pid=1070关键是牛奶最多就喝5天,坑得我不要不要的!!比较的数值是每天花费的钱:总花费/可以喝多少天#include#include #include #includeusing namespace std;struct milk{ char band[25]; double riot原创 2017-06-08 13:16:14 · 304 阅读 · 0 评论 -
hdoj1071 The area(数学题,积分)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1071y=ax*x+bx+c。给了你三个点,其中一个还是顶点,可以根据顶点和其他两点中的一点求出a,b,c的值。在根据列出的积分式代入求解。#include#include #include #includeusing namespace std;int main(){ int t原创 2017-06-08 15:48:29 · 378 阅读 · 0 评论 -
hdoj1002 A + B Problem II(简单的大数处理)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1002用字符串的形式输入输出,先倒置字符串使每位能够对应相加,大于‘9’的那位需要进行进位处理代码如下:#include#include#includeusing namespace std;char c[1005],a[1001],b[1001];void change(char c原创 2017-06-20 16:53:03 · 506 阅读 · 0 评论 -
hdoj1072 Nightmare(bfs寻找最短时间)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1072创建了一个点的结构体point用来存储当前坐标和剩余时间及已花费的时间。很重要的一点就是你得存储到每个点时剩余的时间,这个值由上一个点及自己当前的值确定。开始没有ac的原因是在经过值为4的点后没有将4变为1,从而陷入死循环,以后要特别注意!代码如下:#include#include原创 2017-06-08 21:21:08 · 500 阅读 · 0 评论 -
hdoj1073 Online Judge(对字符串的操作问题)
来源http://acm.hdu.edu.cn/showproblem.php?pid=1073模拟简单的oj系统,考察对字符串的操作,关键在于如何成功的把数据都存入字符串。代码如下:#include#include #include#include using namespace std;string change(string a)//剔除' ','\t','\n' {原创 2017-06-09 10:36:48 · 389 阅读 · 0 评论 -
hdoj1006 Tick and Tick(数学问题,解不等式,求并集)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1006看秒针的转动,一分钟一分钟的算#include#include#includeusing namespace std;struct range//取值范围 { double l,r;};double d;range work(double a,double b)//求 d<=原创 2017-06-21 11:10:27 · 593 阅读 · 0 评论 -
hdoj1008 Elevator(简单运用队列)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1008运用队列,先进先出。代码如下:#include#include#include#includeusing namespace std; int main() { int n,sum,i,j; queue q; while(scanf("%d",&n)&&n) {原创 2017-06-21 16:07:27 · 336 阅读 · 0 评论 -
hdoj1089~hdoj1096 A+B问题(输入输出的格式)
就是考察输入输出的格式:1089#includeint main(){ int a,b; while(~scanf("%d%d",&a,&b)) { printf("%d\n",a+b); } return 0;} 1090#includeint main(){ int a,b,t; scanf("%原创 2017-06-21 16:14:22 · 1030 阅读 · 0 评论 -
hdoj1097 A hard puzzle(简单题)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1097关键在于如何解决超时问题。我们首先取a的个位数,然后判断b是否大于10000,小于10000则直接循环计算。如果大于10000,我们算出b为10000时,a^b的个位数t1,然后进行对t1进行(b/10000)次循环,得到一个数再进行原创 2017-06-21 17:15:20 · 402 阅读 · 0 评论 -
hdoj1069 Monkey and Banana(DP)
dp[i]代表第i块砖头为顶时的最大高度。dp[i]=max{dp[j]+b[i].z,dp[i]}。因为一类砖头可以拿任意块,所以一类砖头最多可以有3种高度。最后目的是找到一个单挑递减的序列使得累起来的高度之和最大。代码如下:#include#include #include #includeusing namespace std;struct block{ i原创 2017-06-08 10:47:50 · 283 阅读 · 0 评论 -
hdoj1058 Humble Numbers(值得注意的简单题)
来源http://acm.hdu.edu.cn/showproblem.php?pid=1058题意很简单。需要注意的是筛选出平庸数的小技巧和输出时英文第11,12,13的不同表述方式。#includeint hn[5845];int min2(int a,int b){ return (a>b)?b:a;}int minn(int a,int b,int c,int d)原创 2017-06-04 11:21:45 · 439 阅读 · 0 评论 -
hdoj1057 A New Growth Industry(主要是理解题意)
来源http://acm.hdu.edu.cn/showproblem.php?pid=1057题意:有一个20X20的网格,每个网格里有个数字(0~3),每天网格里数字的变化是先将网格里本身的数字与其上下左右网格里数字依次相加,得到一个0~15的值k这个值确定了题目里数组d[k],接下来我们只需要把网格里的值与d[k]相加,如果相加后的值大于3,变化后的值就为3,小于0则就为0。最后再根原创 2017-06-04 10:06:24 · 924 阅读 · 0 评论 -
hdoj1021 Fibonacci Again
如果直接按照公式递归的求f(n),求不到那么大的数。题目要求是判断是否能被3整除,这种题目可以试试找找规律。列出前20个f(n),试试mod3求余数,发现余数以8为周期。分别为1 2 0 2 2 1 0 1。所以只需要先将输入的n对8求余,判断所得余数是否为2或者6。#includeusing namespace std;int main(){ int i; while(原创 2017-05-22 21:10:56 · 272 阅读 · 0 评论 -
hdoj1052 Tian Ji -- The Horse Racing(贪心算法+2)
田忌赛马,关键在于比较的次序。首先先比较两个人最慢的马,如果田忌的马快就直接赢下一分,count++如果慢的话就用这匹慢马去与大王最快的马比赛,count--如果相等的话,再比较两个人最快的马,如果田忌的马更快,count--反之就用田忌的慢马去消耗大王这匹快马,count--如果仍相等,最后用田忌最慢的马与大王最快的马比较,这时因为大王和田忌最快的马是一样快的,所以这时只原创 2017-06-02 19:13:24 · 1051 阅读 · 0 评论 -
hdoj1053 Entropy(哈夫曼编码)
EntropyTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6428 Accepted Submission(s): 2731Problem DescriptionAn entropy encoder is原创 2017-06-02 23:20:24 · 366 阅读 · 0 评论 -
hdoj1054 Strategic Game(二分图最大匹配求最小点覆盖)
Strategic GameTime Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8181 Accepted Submission(s): 3911Problem DescriptionBob enjoys pl原创 2017-06-03 11:27:57 · 355 阅读 · 0 评论 -
hdoj1067 Gap(bfs+hash)
看注释吧#include#include#include#include#include#includeusing namespace std;typedef struct loc{ int x,y;}loc;typedef struct map//图 { loc pos[48],gap[4];//各个值的坐标,空白处的坐标 string s;//序列顺序 i原创 2017-06-07 16:22:27 · 334 阅读 · 0 评论 -
hdoj1005 Number Sequence(找规律)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1005很明显找规律的题目,因为它给出的n太大,遍历的话一定会超时。代码如下:#include#include#includeusing namespace std;int t[90000001];int main(){ int a,b,n,i,cycle,j; while(~sc原创 2017-06-19 10:36:23 · 318 阅读 · 0 评论 -
hdoj1001 Sum Problem(细心点)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1001注意题目要求最后结果不能超过32位,所以我设的long long64位类型。代码如下#includeint main(){ long long n,sum; while(~scanf("%lld",&n)) { sum=(1+n)*n/2; printf("%lld\n\原创 2017-06-19 16:54:25 · 334 阅读 · 0 评论 -
hdoj1068 Girls and Boys(二分图+最大独立集)
来源http://acm.hdu.edu.cn/showproblem.php?pid=1068最大独立集=节点数-最大匹配集一开始用vector存储图,求其最大匹配数,一直wr,百思不得其解。后面改成用二维数组存储就能ac了,很奇怪。又有什么忽略的吗?#include#include #include #includeusing namespace std;int fl原创 2017-06-07 19:55:24 · 420 阅读 · 0 评论 -
hdoj 1056 HangOver(简单题)
一开始想复杂了。。。简单题。#includeusing namespace std;int dabiao(double b[]){ double a1; int i; i=2;a1=0;b[1]=0.5; while(a1<5.30) { b[i]=b[i-1]+1/(double)(i+1); a1=b[i];i++; } return i; }原创 2017-06-03 23:11:23 · 491 阅读 · 0 评论 -
hdoj1074 Doing Homework(好题呀,状态压缩+DP)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1074参考了网上的代码,然后自己又重新敲了一遍。需要用到状态压缩,压成二进制来表示不同的状态。有关状态压缩的讲解:http://www.cnblogs.com/avril/archive/2013/08/26/3282295.html几点要点:1.如果不用状态压缩,直接穷举,最多会有15!种原创 2017-06-09 18:24:58 · 387 阅读 · 0 评论 -
hdoj1098 Ignatius's puzzle(数论)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1098先给出费马小定理:假如a是整数,p是质数,且a,p互质(即两者只有一个公约数1),那么a的(p-1)次方除以p的余数恒等于1。题意:f(x)=5*x^13+13*x^5+k*a*x,给定k,求最小非负数a,对于任意整数x都满足f(x)|65.65=13*5,13和5都是质数,要使f(x)|原创 2017-06-22 10:30:54 · 327 阅读 · 0 评论 -
hdoj 1007 Quoit Design(分治法)
题意:给你n个点,让你求出n个点里距离最近的两点距离。思路:分治法先把点按照坐标y进行排序,划分为上下两部分,最近点对有三种情况,都在上半部分,都在下半部分,上下都有递归求出都在上边和都在下边的情况,选一个最小值m1。然后求出两边都有的情况。代码如下:#include#include#include#includeusing namespace std;struc原创 2017-07-04 10:59:16 · 585 阅读 · 0 评论 -
hdoj1108 最小公倍数(zz)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1108求最小公倍数#include#includeusing namespace std;int gcd(int a,int b){ int c; while(b) { c=a%b; a=b; b=c; } return a;}int main(){ int a原创 2017-06-25 16:20:17 · 439 阅读 · 0 评论 -
hdoj1084 What Is Your Grade?(思路很简单)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1084感觉我已经用stl走火入魔了,看到这道题需要分别对完成不同题数的学生进行排序,就又想用vector存储,v[i]的i表示的是做出题的题数。代码有点长和拖但很明了。注:对二维数组进行sort()函数排序,可以把数组首地址和末地址+1读入代码如下:#include#include#原创 2017-06-13 16:20:13 · 334 阅读 · 0 评论 -
hdoj1028 Ignatius and the Princess III(母函数,生成函数)
硬想了大半天还是不会。一开始想找规律看看有没有什么递推式,无果。。。后面在网上看代码,了解到有关母函数的问题。大神帅气闪闪的讲解入口http://blog.163.com/lyt9469@126/blog/static/17044235820108203120482/在这里列个本题解法和母函数的模板。#include int main() { int i,j,k原创 2017-05-26 20:51:19 · 538 阅读 · 0 评论 -
hdoj1100 Trees Made to Order(递归+卡特兰数,关于卡特兰数的讲解)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1100卡特兰数的讲解:http://www.cnblogs.com/code-painter/p/4417354.html设a[],a[i]表示i个节点能表示的二叉树数量设b[],b[i]表示节点数小于等于i时所能表示的所有二叉树数量,既b[i]=b[i-1]+a[i]有关二叉树数量计算原创 2017-06-26 11:33:12 · 573 阅读 · 0 评论 -
hdoj1085 Holding Bin-Laden Captive!(又见母函数)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1085关于母函数的讲解在之前hd1028中提到过。本题反过来求不能组成的最小值数,其实就是在求出c1[]后,找到第一个为0的下标。处理母函数的问题有一套模版,再贴一下有着详细讲解的链接:http://www.cnblogs.com/dolphin0520/archive/2012/11/07/2原创 2017-06-14 10:21:26 · 354 阅读 · 0 评论 -
hdoj1063&&poj1001 Exponentiation(大数据的处理,浮点数的幂高精确度表示)
很奇怪,我的代码在poj上能ac在hdoj上却ac不了,题目是完全一样的啊。。。蛋疼呀!(/ □ \)思路:这道题不难,但有几种情况要考虑。1.得到的数是整数,不需要输出小数点2.小数点前没有整数3.小数点前有整数我先把浮点数转化为整数,比如1.0100变为101,并记录小数点的位置,然后用处理大数相乘的方法,设一个数组a[],将个位的1存在a[0],十位的0存在a[1原创 2017-06-05 20:24:12 · 338 阅读 · 0 评论 -
hdoj1086 You can Solve a Geometry Problem too(数学几何题)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1086有两种思路1.求出某一直线的方程式,将另一线段两端点代入判断正负。2.叉乘的思想这里用的是叉乘的方法(写这个得细心些)代码如下#include#include#include #includeusing namespace std;#define Max 0x7fff原创 2017-06-14 16:17:26 · 350 阅读 · 0 评论 -
hdoj1087 Super Jumping! Jumping! Jumping!(简单的DP)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1087求最大递增字段和dp[i]=max{dp[j]}+a[i].-1a[j].代码如下:#include#include#include #includeusing namespace std;long long dp[1001],a[1001];int main(){ l原创 2017-06-14 17:22:45 · 375 阅读 · 0 评论 -
hdoj1083 Courses(二分图的最大匹配数)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1083题目很明显把点分为两类,一类课程,一类学生。让我们检验是否能选出一个完全符合条件的学生委员会:1.委员会的每个学生代表不同的课程(如果学生参加该课程,学生可以代表课程)2.每个课程都有委员会的代表二分图的最大匹配数呼之欲出,当匹配数等于课程数时满足条件注:这次用的是ve原创 2017-06-13 10:27:21 · 410 阅读 · 0 评论 -
hdoj1106 排序(简单的对字符串的处理)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1106用字符串存储输入的数据,然后将字符子串转化为整数。代码如下:#include#include#include#includeusing namespace std;int a[1000];int change(string str) { int l,i,j,sum; l=原创 2017-06-24 10:25:34 · 378 阅读 · 0 评论 -
hdoj1082 Matrix Chain Multiplication(栈的运用)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1082感觉自己做复杂了,还用了map。代码如下:#include#include#include#include #includeusing namespace std;struct matr{ int m,n;};map alp;int main(){ matr te原创 2017-06-12 19:21:32 · 301 阅读 · 0 评论 -
hdoj1075 What Are You Talking About(STL map处理字符串)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1075运用map处理问题具体见代码注释#include#include #include#include#include using namespace std;map m;string s;int search(string key) //用来判断map里是否存在key值 {原创 2017-06-10 11:11:32 · 291 阅读 · 0 评论 -
hdoj1076 An Easy Task(简单题)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1076简单的判断第n个闰年的年份。#includeusing namespace std;int main(){ int t,i,j; scanf("%d",&t); int y,n; while(t--) { scanf("%d%d",&y,&n); while(1)原创 2017-06-10 12:45:54 · 348 阅读 · 0 评论 -
hdoj1077 Catching Fish(几何题,枚举遍历)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1077可以由两个点确定两个圆心。圆心与两个点的距离为1,画图易知,圆心位于两点连线的中垂线上,本题的关键就在于求出圆心坐标。存在两种情况1.当两点的y值相等。2.当两点的y值不等。具体见代码:#include#include#include using namespace原创 2017-06-11 10:21:53 · 541 阅读 · 0 评论 -
hdoj1079 Calendar Game(分析奇偶,找规律,博弈)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=1079参考了别人的我们首先要认清的是,在这种博弈问题上,一开始处于优势的一方一定会努力保持自己的优势,而处于劣势的一方肯定在不断寻找翻盘点。这题没有很复杂的规则。最后日期是2001.11.4,设y表示年份,m表示月份,d表示天数。temp=m+d原创 2017-06-11 11:41:19 · 356 阅读 · 0 评论