恒邪

2014年3月25日 #

[ACM] hdu 1398 Square Coins (母函数)

摘要: Square CoinsTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7452Accepted Submission(s): 5050Problem DescriptionPeople in Silverland use square coins. Not only they have square shapes but also their values are square numbers. Coins with values of al 阅读全文

posted @ 2014-03-25 20:55 恒邪 阅读(147) 评论(0) 推荐(0) 编辑

[ACM] hdu 1028 Ignatius and the Princess III (母函数)

摘要: Ignatius and the Princess IIITime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11475Accepted Submission(s): 8118Problem Description"Well, it seems the first problem is too easy. I will let you know how foolish you are later." feng5166 says. 阅读全文

posted @ 2014-03-25 20:29 恒邪 阅读(148) 评论(0) 推荐(0) 编辑

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

摘要: #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 恒邪 阅读(2066) 评论(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 恒邪 阅读(289) 评论(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) 编辑

导航