NOIP2010 提高组

版权声明:吸吸 https://blog.csdn.net/walk_dog/article/details/80718525

###T1

OJ传送门
洛谷传送门
总结:一道比较简单的模拟题,这道题当时把if_push[Tra[tot_head]]= 0;写成了if_push[tot_head]= 0;差点没调出来…发现真相的我吐血三百升…

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<deque>
using namespace std;

const int MAXN = 1e4+5;
int m, n;
int tmp, tot_head, tot_tail, answer;
int Tra[MAXN];
bool if_push[MAXN];

int main()
{
//	freopen("translate.in","r",stdin);
//	freopen("translate.out","w",stdout);
	scanf("%d%d", &m, &n);
	tot_head = tot_tail = 1;
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &tmp);
		if(!if_push[tmp])
		{
			answer++;
			if(tot_tail-tot_head < m)
			{
				Tra[tot_tail++] = tmp;
				if_push[tmp] = 1;
			} else {
				if_push[Tra[tot_head]]= 0;
				tot_head++;
				Tra[tot_tail++] = tmp;
				if_push[tmp] = 1;
			}
		}
	}
	printf("%d\n", answer);
	return 0;
}

###T2


OJ传送门
洛谷传送门
这道题用dp[a][b][c][d]来表示每种牌各出a,b,c,d张后能获得的最大分数,记得初始化dp[0][0][0][0] = Sco[1],原因在题目中出现。

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int MAXN = 45, MAXM = 355;
int n, m;
int Tmp;
int Sco[MAXM], Num[5];
int dp[MAXN][MAXN][MAXN][MAXN];

int main()
{
//	freopen("tortoise.in","r",stdin);
//	freopen("tortoise.out","w",stdout);
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)
		scanf("%d", &Sco[i]);
	for(int i = 1; i <=m; i++)
		scanf("%d", &Tmp),
		Num[Tmp]++;
	dp[0][0][0][0] = Sco[1];
	for(int a = 0; a <= Num[1]; a++)
		for(int b = 0; b <= Num[2]; b++)
			for(int c = 0; c <= Num[3]; c++)
				for(int d = 0; d <= Num[4]; d++)
				{
					int Dist = 1 + a + b*2 + c*3 + d*4;
					if(a) dp[a][b][c][d] = max(dp[a][b][c][d], dp[a-1][b][c][d]+Sco[Dist]); 
					if(b) dp[a][b][c][d] = max(dp[a][b][c][d], dp[a][b-1][c][d]+Sco[Dist]); 
					if(c) dp[a][b][c][d] = max(dp[a][b][c][d], dp[a][b][c-1][d]+Sco[Dist]); 
					if(d) dp[a][b][c][d] = max(dp[a][b][c][d], dp[a][b][c][d-1]+Sco[Dist]); 
				}
	printf("%d", dp[Num[1]][Num[2]][Num[3]][Num[4]]);
	return 0;
} 

###T3


OJ传送门
洛谷传送门
总结:一道并查集扩展域做法的题

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long ll;
const int MAXN = 1e5+5;
ll n, m;
int fa[MAXN];
struct name {
	ll f, s, c;
}Tree[MAXN];

bool comp(name x, name y){ return x.c > y.c; }

int find(int x)
{
    if(fa[x]==x)return x;
    return fa[x]=find(fa[x]);    
}

int merge(int x,int y)
{
    int ff=find(x),fff=find(y);
    fa[ff]=fff;
}

int main()
{
//	freopen("prison.in","r",stdin);
//	freopen("prison.out","w",stdout);
	scanf("%lld%lld", &n, &m);
	for(int i = 1; i <= 2*n; i++)
		fa[i] = i;
	for(int i = 1; i <= m; i++)
		scanf("%lld%lld%lld", &Tree[i].f, &Tree[i].s, &Tree[i].c);
	sort(Tree+1, Tree+m+1, comp);
	for(int i = 1; i <= m; i++)
	{
		int x = find(Tree[i].f), y = find(Tree[i].s);
		if(x == y)
		{
			cout << Tree[i].c;
			return 0;
		} 
		merge(Tree[i].f, Tree[i].s+n);
		merge(Tree[i].s, Tree[i].f+n);
	}
	cout << 0;
	return 0;
}

###T4
等我改出来…

猜你喜欢

转载自blog.csdn.net/walk_dog/article/details/80718525