日常模拟赛

题目链接

None
100 + 100 + 10 = 210

T1

不太会做...
好像....是个SB题....嗯.....div3T1难度

#include<cstdio> 
#include<algorithm> 
#define int long long 
#define gc getchar() 
#define pc putchar
inline int read() {
	int x = 0,f = 1; 
	char c = getchar(); 
	while(c < '0' || c > '9') c = getchar(); 
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
} 
void print(int x)  {
	if(x < 0) { 
		pc('-'); 
		x = -x; 
	} 
	if(x >= 10) print(x / 10); 
	pc(x % 10 + '0'); 
} 
main() { 
	freopen("grid.in","r",stdin); 
	freopen("grid.out","w",stdout); 
	int n = read(),a = read(),b = read(),c = read(),d = read(); 
	printf("%lld\n",std::max(std::abs(a - c),std::abs(d - b))); 
	return 0; 
} 

T2

dp[i][2/3]表示以i为开始向后扩展两位是否可行..那么就是从dp[i + 2 / 3][2 / 3]转移就好了

#include<cstdio> 
#include<string> 
#include<cstring>  
#include<algorithm> 
#include<bits/stdc++.h> 
using namespace std; 
#define gc getchar() 
#define pc putchar
inline int read() {
	int x = 0,f = 1; 
	char c = getchar(); 
	while(c < '0' || c > '9') c = getchar(); 
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
} 
#define ull unsigned long long
void print(int x)  {
	if(x < 0) { 
		pc('-'); 
		x = -x; 
	} 
	if(x >= 10) print(x / 10); 
	pc(x % 10 + '0'); 
} 
const int maxn = 200007; 
bool dp[maxn][5]; 
char s[maxn]; 
bool judge(int l,int r,int l1,int r1) {  
	for(int i = l,j = l1; i <= r; ++ i,++ j) {
		if(s[i] != s[j]) return true; 
	} 
	return false; 
} 
struct node { 
	int l,r; 
} ans[maxn]; 
/*const int bas; 
struct node { 
	ull has; 
	int id; 
	bool operator < (const Hash &k)const { 
		return has < k.has; 
	} 
} 
char Ts[]
ull hash(char S[]) { 
	
} */
std::string A[maxn],B[maxn]; 
int tot = 0; 
bool judge2(int x,int y) { 
	int a = A[x].size(),b = A[y].size(); 
	if(a != b) return true; 
	if(a == 2) { 
		if(A[x][0] != A[y][0]) return true;  
		if(A[x][1] != A[y][1]) return true;  
	} else { 
		if(A[x][0] != A[y][0]) return true;  
		if(A[x][1] != A[y][1]) return true;  
		if(A[x][2] != A[y][2]) return true;  
	} 
	return false; 
} 
void solve() { 
	memset(dp,0,sizeof dp); 
	tot = 0; 
	int n = strlen(s + 1); 
	dp[n - 1][2] = 1; 
	dp[n - 2][3] = 1; 
	for(int i = n;i > 3;-- i) { 
		if((dp[i + 2][2] && judge(i,i + 1,i + 2,i + 3)) || dp[i + 2][3])
			dp[i][2] = 1; 
		if((dp[i + 3][3] && judge(i,i + 2,i + 3,i + 5)) || dp[i + 3][2])
			dp[i][3] = 1; 
	} 
	A[0] = "*(&*("; 
	for(int i = 4;i <= n;++ i) { 
		if(dp[i][2]) { 
			++ tot;
			A[tot].clear(); 
			A[tot] += s[i] , A[tot] += s[i + 1]; 
		} 
		if(dp[i][3]) { 
			++ tot; 
			A[tot].clear(); 
			A[tot] += s[i],A[tot] += s[i + 1],A[tot] += s[i + 2]; 
		} 
	} 
	std::sort(A + 1,A + tot + 1); 
	int ans = 0;  
	 for(int i = 1;i <= tot;++ i) { 
		if(judge2(i,i - 1)) 
		B[++ ans] = A[i]; 
	} 
	print(ans); 
	pc('\n'); 
	for(int i = 1;i <= ans;++ i) { 
		for(int j = 0;j < B[i].size();++ j) {
			pc(B[i][j]); 
		} 
		pc('\n'); 
	} 
} 
void solve2() {
	
	memset(dp,0,sizeof dp); 
	tot = 0; 
	int n = strlen(s + 1); 
	dp[n - 1][2] = 1; 
	dp[n - 2][3] = 1; 
	for(int i = n;i > 3;-- i) { 
		if((dp[i + 2][2] ) || dp[i + 2][3])
			dp[i][2] = 1; 
		if((dp[i + 3][3] ) || dp[i + 3][2])
			dp[i][3] = 1; 
	} 
	A[0] = "*(&*("; 
	for(int i = 4;i <= n;++ i) { 
		if(dp[i][2]) { 
			++ tot;
			A[tot].clear(); 
			A[tot] += s[i] , A[tot] += s[i + 1]; 
		} 
		if(dp[i][3]) { 
			++ tot; 
			A[tot].clear(); 
			A[tot] += s[i],A[tot] += s[i + 1],A[tot] += s[i + 2]; 
		} 
	} 
	std::sort(A + 1,A + tot + 1); 
	int ans = 0;  
	 for(int i = 1;i <= tot;++ i) { 
		if(judge2(i,i - 1)) 
		B[++ ans] = A[i]; 
	} 
	print(ans); 
	pc('\n'); 
	for(int i = 1;i <= ans;++ i) { 
		for(int j = 0;j < B[i].size();++ j) {
			pc(B[i][j]); 
		} 
		pc('\n'); 
	} 
} 
int main() { 
	freopen("ling.in","r",stdin); 
	freopen("ling.out","w",stdout); 
	int n = read(),type = read(); 
	for(int i = 1;i <= n;++ i) { 
		scanf("%s",s + 1); 
		if(type == 0) solve(); 
		else solve2(); 
	} 
	return 0; 
} 

