AtCoder Beginner Contest 159

前言

第一次0失误AK Atcoder比赛,真是太爽了.

正题

题目

  1. 题意:选两个数的和为偶数.
    只需选的数奇偶性相同即可.
  2. 暴力判断回文串
  3. 均值不等式. a n s = ( L / 3 ) 3 ans=(L/3)^3
  4. 暴力去除影响.用个桶即可.
  5. 行数那么少,暴力搜行的切割方法.然后扫描列,对于一定要切的地方就切.复杂度 O ( 2 n m ) O(2^n*m)
  6. 背包.设 x 1 , x 2 , . . . . . . x k ( x 1 < x 2 < . . . . x k ) i = 1 k a [ x i ] = m , x 1 ( n x k + 1 ) x_1,x_2,......x_k(x_1<x_2<....x_k)满足\sum_{i=1}^k a[x_i]=m,则对答案的贡献为x_1*(n-x_k+1)
    显然,我们只关心 i = 1 k 1 a [ x i ] \sum_{i=1}^{k-1} a[x_i] 的总和及起始位置的总和.那么背包很好就能解决这样的问题,因为每次我们要把 f [ j ] f [ j + a [ i ] ] . f[j]贡献到f[j+a[i]].
    定义状态 f [ i ] i f[i]表示总和为i的所有方案的起始位置总和 .然后 O ( n 2 ) O(n^2) 爆踩过去就行啦~

请自行忽略无用的缺省源.

A A

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int main() {
	int n,m; qr(n); qr(m);
	pr2((n*(n-1)+m*(m-1))>>1); 
	return 0;
}

B B

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

char s[N];
int n;

bool check(char *a,int len) {
	for(int i=0;i<len;i++)
		if(a[i]^a[len-i-1]) return 0;
	return 1;
}

bool pd() {
	if((n&1)==1||n==0) return 0;
	int m=n>>1;
	return check(s,n+1)&&check(s,m)&&check(s+m+1,m);
}
	
int main() {
	scanf("%s",s); n=strlen(s)-1;
	puts(pd()?"Yes":"No");
	return 0;
}

C C

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

long double a;

int main() {
	qr(a); a/=3.0;
	printf("%12LF\n",a*a*a);
	return 0;
}

D D

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,a[N];
ll cnt[N];
ll ans;

int main() {
	qr(n);
	for(int i=1;i<=n;i++) qr(a[i]),ans+=cnt[a[i]]++;
	for(int i=1;i<=n;i++) pr2(ans-(cnt[a[i]]-1));
	return 0;
}

E E

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1010,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,k,ans,sum[14][N],a[14];
char s[N];

void solve(int tot) {
	int l=0,tmp=tot-1,mx;
	for(int i=1;i<=m&&tmp<ans;i++) {
		mx=0;
		for(int j=1;j<=tot;j++) 
			mx=max(mx,sum[a[j]][i]+sum[a[j-1]][l]-sum[a[j-1]][i]-sum[a[j]][l]);
		if(mx>k) {
			if(l==i-1) return ;
			l=i-1; tmp++;
		}
	}
	if(l==m-1) {
		mx=0;
		for(int j=1;j<=tot;j++) 
			mx=max(mx,sum[a[j]][m]+sum[a[j-1]][l]-sum[a[j-1]][m]-sum[a[j]][l]);
		if(mx>k) return ;
	}
	ans=min(ans,tmp);
}
		

void dfs(int i,int s) {
	if(s>=ans) return ;
	int j;
	for(j=i;sum[j+1][m]-sum[i-1][m]<=k&&j<n;j++);//隔断j,j+1行 
	for(   ;j<n;j++) 
		a[s+1]=j,dfs(j+1,s+1);
	a[s+1]=n; solve(s+1);
}

int main() {
	qr(n); qr(m); qr(k);
	for(int i=1;i<=n;i++) {
		scanf("%s",s+1);
		for(int j=1;j<=m;j++) sum[i][j]=sum[i][j-1]+s[j]-'0';
		for(int j=1;j<=m;j++) sum[i][j]+=sum[i-1][j];
	} 
	ans=n-2+m; dfs(1,0);  pr2(ans);
	return 0;
}

F F

#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
const int N=3010,size=1<<20,mod=998244353;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m;
ll f[N],ans;

int main() {
	qr(n); qr(m); 
	for(int i=1,x;i<=n;i++) {
		qr(x); f[0]++; if(x>m) continue;
		ans+=1LL*(n-i+1)*f[m-x]%mod;
		for(int j=m-x;j>=0;j--) (f[j+x]+=f[j])%=mod;
	}
	pr2(ans%mod);
	return 0;
}

发布了71 篇原创文章 · 获赞 88 · 访问量 5433

猜你喜欢

转载自blog.csdn.net/qq_42886072/article/details/105036362
今日推荐