NOIP2014

Posted MashiroSky

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了NOIP2014相关的知识,希望对你有一定的参考价值。

生活大爆炸版石头剪刀布

  直接模拟即可。

// codevs3716
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define MOD 1000000007
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;

const int maxn=2000;
int c[5][5]={{0,0,1,1,0},
			 {1,0,0,1,0},
			 {0,1,0,0,1},
			 {0,0,1,0,1},
			 {1,1,0,0,0}};
int a[maxn],b[maxn];

int main() {
	int n,na,nb;
	scanf("%d%d%d",&n,&na,&nb);
	for (int i=0;i<na;i++) scanf("%d",&a[i]);
	for (int i=0;i<nb;i++) scanf("%d",&b[i]);
	int A=0,B=0;
	for (int i=0;i<n;i++) {
		A+=c[a[i%na]][b[i%nb]];
		B+=c[b[i%nb]][a[i%na]];
	}
	printf("%d %d",A,B);
	return 0;
}

联合权值

  一开始无脑枚举,因为只需要dfs1层,感觉完全不虚,结果被菊花树卡得只有70分,于是怒水一发树形dp。

// codevs3728
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define MOD 10007
#define inf 2147483640
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;

const int maxn=200010;
struct edge {int to,next;}e[maxn<<1];
int head[maxn],n,cnt,w[maxn],ans1,ans2;;

void link(int u,int v) {
	e[++cnt].to=v;e[cnt].next=head[u];head[u]=cnt;
	e[++cnt].to=u;e[cnt].next=head[v];head[v]=cnt;
}
void dfs(int x,int fa,int f) {
	ans1=(ans1+w[x]*w[f]);ans2=max(ans2,w[x]*w[f]);
	int x1=0,x2=0;
	for (int i=head[x];i;i=e[i].next) if (e[i].to!=fa) {
			dfs(e[i].to,x,fa);
			ans2=max(ans2,x2*w[e[i].to]);
			ans1=(ans1+x1*w[e[i].to])%MOD;
			x1=(x1+w[e[i].to])%MOD;x2=max(x2,w[e[i].to]);
		}
}
int main() {
	scanf("%d",&n);
	for (int u,v,i=1;i<n;i++) {
		scanf("%d%d",&u,&v);
		link(u,v);
	}
	for (int i=1;i<=n;i++) scanf("%d",&w[i]);
	dfs(1,0,0);
	printf("%d %d",ans2,ans1*2%MOD);
	return 0;
}

 飞扬的小鸟

  一开始打了个nm²加队列乱搞可以获得85分的高分哦!正解背包。

// codevs3729
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 100000000
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;

const int maxn=10010,maxm=1010;
struct data {int p,l,r;}t[maxn];
int n,m,K,u[maxn],d[maxn],l[maxn],r[maxn],f[maxn][maxm];

int main() {
	scanf("%d%d%d",&n,&m,&K);
	for (int i=0;i<n;i++) scanf("%d%d",&u[i],&d[i]);
	for (int i=0;i<=n;i++) l[i]=0,r[i]=m+1;
	for (int x,i=1;i<=K;i++) {
		scanf("%d",&x);
		scanf("%d%d",&l[x],&r[x]);
	}
	int cnt=0;
	for (int i=1;i<=n;i++) {
		for (int j=1;j<=m;j++) {
			f[i][j]=inf;
			if (j>u[i-1]) f[i][j]=min(f[i][j],min(f[i-1][j-u[i-1]],f[i][j-u[i-1]])+1);
		}
		for (int j=m-u[i-1];j<=m;j++) f[i][m]=min(f[i][m],min(f[i-1][j],f[i][j])+1);
		for (int j=l[i]+1;j<=r[i]-1;j++)
			if (j+d[i-1]<=m) f[i][j]=min(f[i][j],f[i-1][j+d[i-1]]);
		for (int j=1;j<=l[i];j++) f[i][j]=inf;
		for (int j=r[i];j<=m;j++) f[i][j]=inf;
		int flag=0;
		for (int j=1;j<=m;j++) if (f[i][j]<inf) {flag=1;break;}
		if (!flag) {printf("0\n%d",cnt);return 0;}
		else if (r[i]!=m+1) cnt++;
	}
	int ans=inf;
	for (int i=1;i<=m;i++) ans=min(ans,f[n][i]);
	printf("1\n%d",ans);
	return 0;
}

  

以上是关于NOIP2014的主要内容,如果未能解决你的问题,请参考以下文章

寻找道路(NOIP2014)神奇之题。。

NOIP2014飞扬的小鸟

noip2014的比赛结果啥时候公布?

[NOIP2014]寻找道路 题解

[NOIP2014]联合权值 题解

P1328 [NOIP2014 提高组] 生活大爆炸版石头剪刀布