Codeforces Round #195 (Div. 2)

记次CF吧 1题。。。B题。。因为循环的i没设成long long 却参与了运算 结果就悲剧了 一直交 一直挂 。。上题

A 水。。 第一次少了个空格还。。

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<stdlib.h>

 5 #include<algorithm>

 6 using namespace std;

 7 #define LL long long

 8 LL x,y;

 9 int main()

10 {

11     int i,j,k,n,m;

12     cin>>x>>y;

13     if((x<0&&y>0)||(x>0&&y<0))

14     {

15         LL b = y-x;

16         if(b<0)

17         cout<<"0"<<" "<<b<<" "<<-b<<" "<<"0"<<endl;

18         else

19         cout<<-b<<" "<<"0 "<<"0"<<" "<<b<<endl;

20     }

21     else

22     {

23         LL b = y+x;

24         if(b>0)

25         cout<<"0"<<" "<<b<<" "<<b<<" "<<"0"<<endl;

26         else

27         cout<<b<<" "<<"0"<<" "<<"0 "<<b<<endl;

28     }

29     return 0;

30 }
View Code

B题 大体画画 就出来了 求下和加加

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 #include<cmath>

 7 using namespace std;

 8 #define eps 1e-6

 9 int main()

10 {

11     long long m,r,i;

12     cin>>m>>r;

13     double s =0,s1=0;

14     for(i = 1 ; i <= m ; i++)

15     {

16         s = 0;

17         if(i>2)

18         s+=(i-2)*(i-1)*r+(i-2.0)*sqrt(2.0)*2*r+sqrt(2.0)*r+2*r;

19         else

20         s+=(i-1)*i*r+(i-1)*sqrt(2.0)*r;

21         if(m-i>=2)

22         s+=(m-i-1)*(m-i)*r+(m-i-1)*sqrt(2.0)*2*r+2*r+sqrt(2.0)*r+2*r;

23         else

24         s+=(m-i)*(m-i+1)*r+(m-i)*sqrt(2.0)*r+2*r;

25         s1+=s/m;

26     }

27     printf("%.10f\n",s1/m);

28     return 0;

29 }
View Code

往后就没再看 一直在交B 7次WA啊啊 泪~~

 补道C题

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 #define N 100010

 7 #define LL long long

 8 using namespace std;

 9 struct node

10 {

11     LL a;

12     int d[50],k;

13 }q[N];

14 int f[50];

15 void digit(int e)

16 {

17     int g=0;

18     LL y = q[e].a;

19     while(y)

20     {

21         int x = y%2;

22         g++;

23         q[e].d[g] = x;

24         y/=2;

25     }

26     q[e].k = g;

27 }

28 bool cmp(node a,node b)

29 {

30     return a.a<b.a;

31 }

32 int main()

33 {

34     int i,j,k,n,o,g;

35     cin>>n;

36     for(i = 1; i <= n ;i++)

37     {

38         scanf("%d",&q[i].a);

39         digit(i);

40     }

41     sort(q+1,q+n+1,cmp);

42     o = 0;

43     for(i = 32; i >= 0 ; i--)

44     {

45         memset(f,0,sizeof(f));

46         for(j = n; j >= 1 ; j--)

47         {

48             if(q[j].k<i)

49             break;

50             if(q[j].d[i]!=0)

51             {

52                 for(g = 1; g < q[j].k ; g++)

53                 if(q[j].d[g]==0)

54                     f[g] = 1;

55             }

56         }

57         for(g = 1 ; g < i ; g++)

58             if(!f[g]) break;

59         if(g==i)

60         {

61             o = g;

62             break;

63         }

64     }

65     int num = 0;

66     for(i = n ; i >= 1 ; i--)

67     if(q[i].d[o]==1)

68     num++;

69     cout<<num<<endl;

70     int w=0;

71     for(i = n ; i >= 1 ; i--)

72     if(q[i].d[o]==1)

73     {

74         if(w)

75         printf(" ");

76         w++;

77         cout<<q[i].a;

78     }

79     return 0;

80 }
View Code

 补道D题

根据费马小定理神马的求逆元 然后高端的算组合数取模 

若第一个是1 则最后为0  若全是0且为偶数-》1 否则-》0 组合起来就可以求解了 

100。。。。

0100。。

0010。。

0001。。。

 1 #include <iostream>

 2 #include<cstdio>

 3 #include<cstring>

 4 #include<algorithm>

 5 #include<stdlib.h>

 6 using namespace std;

 7 #define mod 1000000007

 8 #define LL long long

 9 LL ff[200010];

10 LL fmod(LL a,LL k)

11 {

12     LL b = 1;

13     while(k)

14     {

15         if(k&1)

16         b = a*b%mod;

17         a = (a%mod)*(a%mod)%mod;

18         k/=2;

19     }

20     return b;

21 }

22 LL cn(int n,int m)

23 {

24     LL ans,a;

25     ans = ff[n];

26     a = fmod((ff[n-m]*ff[m])%mod,mod-2);

27     return (ans*a)%mod;

28 }

29 int main()

30 {

31     int i,j,k,n,m,g;

32     while(cin>>n>>m>>g)

33     {

34         LL s1=0,s2=0;

35         if(n==0)

36         {

37             if(m==1&&g==1)

38             cout<<"1\n";

39             else if(m>1&&g==1)

40             cout<<"0\n";

41             else if(m==1&&g==0)

42             cout<<"0\n";

43             else

44             cout<<"1\n";

45             continue;

46         }

47         else if(m==0)

48         {

49             if(n%2==0)

50             k = 1;

51             else

52             k = 0;

53             if(k==g)

54             cout<<"1\n";

55             else

56             cout<<"0\n";

57             continue;

58         }

59         ff[0] = 1;

60         for(i = 1;i <= n+m;i ++)

61         {

62            ff[i] = (ff[i-1]*i)%mod;

63         }

64         s1 = cn(n+m,m);

65         for(i = 0 ;i <= n ; i+=2)

66         {

67             if(m+n-i-1>=m-1)

68             s2=(s2+cn(m+n-i-1,m-1))%mod;

69         }

70         if(m==1&&n%2!=0)

71         s2++;

72         if(m==1&&n%2==0)

73         s2--;

74         if(g==0)

75         cout<<s2<<endl;

76         else

77         {

78             if(s1-s2<0)

79             s1 = s1-s2+mod;

80             else

81             s1 = s1-s2;

82             cout<<s1<<endl;

83         }

84     }

85     return 0;

86 }
View Code

 

你可能感兴趣的:(codeforces)