A B
4801: 打牌
分类讨论就行了
比赛时一开始写挂了...
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = (1<<18) + 5;
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
int aq, bq, at, bt, c[300];
char s[5];
inline int f(int x) {return x==100 ? 1 : x;}
int solve(int a, int b, int c, int d) {
//printf("solve %d %d %d %d\n", a, b, c, d);
int ans = 0;
if(a >= c) {
ans += f(a);
int t = 0;
if(c > b) t = max(t, f(c));
if(d > b) t = max(t, f(d));
if(!t) ans += f(b);
else ans -= t;
} else {
int t = 0;
if(b < d || (b == d && a == b)) ans = -f(c) - f(d);
else {
t = min(f(a), f(b));
ans = t - f(c);
}
}
return ans;
}
int main() {
freopen("in", "r", stdin);
int T = read();
for(int i=1; i<=9; i++) c[i + '0'] = i;
c['T'] = 10; c['J'] = 11; c['Q'] = 12; c['K'] = 13; c['A'] = 100;
while(T--) {
int x, y;
scanf("%s", s); x = c[ s[0] ];
scanf("%s", s); y = c[ s[0] ];
aq = max(x, y); bq = min(x, y);
scanf("%s", s); x = c[ s[0] ];
scanf("%s", s); y = c[ s[0] ];
at = max(x, y); bt = min(x, y);
printf("%d\n", solve(aq, bq, at, bt));
}
}
4832: 抵制克苏恩
裸期望DP,\(f[i][a][b][c]\)
然而比赛的时候概率忘记乘上a,b,c的个数一直WA,我二轮药丸....
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N = (1<<18) + 5;
inline int read(){
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
double f[55][10][10][10];
void dp() {
for(int i=1; i<=50; i++)
for(int a=0; a<=7; a++)
for(int b=0; b<=7-a; b++)
for(int c=0; c<=7-a-b; c++) {
double &now = f[i][a][b][c], t = 1.0 / (a+b+c+1);
now += t * (f[i-1][a][b][c] + 1);
if(a) now += a * t * f[i-1][a-1][b][c];
if(a + b + c < 7) {
if(b) now += b * t * f[i-1][a+1][b-1][c+1];
if(c) now += c * t * f[i-1][a][b+1][c];
} else {
if(b) now += b * t * f[i-1][a+1][b-1][c];
if(c) now += c * t * f[i-1][a][b+1][c-1];
}
}
}
int k, a, b, c;
int main() {
freopen("in", "r", stdin);
dp();
int T = read();
while(T--) {
k=read(); a=read(); b=read(); c=read();
double ans = f[k][a][b][c];
//ans = min(ans, 30.00);
printf("%.2lf\n", ans);
}
}
Copyright:http://www.cnblogs.com/candy99/