[ABC185] AtCoder Beginner Contest 185

AtCoder Beginner Contest 185.


Task Name Time Limit Memory Limit
A ABC Preparation 2 sec 1024 MB Submit
B Smartphone Addiction 2 sec 1024 MB Submit
C Duodecim Ferra 2 sec 1024 MB Submit
D Stamp 2 sec 1024 MB Submit
E Sequence Matching 2 sec 1024 MB Submit
F Range Xor Query 3 sec 1024 MB Submit

A

#pragma GCC optimize(2)
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int INF=0x3f3f3f3f;

int main()
{
//	freopen("1.in","r",stdin);
	
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	a=min(a,b);
	a=min(a,c);
	a=min(a,d);
	cout<<a<<endl;
	return 0;
}

B

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int N=1024;

int n,m,t;

int main()
{
//	freopen("1.in","r",stdin);
	int i;
	int x,y;
	
	int last=0;
	cin>>n>>m>>t;
	int lit=n;
	for(i=1;i<=m;i++) {
		cin>>x>>y;
		n-=(x-last);
		if(n<=0) {
			printf("No\n");
			return 0;
		}
		n+=(y-x);
		if(n>lit) n=lit;
		last=y;
	}
	
	n-=(t-last);
	if(n<=0) printf("No\n");
	else printf("Yes\n");
	
	return 0;
}

C

\(C_{L-1}^{11}\)

#pragma GCC optimize(2)
#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

// C(L-1,11)

const int N=256;

LL c[N][N];

int main()
{
//	freopen("1.in","r",stdin);
	int i,j;
	
	for(i=0;i<=N-1;i++) 
		for(j=0;j<=i;j++) {
			if(j==0||j==i) c[i][j]=1;
			else c[i][j]=c[i-1][j]+c[i-1][j-1];
		}
	
	int n;
	cin>>n;
	cout<<c[n-1][11];
	return 0;
}

D

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int N=4e5+5,INF=2e9;

int n,m,k=INF;
int a[N];

int paint(int len)
{
	return len/k+(len%k>0);
}

int main()
{
///	freopen("1.in","r",stdin);
	int i;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;i++) 
		scanf("%d",&a[i]);
	sort(a+1,a+m+1);
	a[++m]=n+1;
	for(i=1;i<=m;i++) {
		if(a[i]==a[i-1]+1) continue;
		k=min(k,a[i]-a[i-1]-1);
	}
	int ans=0;
	for(i=1;i<=m;i++) {
		if(a[i]==a[i-1]+1) continue;
		else ans+=paint(a[i]-a[i-1]-1);
	}
	cout<<ans<<endl;
	
	return 0;
}

E

\(n^3\) 竟然可过,这 Atcoder 神机。

不过后来又被我优化成了 \(O(n^2)\) 了。

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int N=1024,INF=0x3f3f3f3f;

int f[N][N];
int n,m;
int a[N],b[N];
int g1[N],g2[N];

int main()
{
//	freopen("1.in","r",stdin);
	int i,j;
	
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<=m;i++) scanf("%d",&b[i]);
	
	memset(f,0x3f,sizeof f);
	int ans=INF;
	f[0][0]=0;
	for(j=0;j<=m;j++) g2[j]=f[0][j]-0-1;
	for(i=1;i<=n;i++) {
		g1[0]=f[i-1][0]-0-1;
		for(j=1;j<=m;j++) 
			g1[j]=min(g1[j-1],f[i-1][j]-j-1);
			
		for(j=1;j<=m;j++) {
			// f[i][j]= min{ f[k][p]+(j-p-1)+(i-k-1)} + (a[i]!=a[j])
			// f[i-1][j-1] = max { f[k][p]+(j-p-1)+(i-k-1) ) - 2 + (a[i-1]!=a[j-1]);
			
			f[i][j]=f[i-1][j-1]-(a[i-1]!=b[j-1])+2+(a[i]!=b[j]);
			// else f[i-1][k from 0 to j-1]
//			for(int k=0;k<=j-1;k++) 
//				f[i][j]=min(f[i][j],f[i-1][k]+(j-k-1)+(a[i]!=b[j]));
			f[i][j]=min(f[i][j],g1[j-1]+j+(a[i]!=b[j]));
			
//			for(int k=0;k<=i-1;k++) 
//				f[i][j]=min(f[i][j],f[k][j-1]+i-k-1+(a[i]!=b[j]));
			f[i][j]=min(f[i][j],g2[j-1]+i+(a[i]!=b[j]));
			
			ans=min(ans,f[i][j]+(n-i)+(m-j));
		}
		for(j=0;j<=m;j++) 
			g2[j]=min(g2[j],f[i][j]-i-1);
	}
	
	cout<<ans<<endl;
	return 0;
}

话说我状态定义想偏了,要是换一个可能更好些。

F

#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

const int N=3e5+5;

int n,m;
struct Bits
{
	int c[N];
	inline int lowbit(int x) { return x&(-x); }
	void Update(int x,int y)
	{
		for(;x<=n;x+=lowbit(x)) 
			c[x]^=y;
	}
	int Sum(int x)
	{
		int res=0;
		for(;x>=1;x-=lowbit(x)) 
			res^=c[x];
		return res;
	}
}C;

int main()
{
//	freopen("1.in","r",stdin);
	int i;
	int opt,x,y;
	
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++) {
		scanf("%d",&x);
		C.Update(i,x);
	}
	
	while(m--) {
		scanf("%d%d%d",&opt,&x,&y);
		if(opt==1) C.Update(x,y);
		else printf("%d\n",C.Sum(x-1)^C.Sum(y));
	}
	return 0;
}

维护一个前缀异或和。

posted @ 2020-12-13 22:27  cjlworld  阅读(369)  评论(0编辑  收藏  举报