zoukankan      html  css  js  c++  java
  • 2019/11/8 CSP模拟

    T1 药品实验

    内网#4803
    由概率定义,有$$a + b + c = 0$$
    变形得到$$1 - b = a + c$$
    根据题意有$$p_i = a p {i - 1} + b p_i + c p{i + 1}$$

    [ herefore (1 - b) p_i = a p_{i - 1} + c p_{i + 1} ]

    [ herefore (a + c) p_i = a p_{i - 1} + c p_{i + 1} ]

    [a(p_i - p_{i - 1}) = c(p_{i + 1} - p_i) ]

    仔细观察一下发现这对于任何(i)都适用,也就是说(p)序列的差分序列有一些优秀的性质
    (d)(p)的差分序列,(k)(d)的公比即(frac{a}{c}),那么有$$a* d_i = c * d_{i + 1}$$
    即$$frac{d_{i + 1}}{d_i} = frac{a}{c}$$
    (d)是一个等比数列,求(p_n)即求(sumlimits_{i = 1}^n d_i),由等比数列求和公式得到

    [p_{2n} = d_1 * frac{(k^n - 1)(k^n + 1)}{k - 1} = 1 ]

    [p_n = d_1 * frac{1}{k^n + 1} = p_{2n} * frac{1}{k^n + 1} = frac{1}{k^n + 1} ]

    (O(log(n)))求快速幂即可

    #include<bits/stdc++.h>
    #define ll long long
    using namespace std;
    const int mod = (int)1e9 + 7;
    ll n, alpha, beta, a, c, ans;
    ll qpow(ll a, ll b) {ll ans = 1; for (; b; b >>= 1) {if (b&1) ans = (a * ans) % mod; a = (a * a) % mod;} return ans % mod;}
    int main() {
    	cin >> n >> alpha >> beta;
    	a = ((1 - alpha) * beta) % mod, c = alpha * (1 - beta) % mod;
    	ans = qpow(c, mod - 2) * a % mod; ans = qpow(ans, n) % mod + 1; ans = qpow(ans, mod - 2) % mod;
    	printf("%lld", ans);
    	return 0;
    }
    

    T2 小猫钓鱼

    内网#4804
    被自己sb到了,(s)没跟着离散化 (100pts -> 10pts)

    #include<bits/stdc++.h>
    #define N (100000 + 10)
    using namespace std;
    inline int read(){
    	int cnt = 0, f = 1; char c = getchar();
    	while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
    	while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + (c ^ 48); c = getchar();}
    	return cnt * f;
    }
    int T, n, m, s, l, a[N], b[N], cnt, tot, inq[N], kil[N], r;
    deque <int> q[205], q2, t;
    void pre_work() {
    	sort (b + 1, b + cnt + 1);
    	int q = unique(b + 1, b + cnt + 1) - b - 1;
    	for (register int i = 1; i <= cnt; ++i) a[i] = lower_bound(b + 1, b + q + 1, a[i]) - b;
    	s = lower_bound(b + 1, b + q + 1, s) - b;
    }
    int main() {
    //	freopen("fishing.in", "r", stdin);
    //	freopen("fishing.out", "w", stdout);
    	while (1) {
    		n = read(), m = read(), l = read(), s = read(), T = read();
    		tot = n; cnt = 0; r = 0;
    		if (n == -1) break;
    		memset(inq, 0, sizeof inq);
    		for (register int i = 1; i <= n; ++i) while (q[i].size()) q[i].pop_back();
    		while (q2.size()) q2.pop_back();
    		while (t.size()) t.pop_back();
    		for (register int i = 1; i <= n; ++i) 
    			for (register int j = 1; j <= l; ++j) a[++cnt] = b[cnt] = read();
    		a[++cnt] = b[cnt] = s;
    		pre_work();
    		for (register int i = 1; i <= n; ++i) 
    			for (register int j = 1; j <= l; ++j) q[i].push_back(a[(i - 1) * l + j]);
    		while (T-- && tot > 1) {  //every round
    			++r;
    			for (register int i = 1; i <= n; ++i) { // every person
    				if (q[i].empty()) continue;
    				int cur = q[i].front(); q[i].pop_front();
    				q2.push_back(cur); ++inq[cur];
    				if (cur == s && q2.size() > 1) { // if cur is J
    					while (!q2.empty()) t.push_back(q2.back()), --inq[q2.back()], q2.pop_back();
    					while (!t.empty()) q[i].push_back(t.back()), t.pop_back();
    				}
    				if (inq[cur] > 1 && cur != s && q2.size() > 1) {
    					while (inq[cur] && q2.size())   //pop from back
    						t.push_back(q2.back()), --inq[q2.back()], q2.pop_back();
    					while (!t.empty()) q[i].push_back(t.back()), t.pop_back();
    				}
    				if (q[i].empty()) --tot, kil[i] = r;
    			}
    		}
    		for (register int i = 1; i <= n; ++i) printf("%d ", q[i].size() ? q[i].size() : -kil[i]);
    		puts("");
    		for (register int i = 1; i <= n; ++i) {
    			while (q[i].size()) {printf("%d ", b[q[i].front()]); q[i].pop_front();}
    			puts("");
    		}
    	}
    	return 0;
    }
    

    T3

    太毒瘤了所以咕了

  • 相关阅读:
    我的小问题
    js实现随机的四则运算题目
    VC++ 6.0 无法打开文件
    VC6.0致命错误 RC1015: 无法打开包含文件 'afxres.h'.解决方案
    VS2010 如何添加H文件目录和LIB目录
    学习计划(四月)
    IIS与apache的对比:大杂烩
    ubuntu下有线网卡启动(Atheros AR8161 Gigabit Ethernet)
    putty终端乱码解决办法
    Proxy Switchysharp配置
  • 原文地址:https://www.cnblogs.com/kma093/p/11821732.html
Copyright © 2011-2022 走看看