随笔分类 -  ACM-HDU题集

摘要:产生冠军的条件:(1)获胜的人没输过一次(2)最终获胜的人只有一个View Code #include"iostream"//#include"algorithm"using namespace std;#define M 1010int main(){ int n; int i,j; char a[M][100],b[M][100]; int sum[M],c[M]; while(cin>>n,n) { memset(sum,0,sizeof(sum)); //0表示失败 for(i=0;i<n;i++) { cin>>a 阅读全文
posted @ 2011-04-07 09:34 聊聊IT那些事 阅读(648) 评论(0) 推荐(0)
摘要:借鉴了一位dn的,筛选法。求出每个数的因子和,然后看因子和是否在1000以内,是的话就证明等于因子和的这个数是不可摸数。http://acm.hdu.edu.cn/showproblem.php?pid=1999 阅读全文
posted @ 2011-04-06 21:13 聊聊IT那些事 阅读(309) 评论(0) 推荐(0)
摘要:注意精度进OKl了。。。。。http://acm.hdu.edu.cn/showproblem.php?pid=1036View Code #include"iostream"using namespace std;int main(){ int n; double s; int m; char ch[100]; int i,j,k; cin>>n>>s; while(cin>>m) { int mark=0; int sum=0; for(i=0;i<n;i++) { cin>>ch; if(ch[0]=='- 阅读全文
posted @ 2011-04-04 10:37 聊聊IT那些事 阅读(343) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1408精度问题View Code #include"iostream"using namespace std;int main(){ double v,d; while(cin>>v>>d) { int l=v/d; //l为所滴的滴数 if(l!=v/d) l++; //+1表示最后一滴小于d,也算成一滴 double sum=0; int t=0; //记录间隔数 int i=1; while(sum<l) //已有的滴数和总的滴数比较 { sum+=i; 阅读全文
posted @ 2011-04-04 08:53 聊聊IT那些事 阅读(326) 评论(0) 推荐(0)
摘要:这类问题一般都有固定的公式,告诉大家一个技巧:二维的一般是f(x)=a*x^2+b*x+c,三维的一般是f(x)=a*x^3+b*x^2+c*x+d. 用带定系数法求出各个系数就行了。http://acm.hdu.edu.cn/showproblem.php?pid=1290View Code #include"iostream"using namespace std;int main(){ int n; while(cin>>n) { cout<<(n*n*n+5*n+6)/6<<endl; } return 0;} 阅读全文
posted @ 2011-04-02 21:18 聊聊IT那些事 阅读(567) 评论(0) 推荐(0)
摘要::::---> a = b ^ c —-> c = a ^ b b = a ^ c,就是异或递推的关系。http://acm.hdu.edu.cn/showproblem.php?pid=1287View Code // a = b ^ c —-> c = a ^ b b = a ^ c#include"iostream"#include"math.h"using namespace std;int main(){ int n,i; int a[1000]; char ch; while(cin>>n) { for(i=0; 阅读全文
posted @ 2011-04-02 19:45 聊聊IT那些事 阅读(228) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1065错了n次了,让所有的水题汗颜啊!View Code #include"iostream"using namespace std;#define pi 3.1415926//3.1415927(wrong)int main(){ int n; double a,b,sum; cin>>n; int i=0; while(n--) { cin>>a>>b; sum=pi*(a*a+b*b)/2; int x=(int)(sum/50)+1; //(in 阅读全文
posted @ 2011-04-02 17:49 聊聊IT那些事 阅读(396) 评论(0) 推荐(0)
摘要:m与n互质即可:http://acm.hdu.edu.cn/showproblem.php?pid=1222 阅读全文
posted @ 2011-04-01 21:38 聊聊IT那些事 阅读(214) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=2707View Code #include"iostream"#include"math.h"using namespace std;int main(){ char ch[101]; int a[1000]; int b[100]; int i,j; while(1) { int s=0; while(gets(ch)) { if(strcmp(ch,"*")==0) break; if(strcmp(ch,"#")==0) b 阅读全文
posted @ 2011-04-01 20:32 聊聊IT那些事 阅读(296) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1032View Code #include"iostream"using namespace std;int i,j,Max=0;int fun(int x,int y){ for(i=x; i<=y; i++) { int count=1; int xx=i; while(xx!=1) { if(xx%2!=0) xx=3*xx+1; else xx=xx/2; count++; } if(count>Max) Max=count; } return Max;}int mai 阅读全文
posted @ 2011-03-31 17:44 聊聊IT那些事 阅读(330) 评论(0) 推荐(0)
摘要:View Code //按矩阵对角线输出问题#include"iostream"#define M 50using namespace std;int main(){ int n,i,j; int a[M][M]; while(cin>>n) { for(i=0;i<n;i++) { for(j=0;j<n;j++) cin>>a[i][j]; } int k=0; for( k=1; k<=2*n-1;k++) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(i+j==k-1)// 阅读全文
posted @ 2011-03-28 21:25 聊聊IT那些事 阅读(391) 评论(0) 推荐(0)
摘要:View Code #include"iostream"using namespace std;int main(){ int n,i,j; int b[720][720]; while(cin>>n) { memset(b,0,sizeof(b)); if(n==1) cout<<n<<endl; else { i=1,j=1; int k=1; for(int t=1; t<n ; t++) { while(j<=n-i+1&&j>=i) //横行->rigth { b[i][j]=k++; i 阅读全文
posted @ 2011-03-27 11:49 聊聊IT那些事 阅读(291) 评论(0) 推荐(0)
摘要:View Code #include"iostream"using namespace std;int main(){ int n; char ch[1000]; int i; scanf("%d\n",&n); // cin>>n;cout<<endl; while(n--) { gets(ch); int count=0; if(!(ch[0]>='a'&&ch[0]<='z')&&ch[0]!='_'&&!(c 阅读全文
posted @ 2011-03-26 20:51 聊聊IT那些事 阅读(804) 评论(0) 推荐(0)
摘要:很繁琐,花了将近两个小时。。。。。。。View Code #include"iostream"using namespace std;int main(){ char a[100]; int i,j,L; while(scanf("%s",a)!=EOF) { L=strlen(a); int num=0,zf=0,sign=0; for(i=0;i<L;i++) { if(a[i]>='0'&&a[i]<='9') { num=1;} if(a[i]>='A'&am 阅读全文
posted @ 2011-03-26 10:44 聊聊IT那些事 阅读(379) 评论(0) 推荐(0)
摘要:素数的测试: 费尔马小定理:如果p是一个素数,且0<a<p,则a^(p-1)%p=1. 利用费尔马小定理,对于给定的整数n,可以设计素数判定算法,通过 计算d=a^(n-1)%n来判断n的素性,当d!=1时,n肯定不是素数,当d=1时,n很可能是素数. 二次探测定理:如果n是一个素数,且0<x<p,则方程x^2%p=1的解为:x=1或 x=p-1. 利用二次探测定理,可以再利用费尔马小定理计算a^(n-1)%n的过程 中增加对整数n的二次探测,一旦发现违背二次探测条件,即得出n不是素数的结论. 如果n是素数,则(n-1)必是偶数,因此可令(n-1)=m*(2^q),其中 阅读全文
posted @ 2011-03-14 20:42 聊聊IT那些事 阅读(882) 评论(0) 推荐(0)
摘要:刚参加完HDUContest Ranklist,前所未有的纠结,也是前所未有的尝到了“不是努力的不够,而上效率的滞后”,一直在努力,一直期盼着能小试牛刀,一展身手。可谁想第一道题就给泼了冷水,貌似简单的面罩下隐藏着捉摸不透的不确定性因素,使劲浑身解数,最终以提交n次超时而结束,就这样抱着试试的心态开始看艰难的第二题。一看,简单! 当带着激动的心情迅速地拿出方案并顺利地写完后,这下总该给个a鼓励鼓励了吧,感觉是标准答案了,一提交,w; 后来改了数遍,也没想明白究竟是哪儿出了错,就在最后的十几分钟突然灵感一闪,原来错的很深啊,这也是这道题的关键所在,又是算法,又是效率。。。看来需要改进的地方还很. 阅读全文
posted @ 2011-03-13 16:43 聊聊IT那些事 阅读(370) 评论(0) 推荐(0)
摘要:View Code //超时了,艾~ 1 #include"iostream" 2 using namespace std; 3 char a[100005],b[100005]; 4 int i,j,k; 5 int L1,L2; 6 int sign=0; 7 int mark=0; 8 int start=0,end=0; 9 void Xun_huan() //实现一次循环10 {11 char ch=a[0];12 for(int q=0;q<=L1-1;q++)13 {14 a[q]=a[q+1];15 }16 a[L1-1]=ch;17 sign++; 阅读全文
posted @ 2011-03-13 08:05 聊聊IT那些事 阅读(535) 评论(0) 推荐(0)
摘要:转: 为了把0去掉,我们把所有的因数2和5都提出来,放到最后再处理。N!中的N个相乘的数可以分成两堆:奇数和偶数。偶数相乘可以写成(2^M)*(M!),M=N DIV 2。M!可以递归处理,因此现在只需讨论奇数相乘。考虑1*3*5*7*9*11*13*15*17*...*N(如果N为偶数则是N-1),这里面是5的倍数的有5,15,25,35,...,可以其中的5提出来,变成(5^P)*(1*3*5*7*9* ...),后面括号中共P项,P=(N DIV 5+1) DIV 2,而后面的括号又可以继续提5出来,递归处理.现在剩下的数是1*3*7*9*11*13*17*19*....这些数我们只需要 阅读全文
posted @ 2011-03-12 17:09 聊聊IT那些事 阅读(1869) 评论(0) 推荐(0)
摘要:hduacm2044hduacm2045hduacm2046hduacm2050 阅读全文
posted @ 2010-10-05 18:25 聊聊IT那些事 阅读(323) 评论(0) 推荐(0)