# Bzoj4767 两双手

Time Limit: 10 Sec  Memory Limit: 256 MB
Submit: 553  Solved: 160

## Description

)呢？两种移动方法不同当且仅当移动步数不同或某一步所到达的点不同。老W听了这个问题，觉得还不够有趣，他

## Input

|Ax|,|Ay|,|Bx|,|By| <= 500, 0 <= n,Ex,Ey <= 500

4 4 1
0 1 1 0
2 3

40

## Source

$Ax * X + Bx * Y =Ex$

$Ay * X + By * Y =Ey$

  1 /*by SilverN*/
2 #include<algorithm>
3 #include<iostream>
4 #include<cstring>
5 #include<cstdio>
6 #include<cmath>
7 #include<vector>
8 #define LL long long
9 using namespace std;
10 const int mod=1e9+7;
11 const int mxn=1200000;
13     int x=0,f=1;char ch=getchar();
14     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
15     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
16     return x*f;
17 }
18 struct point{
19     int x,y;
20     bool operator < (const point b)const{return x<b.x;}
21 }s[mxn];
22 int n,Ex,Ey;
23 int ax,ay,bx,by;
24 int SA,SB;
25 LL fac[mxn];
26 LL inv[mxn];
27 void init(){
28     fac[1]=1;inv[1]=1;
29     fac[0]=1;inv[0]=1;
30     for(int i=2;i<mxn;i++){
31         fac[i]=(LL)fac[i-1]*i%mod;
32         inv[i]=((-mod/i)*inv[mod%i]%mod+mod)%mod;
33     }
34     for(int i=2;i<mxn;i++) inv[i]=inv[i]*inv[i-1]%mod;
35 //  for(int i=1;i<=100;i++)printf("i:%d %lld\n",i,inv[i]);
36     return;
37 }
38 bool GST(int u,int v){
39     int x0=s[v].x-s[u].x;
40     int y0=s[v].y-s[u].y;
41     int a=x0*ay-y0*ax,b=bx*ay-by*ax;
42     if(a%b)return 0;else SA=a/b;
43     a=x0*by-y0*bx,b=ax*by-ay*bx;
44     if(a%b)return 0;else SB=a/b;
45     return 1;
46
47 /*  int tmp=y0*ax-x0*ay;
48     int t2=ax*by-ay*bx;
49     if(tmp%t2)return 0;
50     else SB=tmp/t2;
51     tmp=y0*bx-x0*by;
52     t2=bx*ay-by*ax;
53     if(tmp%t2)return 0;
54     else SA=tmp/t2;
55     return 1;*/
56 }
57 inline LL calc(int n,int m){
58     if(n<m)return 0;
59     return fac[n]*inv[m]%mod*inv[n-m]%mod;
60 }
61 LL f[mxn];
62 void solve(){
63     int i,j;
64 //  printf("%d %d %d %d\n",ax,ay,bx,by);
65     for(i=1;i<=n;i++){
66         if(!GST(0,i))continue;
67 //      printf("x:%d y:%d\n",s[i].x,s[i].y);
68 //      printf("SA:%d SB:%d\n",SA,SB);
69         f[i]=calc(SA+SB,SA);
70         for(j=1;j<i;j++){
71 //          if(s[j].x<=s[i].x && s[j].y<=s[i].y){
72                 if(!GST(j,i))continue;
73 //              printf("j%d:SA:%d SB:%d %lld\n",j,SA,SB,calc(SA+SB,SA));
74                 f[i]=(f[i]-(f[j]*calc(SA+SB,SA))%mod+mod)%mod;
75 //          }
76         }
77 //      printf("f[%d]:%lld\n",i,f[i]);
78     }
79     printf("%lld\n",f[n]);
80     return;
81 }
82 int main(){
83 //  freopen("in.txt","r",stdin);
84     init();
85     int i,j;
88     for(i=1;i<=n;i++){
90 /*      if(s[i].x>Ex || s[i].y>Ey){
91             i--;n--;
92         }*/
93     }
94     ++n;s[n].x=Ex,s[n].y=Ey;
95     if(!GST(0,n)){
96         printf("0\n");return 0;
97     }
98     sort(s+1,s+n);
99     solve();
100     return 0;
101 }
WA掉的代码

  1 /*by SilverN*/
