# BestCoder Round #7

Start Time : 2014-08-31 19:00:00    End Time : 2014-08-31 21:00:00
Contest Type : Register Public   Contest Status : Ended

Current Server Time : 2014-08-31 21:12:12

SolvedPro.IDTitleRatio(Accepted / Submitted)
1001 Little Pony and Permutation 37.91%(348/918)
1002 Little Pony and Alohomora Part I 29.86%(132/442)
1003 Little Pony and Dice 20.00%(8/40)
1004 Little Pony and Boast Busters 4.41%(3/68)

 hdu4985 Little Pony and Permutation 73.23%(93/127) hdu4986 Little Pony and Alohomora Part I 61.11%(88/144) hdu4987 Little Pony and Dice 23.53%(36/153) hdu4988 Little Pony and Boast Busters 80.00%(16/20)

1001（ hdu4985 Little Pony and Permutation ）：

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
2 #include<cstdio>
3 #include<cmath>
4 #include<iostream>
5 #include<cstring>
6 #include<algorithm>
7 #include<cmath>
8 #include<map>
9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) printf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 #define pb push_back
27 const int maxn=111111;
28 int n;
29 int a[maxn];
30 int b[maxn];
31 int main() {
32     int i,j;
33     while(scanf("%d",&n)!=EOF) {
34         FOR(i,1,n)scanf("%d",&a[i]);
35         mz(b);
36         FOR(i,1,n) {
37             if(!b[i]) {
38                 printf("(%d",i);
39                 j=a[i];
40                 while(j!=i) {
41                     printf(" %d",j);
42                     b[j]=1;
43                     j=a[j];
44                 }
45                 putchar(')');
46             }
47
48         }
49         puts("");
50     }
51     return 0;
52 }
View Code

(有人说用递归会爆栈，太萎了，看我的碉递归版：

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
2 #include<cstdio>
3 #include<cmath>
4 #include<iostream>
5 #include<cstring>
6 #include<algorithm>
7 #include<cmath>
8 #include<map>
9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) printf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 #define pb push_back
27 const int maxn=111111;
28 int n;
29 int a[maxn];
30 int b[maxn];
31 int i,j;
32
33 void dg(const int &x){
34     if(x==i)return;
35     printf(" %d",x);
36     b[x]=1;
37     dg(a[x]);
38 }
39
40 int main() {
41     while(scanf("%d",&n)!=EOF) {
42         FOR(i,1,n)scanf("%d",&a[i]);
43         mz(b);
44         FOR(i,1,n) {
45             if(!b[i]) {
46                 printf("(%d",i);
47                 dg(a[i]);
48                 putchar(')');
49             }
50
51         }
52         puts("");
53     }
54     return 0;
55 }
View Code

1002( hdu4986  Little Pony and Alohomora Part I)：

（其实这个约等于的和暴力算得的有好多数不一样，暴力算的因为精度有限也可能不对。如果要全部输出暴力的结果，可以分段打表，隔一段记一个数，输入n在两段之间时，从上一段记的那个数开始算）

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
2 #include<cstdio>
3 #include<cmath>
4 #include<iostream>
5 #include<cstring>
6 #include<algorithm>
7 #include<cmath>
8 #include<map>
9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) printf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 #define pb push_back
27
28 double farm(int n) {
29     double re=0.0;
30     for(int i=n; i>=1; i--) {
31         re+=1.0/i;
32     }
33     return re;
34 }
35
36 int main() {
37     int i,j;
38     int n;
39     while(scanf("%d",&n)!=EOF) {
40         if(n<=10000) {///8个0交C++能984ms过，4个0能过
41             double t=farm(n);
42             printf("%.4f\n",t);
43         } else
44             printf("%.4f\n",log((double)n)+0.5772156649);///实际上10035就不一样了，不过数据里没有
45         //getchar();
46     }
47     return 0;
48 }
View Code

1003( hdu4987 Little Pony and Dice )：

f[i]表示到第i个格子的概率，s[i]表示0~i的概率和。

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
2 #include<cstdio>
3 #include<cmath>
4 #include<iostream>
5 #include<cstring>
6 #include<algorithm>
7 #include<cmath>
8 #include<map>
9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) printf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 #define pb push_back
27 const int maxcul=1111111;
28 const int maxcnt=2000;
29 const double eps=1e-9;
30
31 double f[maxcul+10];
32 double s[maxcul+10];
33 double farm(int m,int n){
34     if(m>555555)return 0.0;/// m固定，当n=m时ans取最大值，m大于这个时最大值也是0
35     if (n<=m) return pow(1.0+1.0/m,n-1)/m;
36     ///  C(n-1,0)/m + C(n-1,1)/m/m + C(n-1,2)/m/m/m + ... + C(n-1,n-1)/(m^n)
37     ///=( C(n-1,0) + C(n-1,1)/m + C(n-1,2)/m/m + ... + C(n-1,n-1)/(m^(n-1)) )/m
38     ///=(1+1/m)^(n-1)/m
39     int i,j;
40     int cnt=1;
41     mz(f);
42     f[0]=1.0;
43     s[0]=1.0;
44     for(i=1;i<=n;i++){
45         int minj=max(0,i-m);
46         if(minj==0) f[i] = s[i-1]/m;
47         else f[i] = (s[i-1] - s[minj-1]) / m;
48         s[i]=f[i]+s[i-1];
49         if(i>m && fabs(f[i]-f[i-1])<eps)cnt++;
50             else cnt=1;
51         if(cnt>maxcnt)break;
52     }
53     if(cnt>maxcnt) return f[i];
54     else return f[n];
55 }
56
57 int main() {
58     int i,j;
59     int m,n;
60     while(scanf("%d%d",&m,&n)!=EOF){
61         printf("%.5f\n",farm(m,n));
62     }
63     return 0;
64 }
View Code

posted @ 2014-08-31 21:14  带鱼Yuiffy  阅读(238)  评论(0编辑  收藏  举报