码迷,mamicode.com
首页 > 其他好文 > 详细

【bzoj3782】上学路线

时间:2019-07-23 21:21:15      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:c++   为什么   https   sed   microsoft   space   line   event   mes   

这题 WC2018 时 wzj 搬过……

前置题目

技术图片
 1 #include<bits/stdc++.h>
 2 #define int long long
 3 #define ll long long
 4 #define N 505
 5 #define L 1000005 
 6 #define mod 1000000007
 7 using namespace std;
 8 inline int read(){
 9     int x=0; bool f=1; char c=getchar();
10     for(;!isdigit(c); c=getchar()) if(c==-) f=0;
11     for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+(c^0);
12     if(f) return x;
13     return 0-x;
14 }
15 int n; ll jc[L+5],jcn[L+5],f[N];
16 struct node{int x,y;}E,A,B,b[N];
17 inline bool cmp(node a, node b){
18     return a.x==b.x ? a.y<b.y : a.x<b.x;
19 }
20 ll Pow(ll x, int y){
21     ll ret=1;
22     while(y){
23         if(y&1) ret=ret*x%mod;
24         x=x*x%mod;
25         y>>=1;
26     }
27     return ret;
28 }
29 void work(int &x, int &y){
30     int a1 = x*B.y - y*B.x, a2 = A.x*B.y - A.y*B.x;
31     int b1 = x*A.y - y*A.x, b2 = A.y*B.x - A.x*B.y;
32     if(!a2 || !b2 || a1/a2*a2!=a1 || b1/b2*b2!=b1){
33         x=y=-1; return;
34     }
35     else
36         x=a1/a2, y=b1/b2;
37 }
38 ll C(int n, int m){
39     return jc[n] * jcn[n-m] % mod * jcn[m] % mod;
40 }
41 ll cal(int x, int y){
42     if(x<0 || y<0) return 0;
43     return C(x+y, y);
44 }
45 signed main(){
46     //freopen("bzoj4767.in","r",stdin);
47     //freopen("1.out","w",stdout);
48     E.x=read(), E.y=read(), n=read();
49     A.x=read(), A.y=read(), B.x=read(), B.y=read();
50     work(E.x,E.y); if(E.x<0 || E.y<0){printf("0\n"); return 0;}//goto faq;}
51     //printf("%d %d\n",E.x,E.y);
52     for(int i=1; i<=n; ++i){
53         b[i].x=read(), b[i].y=read();
54         work(b[i].x, b[i].y);
55         if(b[i].x<0 | b[i].y<0 || b[i].x>E.x || b[i].y>E.y) --n, --i;
56     }
57     b[++n]=(node){E.x,E.y};
58     sort(b+1,b+n+1,cmp);
59     jc[0]=jc[1]=1;
60     for(int i=2; i<=L; ++i) jc[i] = jc[i-1] * i % mod;
61     jcn[L] = Pow(jc[L], mod-2);
62     for(int i=L-1; i>=0; --i) jcn[i] = jcn[i+1] * (i+1) % mod;
63     for(int i=1; i<=n; ++i){
64         f[i] = cal(b[i].x, b[i].y); 
65         for(int j=1; j<i; ++j)
66             f[i] = ((f[i] - f[j] * cal(b[i].x-b[j].x, b[i].y-b[j].y) % mod) % mod + mod) % mod;
67     }
68       
69     cout<<f[n]<<endl;
70 /*faq:
71     fclose(stdout);
72     cout<<f[n]<<endl;
73     */
74     return 0;
75 }
View Code

本题题解

 

别问为什么都是 zsy 的博客,zsy 天下第一(雾)

 

【bzoj3782】上学路线

标签:c++   为什么   https   sed   microsoft   space   line   event   mes   

原文地址:https://www.cnblogs.com/scx2015noip-as-php/p/bzoj3782.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!