2 #include<algorithm>
3 #include<iostream>
4 #include<cstring>
5 #include<cstdio>
6 #include<cmath>
7 #include<vector>
8 #define LL long long
9 using namespace std;
10 const int mod=1e9+7;
11 const int mxn=1200000;
13     int x=0,f=1;char ch=getchar();
14     while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
15     while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
16     return x*f;
17 }
18 struct point{
19     int x,y;bool ban;
20     bool operator < (const point b)const{
21         return (x<b.x)||(x==b.x && y==b.y);
22     }
23 }s[mxn];
24 int n,Ex,Ey;
25 int ax,ay,bx,by;
26 int SA,SB;
27 LL fac[mxn];
28 LL inv[mxn];
29 void init(){
30     fac[1]=1;inv[1]=1;
31     fac[0]=1;inv[0]=1;
32     for(int i=2;i<mxn;i++){
33         fac[i]=(LL)fac[i-1]*i%mod;
34         inv[i]=((-mod/i)*inv[mod%i]%mod+mod)%mod;
35     }
36     for(int i=2;i<mxn;i++) inv[i]=inv[i]*inv[i-1]%mod;
37     return;
38 }
39 bool ban[mxn];
40 bool GST(int u,int v){
41     int x0=s[v].x-s[u].x;
42     int y0=s[v].y-s[u].y;
43 /*    int a=x0*ay-y0*ax,b=bx*ay-by*ax;
44     if(a%b)return 0;else SA=a/b;
45     a=x0*by-y0*bx,b=ax*by-ay*bx;
46     if(a%b)return 0;else SB=a/b;
47     return 1;*/
48     int tmp=y0*ax-x0*ay;
49     int t2=ax*by-ay*bx;
50     if(tmp%t2)return 0;
51     else SB=tmp/t2;
52     tmp=y0*bx-x0*by;
53     t2=bx*ay-by*ax;
54     if(tmp%t2)return 0;
55     else SA=tmp/t2;
56     return 1;
57 }
58 inline LL calc(int n,int m){
59     if(n<m)return 0;
60     return fac[n]*inv[m]%mod*inv[n-m]%mod;
61 }
62 LL f[mxn];
63 void solve(){
64     int i,j;
65     for(i=1;i<=n;i++){
66         f[i]=calc(s[i].x+s[i].y,s[i].x);
67         for(j=1;j<i;j++){
68             if(s[j].x<=s[i].x && s[j].y<=s[i].y){
69                 f[i]=(f[i]-(f[j]*calc(s[i].x-s[j].x+s[i].y-s[j].y,s[i].x-s[j].x))%mod+mod)%mod;
70             }
71         }
72 //        printf("f[%d]:%lld\n",i,f[i]);
73     }
74     printf("%lld\n",f[n]);
75     return;
76 }
77 int main(){
78 //    freopen("in.txt","r",stdin);
79     init();
80     int i,j;
83     for(i=1;i<=n;i++){
85     }
86     ++n;s[1].x=Ex,s[1].y=Ey;
87     if(!GST(0,1)){
88         printf("0\n");return 0;
89     }
90     s[1].x=SA;s[1].y=SB;
91     int cnt=1;
92     for(i=2;i<=n;i++){
93         if(!GST(0,i))continue;
94         s[++cnt].x=SA;s[cnt].y=SB;
95         if(s[cnt].x>s[1].x || s[cnt].x>s[1].y)cnt--;
96     }
97     n=cnt;
98     sort(s+1,s+n+1);
99     solve();
100     return 0;
101 }

posted @ 2017-03-24 21:22  SilverNebula  阅读(178)  评论(0编辑  收藏  举报