2018.10.18 練習賽 數學專練
阿新 • • 發佈:2018-10-19
tail math get ons 因數 inter printf def 質因數
T1 打氣球
題解:
期望遞推,不關心具體位置,所以\(F[i][j]\)表示還有\(i\),\(j\)行,列未完;
\(code\):
#include<cstdio> #include<algorithm> #include<ctype.h> #include<vector> #include<queue> #include<cstring> #define lowbit(x) (x&-x) #define ll long long #define ld double #include<map> #include<stdlib.h> #include<ctime> #define mod 19260817 using namespace std; char buf[1<<20],*p1,*p2; inline char gc() { // return getchar(); return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++; } template<typename T> inline void read(T &x) { char tt; bool flag=0; while(!isdigit(tt=gc())&&tt!='-'); tt=='-'?(flag=1,x=0):(x=tt-'0'); while(isdigit(tt=gc())) x=x*10+tt-'0'; if(flag) x=-x; } int n,m; int hang,lie; ld f[2005][2005]; bool heng[2005],zong[2005]; ld dfs(int x,int y) { if(f[x][y]!=-1) return f[x][y]; if(!x&&!y) return f[x][y]=0.0;f[x][y]=0.0; f[x][y]+=(x)?(dfs(x-1,y)*1.0*x*(n-y)):0.0; // printf("%.2lf\n",f[x][y]); f[x][y]+=(y)?(dfs(x,y-1)*1.0*y*(n-x)):0.0; f[x][y]+=(x&&y)?(dfs(x-1,y-1)*1.0*x*y):0.0; return f[x][y]=(f[x][y]+n*n*1.0)/((x+y)*n-x*y); } int main() { read(n),read(m); for(int i=1;i<=m;i++) { int x,y; read(x),read(y); heng[x]=zong[y]=1; } for(int i=1;i<=n;i++) hang+=!heng[i],lie+=!zong[i]; for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) f[i][j]=-1; printf("%.2lf",dfs(hang,lie)); return 0; }
T2 有趣的數列
題解:
卡特蘭數+質因數分解
\(code:\)
#include<cstdio> #include<algorithm> #include<ctype.h> #include<vector> #include<queue> #include<cstring> #define lowbit(x) (x&-x) #define ll long long #define ld double #include<map> #include<stdlib.h> #include<ctime> using namespace std; char buf[1<<20],*p1,*p2; inline char gc() { // return getchar(); return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin))==p1?0:*p1++; } template<typename T> inline void read(T &x) { char tt; bool flag=0; while(!isdigit(tt=gc())&&tt!='-'); tt=='-'?(flag=1,x=0):(x=tt-'0'); while(isdigit(tt=gc())) x=x*10+tt-'0'; if(flag) x=-x; } const int maxn=1000002; ll pri[maxn<<1],phi[maxn<<1],s[maxn<<1],ans=1; ll n,mod,tot; bool book[maxn<<1]; void modify(int x,int d){ while(1){ if(pri[phi[x]]==0) break; s[phi[x]]+=d; x/=pri[phi[x]]; } } void sent(){ for(int i=2;i<=n<<1;i++){ if(!book[i]) pri[++tot]=i,phi[i]=tot; for (int j=1;pri[j]*i<=(n<<1)&&j<=tot;j++){ book[pri[j]*i]=1,phi[pri[j]*i]=j; if(i%pri[j]==0) break; } } } int main(){ // 1 1 5 14 42 // freopen("interesting.in","r",stdin); // freopen("interesting.out","w",stdout); read(n),read(mod);sent(); for (int i=n<<1;i>n;i--) modify(i,1); for (int i=1;i<=n;i++) modify(i,-1); modify(n+1,-1); for(int i=1;i<=tot;i++) while(s[i]--) ans=(ans*pri[i])%mod; printf("%lld",ans); return 0; }
T3 距離
題解:
待補
\(code:\)
待補
2018.10.18 練習賽 數學專練