NOIP2010 提高组

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

转载于:https://www.cnblogs.com/stooge/p/9885185.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值