BYRBT

Codeforces 336

A:

……

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<algorithm>
 5 
 6 using namespace std;
 7 
 8 int main()
 9 {
10     int x,y;
11     scanf("%d%d",&x,&y);
12     int x1,y1,x2,y2;
13     x1=0;y1=(abs(y)+abs(x))*(y>0 ? 1 : -1);
14     x2=(abs(x)+abs(y))*(x>0 ? 1 : -1);y2=0;
15     if (x1>x2) swap(x1,x2),swap(y1,y2);
16     printf("%d %d %d %d\n",x1,y1,x2,y2);
17 
18     return 0;
19 }
View Code

 

B:

问从下面的圆心走到上面的圆心的平均距离。

贪心走就行了,只需要注意横坐标差大于2时可以先斜着走完再横着走就行了。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 #include<cmath>
 5 
 6 using namespace std;
 7 
 8 int m,r;
 9 
10 #define solve(x) (x ? r+rx*(x-1)+(double)(x-1)*(x-1)*r : 0)
11 
12 int main()
13 {
14     scanf("%d%d",&m,&r);
15     double rx=sqrt(2.0)*r;
16     double ans=0;
17     for (int a=1;a<=m;a++)
18     {
19         ans+=r*m+r;
20         ans+=rx*(m-1);
21         ans+=solve(a-1)+solve(m-a);
22     }
23     printf("%.10lf\n",ans/m/m);
24 
25     return 0;
26 }
View Code

 

C:

找出一些数使得它们and起来的lowbit值最大。

枚举答案贪心选尽量多的数。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 const int maxn=100010;
 8 
 9 int n,z[maxn];
10 
11 int main()
12 {
13     scanf("%d",&n);
14     for (int a=1;a<=n;a++)
15         scanf("%d",&z[a]);
16     for (int a=31;a>=0;a--)
17     {
18         int v=-1;
19         int cnt=0;
20         for (int b=1;b<=n;b++)
21             if ((z[b]>>a)&1)
22             {
23                 cnt++;
24                 if (v==-1) v=z[b];
25                 else v&=z[b];
26             }
27         if (v!=-1 && !(v%(1<<a)))
28         {
29             printf("%d\n",cnt);
30             for (int b=1;b<=n;b++)
31                 if ((z[b]>>a)&1) printf("%d ",z[b]);
32             printf("\n");
33             return 0;
34         }
35     }
36     printf("-1\n");
37 
38     return 0;
39 }
View Code

 

D:

告诉你字符串中0和1的个数并告诉你最后通过替换得到的数问合法序列数。

因为1+?=0 00+?=0,所以一位一位的补齐就行了。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 #define inc(a,b) {a+=b;if (a>=mo) a-=mo;}
 8 
 9 const int maxn=200010;
10 const int mo=1000000007;
11 
12 int n,m,g,fac[maxn],inv[maxn];
13 
14 int mul(int a,int b)
15 {
16     int ans=1;
17     while (b)
18     {
19         if (b&1) ans=(long long)ans*a%mo;
20         a=(long long)a*a%mo;
21         b>>=1;
22     }
23     return ans;
24 }
25 
26 int main()
27 {
28     scanf("%d%d%d",&n,&m,&g);
29     if (n+m==1)
30     {
31         if ((g==0 && n) || (g==1 && m)) printf("1\n");
32         else printf("0\n");
33         return 0;
34     }
35     if (g==1) n--;
36     if (n<0 || m<0)
37     {
38         printf("0\n");
39         return 0;
40     }
41     fac[0]=1;
42     for (int a=1;a<=n+m;a++)
43         fac[a]=(long long)fac[a-1]*a%mo;
44     for (int a=0;a<=n+m;a++)
45         inv[a]=mul(fac[a],mo-2);
46     int ans=0;
47     while (true)
48     {
49         if (n+m>1 && m) inc(ans,(long long)fac[n+m-1]*inv[n]%mo*inv[m-1]%mo);
50         n--;
51         if (n<0) break;
52         if (n+m==1 && m==1) ans++;
53         if (n+m==0) ans++;
54         n--;
55         if (n<0) break;
56     }
57     printf("%d\n",ans);
58 
59     return 0;
60 }
View Code

 

E:

题意是你每次从给定图形中找出一个三角形染色, 要求该三角形中没有被染过色的部分,问方案数。

