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

2018.10.18 练习赛 数学专练

时间:2018-10-19 02:11:07      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:git   tail   距离   inline   get   lin   cst   long   res   

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 练习赛 数学专练

标签:git   tail   距离   inline   get   lin   cst   long   res   

原文地址:https://www.cnblogs.com/KatouKatou/p/9813947.html

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