上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 26 下一页
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1232基本和1856相同,就是最后需要判断一下。。。。。View Code int count=0;for(i=1;i<=n;i++) //其父结点为其本身即可{ if(FindFa(i)==i) count++;}cout<<count-1<<endl; 阅读全文
posted @ 2011-04-06 15:10 聊聊IT那些事 阅读(221) 评论(0) 推荐(0)
摘要: View Code #include<iostream>using namespace std;#define M 10000001int father[M];int _max;int sum[M];int FindFa( int a ){if( father[a] == a ){return a;}return father[a] = FindFa( father[a] ); }void UnionFa( int a , int b ) //将a,b合并{father[b] = a; //把a设为b的父结点sum[a] += sum[b]; //当有元素加入a中时,使其个数加su 阅读全文
posted @ 2011-04-06 15:07 聊聊IT那些事 阅读(214) 评论(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那些事 阅读(339) 评论(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那些事 阅读(322) 评论(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那些事 阅读(560) 评论(0) 推荐(0)
摘要: 刚开始用了几次gcd(),结果n次tle, 最后用了筛选法,终于a了,效率提高不少啊!http://acm.hdu.edu.cn/showproblem.php?pid=1286View Code #include"iostream"using namespace std;int main(){ int n,a,i,j,count; int b[32768]; cin>>n; while(n--) { cin>>a; memset(b,0,sizeof(b)); for(i=2;i<=a;i++) { if(a%i==0&&b[ 阅读全文
posted @ 2011-04-02 20:51 聊聊IT那些事 阅读(265) 评论(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那些事 阅读(221) 评论(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那些事 阅读(392) 评论(0) 推荐(0)
摘要: m与n互质即可:http://acm.hdu.edu.cn/showproblem.php?pid=1222 阅读全文
posted @ 2011-04-01 21:38 聊聊IT那些事 阅读(210) 评论(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那些事 阅读(294) 评论(0) 推荐(0)
上一页 1 ··· 13 14 15 16 17 18 19 20 21 ··· 26 下一页