从内向外DP,压位表示每个部分是否有被染过色的三角形,讨论各种情况即可。

 1 #include<cstdio>
 2 #include<cstdlib>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 
 7 #define inc(a,b) {a+=b;if (a>=mo) a-=mo;}
 8 
 9 const int mo=1000000007;
10 
11 int n,k,f[401][210][16],g[16][10][16],h[5][10][2][2][16],num[16];
12 
13 int main()
14 {
15     scanf("%d%d",&n,&k);
16     for (int a=0;a<16;a++)
17         for (int b=0;b<16;b++)
18         {
19             static int col[4];
20             col[0]=col[1]=col[2]=col[3]=0;
21             int cnt=0;
22             for (int c=0;c<4;c++)
23                 col[c]=((a>>c)&1),cnt+=col[c];
24             bool able=true;
25             for (int c=0;c<4;c++)
26                 if ((b>>c)&1)
27                 {
28                     if (col[c] || col[(c+1)%4]) able=false;
29                     col[c]=col[(c+1)%4]=true;
30                     cnt++;
31                 }
32             if (!able) continue;
33             int news=0;
34             for (int c=3;c>=0;c--)
35                 news=(news<<1)|col[c];
36             f[0][cnt][news]++;
37         }
38     for (int a=0;a<16;a++)
39     {
40         int b=a,c=0;
41         while (b)
42             c+=b&1,b>>=1;
43          num[a]=c;
44     }
45     for (int a=0;a<(1<<4);a++)
46     {
47         memset(h,0,sizeof(h));
48         h[1][0][0][0][a]=h[1][1][1][0][a|1]=h[1][2][1][1][a|1]=h[1][1][0][1][a|1]=1;
49         if (!(a&1)) h[1][1][1][1][a|1]=1;
50         for (int b=1;b<4;b++)
51             for (int use=0;use<=8;use++)
52                 for (int last=0;last<=1;last++)
53                     for (int first=0;first<=1;first++)
54                         for (int s=0;s<16;s++)
55                             if (h[b][use][last][first][s])
56                                 for (int use1=0;use1<2;use1++)
57                                     for (int use2=0;use2<2;use2++)
58                                     {
59                                         if (!use1 && !use2 && !((s>>b)&1)) inc(h[b+1][use+1][1][first][s|(1<<b)],h[b][use][last][first][s]);
60                                         inc(h[b+1][use+use1+use2][use2][first][s|((use1|use2)<<b)],h[b][use][last][first][s]);
61                                         if (!last && !use1) inc(h[b+1][use+1+use2][use2][first][s|(1<<b)|(1<<(b-1))],h[b][use][last][first][s]);
62                                         if (!use1 && !use2 && !((s>>b)&1) && !((s>>(b-1))&1)) inc(h[b+1][use+1][1][first|(b==1)][s|(1<<b)|(1<<(b-1))],h[b][use][last][first][s]);
63                                     }
64         for (int use=0;use<=8;use++)
65             for (int s=0;s<16;s++)
66                 inc(h[4][use+1][1][1][s|9],h[4][use][0][0][s]);
67         for (int use=0;use<=8;use++)
68             for (int s=0;s<16;s++)
69                 if (!(s&1) && !(s&8)) inc(h[4][use+1][1][1][s|9],h[4][use][0][0][s]);
70         for (int use=0;use<=8;use++)
71             for (int last=0;last<=1;last++)
72                 for (int first=0;first<=1;first++)
73                     for (int s=0;s<16;s++)
74                         inc(g[a][use][s],h[4][use][last][first][s]);
75     }
76     for (int a=0;a<2*n;a++)
77         for (int b=0;b<=k;b++)
78             for (int c=0;c<16;c++)
79                 if (f[a][b][c])
80                     if (a&1)
81                     {
82                         for (int delta=0;delta<=8;delta++)
83                             for (int s=0;s<16;s++)
84                                 inc(f[a+1][b+delta][s],(long long)f[a][b][c]*g[c][delta][s]%mo);
85                     }
86                     else
87                     {
88                         for (int d=0;d<16;d++)
89                             inc(f[a+1][b+num[d]][c|d],f[a][b][c]);
90                     }
91     int ans=0;
92     for (int a=0;a<16;a++)
93         inc(ans,f[2*n][k][a]);
94     for (int a=1;a<=k;a++)
95         ans=(long long)ans*a%mo;
96     printf("%d\n",ans);
97 
98     return 0;
99 }
View Code

 

posted @ 2013-09-20 16:20  zhonghaoxi  阅读(319)  评论(0编辑  收藏  举报
BYRBT