CSP-S 模拟 19/11/08
信息学方法:
#include#defineusing namespace std;int read(){ int x = 0, f = 1; char ch = 0; while(!isdigit(ch)) { ch = getchar(); if(ch == '-') f = -1;} while(isdigit(ch)) x = (x + (x << 2) << 1) + (ch^48), ch = getchar(); return x * f;}cs int Mod = 1e9 + 7;typedef long long ll;int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }int mul(int a, int b){ ll r = 1ll * a * b; if(r >= Mod) r %= Mod; return r; }int ksm(int a, int b){ int ans = 1; for(;b;b>>=1,a=mul(a,a)) if(b&1) ans = mul(ans,a); return ans;}int n, a, b, x, y, z;cs int N = 1e7 + 5;int f[N << 2];int main(){ n = read(), a = read(), b = read(); x = mul(add(1,Mod-a), b); y = add(mul(add(a,Mod-1),add(b,Mod-1)), mul(a, b)); z = mul(a, add(1,Mod-b)); int inv = ksm(z, Mod-2); f[1] = 1; for(int i = 2, up = n << 1; i <= up; i++){ f[i] = mul(inv, add(mul(add(1,Mod-y),f[i-1]), Mod-mul(x,f[i-2]))); } cout << mul(ksm(f[n<<1], Mod-2), f[n]); return 0;}
以后一定要倍加小心
#include#defineusing namespace std;namespace IO{ cs int Rlen = 1 << 22 | 1; char buf[Rlen], *p1, *p2; char gc(){ return (p1 == p2) && (p2 = (p1 = buf) + fread(buf, 1, Rlen, stdin), p1 == p2) ? EOF : *p1++; } int read(){ int x = 0, f = 1; char ch = 0; while(!isdigit(ch)){ ch = gc(); if(ch == '-') f = -1; } while(isdigit(ch)) x = (x + (x << 2) << 1) + (ch - '0'), ch = gc(); return x * f; }} using namespace IO;cs int N = 1e5 + 5, M = 105;int n, m, l, s, T;int sta[N], top; // 用栈维护序列 bool insta[N]; int a[M][M];queue q[M]; int b[N], sz; // 离散化 int ban[M]; // 出局时间 int tp[N];void Clear(){ while(top) insta[sta[top]] = 0, top--; sz = 0; } void Solve(){ for(int i = 1; i <= n; i++){ for(int j = 1; j <= l; j++){ a[i][j] = b[++sz] = read(); } } b[++sz] = s; sort(b + 1, b + sz + 1); sz = unique(b + 1, b + sz + 1) - (b + 1); for(int i = 1; i <= n; i++){ for(int j = 1; j <= l; j++){ a[i][j] = lower_bound(b + 1, b + sz + 1, a[i][j]) - b; q[i].push(a[i][j]); } } s = lower_bound(b + 1, b + sz + 1, s) - b; int ct = n; for(int TIME = 1; TIME <= T; TIME++){ if(ct <= 1) break; for(int i = 1; i <= n; i++){ if(ban[i]) continue; int nx = q[i].front(); q[i].pop(); if(insta[nx]){ int ret = 0; while(sta[top] ^ nx) tp[++ret] = sta[top], insta[sta[top]] = 0, top--; tp[++ret] = sta[top], insta[sta[top]] = 0, top--; for(int j = ret; j >= 1; j--) q[i].push(tp[j]); q[i].push(nx); } else if(nx == s && top){ int ret = 0; while(top) tp[++ret] = sta[top], insta[sta[top]] = 0, top--; for(int j = ret; j >= 1; j--) q[i].push(tp[j]); q[i].push(nx); } else sta[++top] = nx, insta[nx] = true; if(q[i].empty()) ban[i] = TIME, --ct; } } for(int i = 1; i <= n; i++){ if(ban[i]) cout << - ban[i]; else cout << q[i].size(); if(i ^ n) cout << " "; else puts(""); } for(int i = 1; i <= n; i++){ if(ban[i]){puts(""); ban[i] = 0; continue;} while(!q[i].empty()) cout << b[q[i].front()] << " ", q[i].pop(); puts(""); }}int main(){ while(1){ n = read(), m = read(), l = read(), s = read(), T = read(); if(!(~n)) break; Solve(); Clear(); } return 0;}
T3
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~