[BestCoder] Round #7
来源:互联网 发布:外国对三体的评价知乎 编辑:程序博客网 时间:2024/06/06 17:08
1001
http://acm.hdu.edu.cn/showproblem.php?pid=4985
输出循环节
#include <iostream>#include <stdio.h>#include <algorithm>#include <string.h>#include <stdlib.h>#include <cmath>#include <iomanip>#include <vector>#include <set>#include <map>#include <stack>#include <queue>#include <cctype>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;int dx[8]={0,0,-1,1,1,1,-1,-1};int dy[8]={1,-1,0,0,-1,1,-1,1};const int maxn=1e5+2;bool vis[maxn];int p[maxn];int n;int main(){ while(rd(n)!=EOF) { for(int i=1;i<=n;i++) rd(p[i]); memset(vis,0,sizeof(vis)); int position; bool first; for(int i=1;i<=n;i++) { position=i; first=1; while(!vis[position]) { vis[position]=1; if(first) { cout<<"("<<position; first=0; } else cout<<" "<<position; position=p[position]; if(vis[position]) cout<<")"; } } cout<<endl; } return 0;}
1002
http://acm.hdu.edu.cn/showproblem.php?pid=4986
题意为在n个盒子里随机放着一个钥匙,且该钥匙和某一个盒子相对应,用1个魔法可以打开一个盒子,问把这些盒子全部打开,使用魔法个数的期望.
设p[i]为打开i个盒子的期望,那么另外一个盒要么是单独的一个循环节,那么插入到前面中去。p[i]= (p[i-1]+1)/i + p[i-1] *(i-1)/i 得p[i]=p[i-1]+ 1/i
也就是p[n]=1+ 1/2 +1/3 + .....1/n
这个数组是发散的,所以没有求和公式,只有一个近似的求解方法:
1+1/2+1/3+......+1/n ≈ lnn+C(C=0.57722......一个无理数,称作欧拉初始,专为调和级数所用)当n很大时,有:1+1/2+1/3+1/4+1/5+1/6+...1/n = 0.57721566490153286060651209 + ln(n)//C++里面用log(n),pascal里面用ln(n)
0.57721566490153286060651209叫做欧拉常数
#include <iostream>#include <stdio.h>#include <cmath>#include <map>#include <stack>#include <queue>#include <cctype>#define rd(x) scanf("%d",&x)#define rd2(x,y) scanf("%d%d",&x,&y)#define rd3(x,y,z) scanf("%d%d%d",&x,&y,&z)using namespace std;typedef long long ll;const int inf=0x3f3f3f3f;const double C=0.57721566490153286060651209;//欧拉常数const int maxn=100000;double p[maxn];int n;void init(){ p[0]=0; for(int i=1;i<=maxn;i++) p[i]=p[i-1]+(1.0/i);}int main(){ init(); while(rd(n)!=EOF) { if(n<=maxn) printf("%.4lf\n",p[n]); else printf("%.4lf\n",log(n)+C); } return 0;}
0 0
- [BestCoder] Round #7
- BestCoder Round #7-A,B,C
- BestCoder Round #3 BestCoder Sequence
- bestcoder round #1
- BestCoder round #1
- BestCoder Round #1
- 【索引】BestCoder Round #2
- BestCoder Round #2
- 【索引】BestCoder Round #3
- BestCoder Round #3
- BestCoder Round #3 小记
- BestCoder Round #4 题解
- BestCoder Round #6
- BestCoder Round #8
- Bestcoder Round #9
- BestCoder Round #9
- BestCoder Round #13(前两题)
- BestCoder Round #14
- 信号机制
- Hive优化
- 利用AC自动机进行关键字的提取和过滤
- 报表打印错误:Forcing NLS_NUMERIC_CHARACTERS to: '.,' for XDO processing
- 归并排序的理解记录
- [BestCoder] Round #7
- 聊聊C语言中的位段(位域)
- Java应用监控工具-JavaMelody
- vmware redhat linux安装遇到的问题
- java基础:Object 的toString方法
- Mysql笔记
- Spring data jpa sort多属性排序问题
- 【leetcode Java】Majority Element
- C#+Devexpress 切换皮肤教程