T3

dp[i][j]表示以i为根的子树中,树高小于等于j的概率
转移就是dp[i][j] *= 0.5 + 0.5 * (dp[i][j-1]) 首先是边不连的概率,其次是<=dp[son][j -1]的
然后我zz了
对于新增一个点,对于父亲的深度影响只有该节点的深度+1,除掉旧的乘上新的就OK,我全更新了一遍...,写出了奇怪的bug...

#include<cstdio> 
#include<string> 
#include<cstring>  
#include<algorithm> 
#include<bits/stdc++.h> 
using namespace std; 
#define gc getchar() 
#define pc putchar
inline int read() {
	int x = 0,f = 1; 
	char c = getchar(); 
	while(c < '0' || c > '9') c = getchar(); 
	while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar(); 
	return x * f; 
} 
void print(int x)  {
	if(x < 0) { 
		pc('-'); 
		x = -x; 
	} 
	if(x >= 10) print(x / 10); 
	pc(x % 10 + '0'); 
} 
const int maxn = 100005; 
const int h = 60; 
double dp[maxn][70]; 
double pp[maxn][70]; 
int fa[maxn]; 
int siz[maxn]; 
int node = 0; 
struct node { 
	int v,next;
} edge[maxn << 1]; 
int num = 0,head[maxn]; 
inline void add_edge(int u,int v) { 
	edge[++ num].v = v; edge[num].next = head[u];head[u] = num; 
} 
#define eps 1e-7 
void update(int x) { 
	int k = 60; 
	dp[x][0] = 1.0; 
	int X = x; 
	while(-- k && X) { 
		siz[X] ++; 
		for(int i = 0;i < h;++ i) { 
			if((fabs(dp[X][i] - 0.0) > eps) && ((fabs(dp[fa[X]][i + 1] - 0.0) > eps))) dp[fa[X]][i + 1] /= (0.5 + 0.5 * dp[X][i]); 
		} 
		X = fa[X]; 
	} 
	k = 60; 
	while(-- k && x) { 
		dp[fa[x]][0] *= 0.5; 
		for(int i = 0;i < h;++ i) { 
			if(fabs(dp[fa[x]][i + 1] - 0.0) <= eps) dp[fa[x]][i + 1] = 1.0; 
			dp[fa[x]][i + 1] *= (0.5 + 0.5 * dp[x][i]); 
		} 	 
		x = fa[x]; 
	} 
} 
int main() { 
	freopen("threebody.in","r",stdin); freopen("threebody.out","w",stdout); 
	int T = read(),q = read(); 
	++ node; 
	siz[node] = 1,dp[node][0] = 1.0; 
	for(int ty,x,i = 1;i <= q;++ i) { 
		ty = read(),x = read(); 
		if(ty == 1) { 
			fa[++ node] = x; 
			update(node); 
		} else { 
			double ans = 0; 
			for(int i = 1;i < std::min(siz[x],h);++ i) { 
				ans += 1.0 * i * std::max(dp[x][i] -  dp[x][i - 1],0.0); 
			} printf("%lf\n",ans); 
		} 
	} 
	return 0; 
} 

posted @ 2018-09-22 21:12  zzzzx  阅读(153)  评论(0编辑  收藏  举报