zoukankan      html  css  js  c++  java
  • 2020 牛客 NOIP 赛前集训营-S(第六场)- A 袜子分配

    ( ext{Description})

    传送门

    ( ext{Solution})

    排列组合真的好差。。。当时还乱容斥了一波没搞出来。

    先算出总方案就是 (frac{ ext A_{2n}^{2n}}{2^{n}})。我们可以考虑操作是固定位置往里面填数,显然可以把 (2n) 划分成 (n) 个长度为 (2) 的位置,每个位置内部都要除以 (2)

    可以分开考虑每一组。

    发现每一对袜子其实只用在包含它的取袜子序列的答案加 (1) 就行了。枚举这对袜子存在的位置有 (n) 种,剩下的位置可以随便放(同总方案计算方法)即 (frac{ ext A_{2n-2}^{2n-2}}{2^{n-1}})。然后一共有 (n) 对袜子,再乘上 (n),最后除以总方案数就是 (n/(2n-1))

    ( ext{Code})

    #include <cstdio>
    
    #define rep(i,_l,_r) for(register signed i=(_l),_end=(_r);i<=_end;++i)
    #define fep(i,_l,_r) for(register signed i=(_l),_end=(_r);i>=_end;--i)
    #define erep(i,u) for(signed i=head[u],v=to[i];i;i=nxt[i],v=to[i])
    #define efep(i,u) for(signed i=Head[u],v=to[i];i;i=nxt[i],v=to[i])
    #define print(x,y) write(x),putchar(y)
    
    template <class T> inline T read(const T sample) {
    	T x=0; int f=1; char s;
    	while((s=getchar())>'9'||s<'0') if(s=='-') f=-1;
    	while(s>='0'&&s<='9') x=(x<<1)+(x<<3)+(s^48),s=getchar();
    	return x*f;
    }
    template <class T> inline void write(const T x) {
    	if(x<0) return (void) (putchar('-'),write(-x));
    	if(x>9) write(x/10);
    	putchar(x%10^48);
    }
    template <class T> inline T Max(const T x,const T y) {if(x>y) return x; return y;}
    template <class T> inline T Min(const T x,const T y) {if(x<y) return x; return y;}
    template <class T> inline T fab(const T x) {return x>0?x:-x;}
    template <class T> inline T Gcd(const T x,const T y) {return y?Gcd(y,x%y):x;}
    template <class T> inline T Swap(T &x,T &y) {x^=y^=x^=y;}
    
    int main() {
    	int n=read(9);
    	printf("%.10f
    ",1.0*n/(2.0*n-1));
    	return 0;
    }
    
  • 相关阅读:
    hive函数之~字符串函数
    hive函数之~条件函数
    JSONP使用及注意事项小结
    css命名管理混乱?不妨试试BEM
    【移动端debug-6】如何做一个App里的web调试小工具
    ES6学习笔记(五):Class和Module
    ES6学习笔记(三):与迭代相关的新东东
    ES6学习笔记(四):异步操作
    ES6学习笔记(二):引用数据类型
    CORS跨域资源共享简述
  • 原文地址:https://www.cnblogs.com/AWhiteWall/p/13903905.html
Copyright © 2011-2022 走看看