恒邪

上一页 1 ··· 7 8 9 10 11 12 13 下一页

2014年3月25日 #

调用函数判断一个数是否为素数(传统+优化)

摘要: #include #include using namespace std;bool prime1(int n) //传统的判断素数。{ if(n==1) return 0; if(n==2) return 1; int t=(int)sqrt(n); for(int i=2;i>n) { if(prime1(n)) cout<<"prime1 : YES"<<endl; else cout<<"prime1 : No"<<endl; if(n%2==... 阅读全文

posted @ 2014-03-25 12:47 恒邪 阅读(2068) 评论(0) 推荐(0) 编辑

[ACM] TOJ 1054 Jesse's Code (素数判断优化+全排列)

摘要: DescriptionJesse是个数学迷,他最喜欢研究“哥德巴赫猜想”,因此他的计算机密码也都采用素数。但一直用同一个密码是不安全的,所以他要经常更换他的密码。但他只允许自己的密码中出现某些数字,且密码的每一位都不相同。比如1 2 4,则有6种情况124 142 214 241 412 421。其中241 和 421为素数。为了获得他的密码(他的机器上存放了第4届舜禹杯大学生程序设计竞赛的题目!),需要生成一个字典来帮助我们破解。请你来编写一个程序帮助我们(因为众所周知的原因我们迫切需要获得这些题目)。InputLine 1:密码的位数n (1 ≤ n ≤ 9)。 Line 2:1-> 阅读全文

posted @ 2014-03-25 12:33 恒邪 阅读(293) 评论(0) 推荐(0) 编辑

next_permutation(,)用法

摘要: 生成n个数的全排列。比如初始序列为 1 2 3 4 则下一个序列为 1 2 4 3 按序生成。#include #include #include using namespace std;int main(){ char a[3]={'a','b','c'};//第一个排列保证正序,有时候根据题目要求,需要对其进行排序处理。 for(int i=1;i<=6;i++)//i为总共排列的个数 ,及 3! { for(int j=0;j<3;j++) cout<<a[j]<<" "; cout& 阅读全文

posted @ 2014-03-25 12:23 恒邪 阅读(157) 评论(0) 推荐(0) 编辑

2014年3月24日 #

[ACM] hdu 2084 数塔 (简单DP)

摘要: Problem Description在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的:有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?已经告诉你了,这是个DP的题目,你能AC吗?Input输入数据首先包括一个整数C,表示测试实例的个数,每个测试实例的第一行是一个整数N(1 #include #include using namespace std;int dp[102][102];int num[102][102];int n;int main(){ int t;cin>>t; while(t--) { ... 阅读全文

posted @ 2014-03-24 21:30 恒邪 阅读(183) 评论(0) 推荐(0) 编辑

[ACM] hdu 1342 Lotto (排列)

摘要: LottoTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1360Accepted Submission(s): 679Problem DescriptionIn a Lotto I have ever played, one has to select 6 numbers from the set {1,2,...,49}. A popular strategy to play Lotto - although it doesn't 阅读全文

posted @ 2014-03-24 21:12 恒邪 阅读(242) 评论(0) 推荐(0) 编辑

[ACM] hdu 2068 RPG的错排 (逆向思考,错排*组合累加)

摘要: RPG的错排Time Limit: 1000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6528Accepted Submission(s): 2648Problem Description今年暑假杭电ACM集训队第一次组成女生队,其中有一队叫RPG,但做为集训队成员之一的野骆驼竟然不知道RPG三个人具体是谁谁。RPG给他机会让他猜猜,第一次猜:R是公主,P是草儿,G是月野兔;第二次猜:R是草儿,P是月野兔,G是公主;第三次猜:R是草儿,P是公主,G是月野兔;...... 阅读全文

posted @ 2014-03-24 19:32 恒邪 阅读(1144) 评论(0) 推荐(0) 编辑

[ACM] hdu 2048 神、上帝以及老天爷 (错位排列公式)

摘要: 神、上帝以及老天爷Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20118Accepted Submission(s): 8530Problem DescriptionHDU 2006'10 ACM contest的颁奖晚会隆重开始了!为了活跃气氛,组织者举行了一个别开生面、奖品丰厚的抽奖活动,这个活动的具体要求是这样的:首先,所有参加晚会的人员都将一张写有自己名字的字条放入抽奖箱中;然后,待所有字条加入完毕,每人从箱中取一个字条;最 阅读全文

posted @ 2014-03-24 18:21 恒邪 阅读(239) 评论(0) 推荐(0) 编辑

2014年3月20日 #

[ACM] hdu 1114 Piggy-Bank(完全背包)

摘要: Piggy-BankTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9921Accepted Submission(s): 4997Problem DescriptionBefore ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes f 阅读全文

posted @ 2014-03-20 17:45 恒邪 阅读(256) 评论(0) 推荐(0) 编辑

[ACM] hdu 2602 Bone Collector(01背包)

摘要: Bone CollectorTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 25042Accepted Submission(s): 10147Problem DescriptionMany years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such 阅读全文

posted @ 2014-03-20 17:30 恒邪 阅读(159) 评论(0) 推荐(0) 编辑

[ACM] hdu 1016 Prime Ring Problem (DFS)

摘要: Prime Ring ProblemTime Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 23268Accepted Submission(s): 10363Problem DescriptionA ring is compose of n circles as shown in diagram. Put natural number 1, 2, ..., n into each circle separately, and the sum of n 阅读全文

posted @ 2014-03-20 15:28 恒邪 阅读(125) 评论(0) 推荐(0) 编辑

上一页 1 ··· 7 8 9 10 11 12 13 下一页

导航