【补题】Codeforces 1065: Educational Round 52 (Rated for Div. 2) ABCD

我是智障吗?2e5的数据范围看成1e9然后卡了一个半小时???

总结

  1. 认真读题,做题有困难时再读一遍题,注意各个常数是否读错。

A. Vasya and Chocolate 数学

饼干单价c元,买a赠b,现在有n元,问最多可以获得多少块饼干。

先降维(减少变量数),最多买p=n/c块饼干,所以最多获得p/a*(a+b)+p%a块。

B. Vasya and Isolated Vertices 图论,构造

定义孤点为度数为0的点,现在给定点数n与边数m,要求构造一个简单无向图,求最多与最少的孤点数。

如果要求孤点最少,把每条边都连接两个孤点。答案是max(n-m*2,0)
如果要求孤点最多,尽量去连完全图。答案是n-k,其中k表示m条边最少使用的点数。

ll n = read(), m=read();
ll k=0; for(;k*(k-1)/2<m;++k); //m条边最少使用的点数
printf("%I64d %I64d\n",max(n-2*m,0ll),max(0,n-k) );

C. Make It Equal 贪心

题意不想说了,难受。

记录原位置,逐层试探。

/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std; using ll = long long; inline int read();
const int M = 500016, MOD = 1000000007;

int save[M];
int main(void)
{
	#ifdef _LITTLEFALL_
	freopen("in.txt","r",stdin);
    #endif

	int n = read(), k = read();
	int low = INT_MAX, hei = INT_MIN;
	for(int i=1;i<=n;++i)
	{
		int v = read();
		++save[v];
		low = min(low,v);
		hei = max(hei,v);
	}
	int ans = 0;
	int pp = 0; //已被切的数量
	while(hei!=low)
	{
		int nh = hei;
		int s=0;
		while(nh > low && s+(pp+save[nh])<=k)
			s+=pp+=save[nh--];
		//slice
		++ans;
		hei = nh;
	}
	printf("%d\n",ans );

    return 0;
}


inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

D. Three Pieces 建图,编码

有一个n*n(10)的棋盘,每个格子都标着一个数字,这些数字是1到n*n的排列。你有三个国际象棋棋子:车、马、象,初始时选择一个棋子放在标1的格子里,要依次经过2,3,4,…n*n,每个格子可以走若干次。每走完一步可以更换棋子,更换棋子也算作一步。输出最少的步数以及在最少步数下最少的更换棋子次数。

一道编码题(?)
因为最多100个格子,3种棋子,只有300个状态,完全可以把任意两个状态之间需要的步数与更换次数预处理出来。
状态编码 s t = ( x − 1 ) ∗ 3 ∗ n + ( y − 1 ) ∗ 3 + r o l st = (x-1)*3*n+(y-1)*3+rol st=(x1)3n+(y1)3+rol,距离编码 s t e p ∗ 1000 + c h a n g e step*1000+change step1000+change
然后floyd即可。

全部预处理出来后使用dp即可求出最优解。

写这个题的时候心态爆炸,变量名写错愣是没查出来。

/* LittleFall : Hello! */
#include <bits/stdc++.h>
using namespace std; using ll = long long; inline int read();
const int M = 500016, MOD = 1000000007;

int n;
const int hgo[8][2] = {{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1},{-1,2}};
ll dis[324][324]; 
//状态编码:(x-1)*3*n+(y-1)*3+rol, rol 0车1马2象
//距离编码:step*1000+change 
inline int ms(int x,int y,int rol)
{
	return (x-1)*3*n+(y-1)*3+rol;
}
ll dp[128][3];
int ch[128];
int main(void)
{
	#ifdef _LITTLEFALL_
	freopen("in.txt","r",stdin);
    #endif

	memset(dis,0x3f,sizeof(dis));
	n = read();
	int ast = n*n*3; //总点数
	//建图
	for(int pnt=0;pnt<ast;++pnt)
	{
		int rol = pnt%3, x = pnt/3/n+1, y = pnt/3%n+1;
		if(rol==0)
		{
			for(int nx=1;nx<=n;++nx)
				dis[pnt][ms(nx,y,rol)] = 1000;
			for(int ny=1;ny<=n;++ny)
				dis[pnt][ms(x,ny,rol)] = 1000;
		}
		else if(rol==1)
		{
			for(int k=0;k<8;++k)
			{
				int nx = x + hgo[k][0], ny = y + hgo[k][1];
				if(nx>=1&&nx<=n&&ny>=1&&ny<=n)
					dis[pnt][ms(nx,ny,rol)] = 1000;
			}
		}
		else if(rol==2)
		{
			int sum = x+y, sub = x-y;
			for(int nx=1;nx<=n;++nx)
			{
				int ny = sum-nx;
				if(ny>=1&&ny<=n)
					dis[pnt][ms(nx,ny,rol)] = 1000;
				ny = nx-sub;
				if(ny>=1&&ny<=n)
					dis[pnt][ms(nx,ny,rol)] = 1000;
			}
		}
		for(int nr=0;nr<3;++nr)
			dis[pnt][ms(x,y,nr)] = 1001;
		dis[pnt][pnt] = 0;
	}
	//floyd
	for(int k=0;k<ast;++k)
		for(int i=0;i<ast;++i)
			for(int j=0;j<ast;++j)
				dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]);

	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			ch[read()] = (i-1)*n+j-1;

	memset(dp,0x3f,sizeof(dp));
	dp[ch[1]][0]=dp[ch[1]][1]=dp[ch[1]][2]=0;

	ll ans = LLONG_MAX;
	for(int i=2;i<=n*n;++i)
	{
		for(int rol=0;rol<3;++rol)
		{
			for(int lr=0;lr<3;++lr)
			{
				dp[ch[i]][rol] = min(dp[ch[i]][rol],dp[ch[i-1]][lr]+dis[ch[i]*3+rol][ch[i-1]*3+lr]);
				if(i==n*n)
					ans = min(ans,dp[ch[i]][rol]);
			}
		}
	}
	printf("%I64d %I64d\n",ans/1000,ans%1000 );
    return 0;
}


inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"educational codeforces round 103 (rated for div. 2)"是一个Codeforces平台上的教育性比赛,专为2级选手设计评级。以下是有关该比赛的回答。 "educational codeforces round 103 (rated for div. 2)"是一场Codeforces平台上的教育性比赛。Codeforces是一个为程序员提供竞赛和评级的在线平台。这场比赛是专为2级选手设计的,这意味着它适合那些在算法和数据结构方面已经积累了一定经验的选手参与。 与其他Codeforces比赛一样,这场比赛将由多个问题组成,选手需要根据给定的问题描述和测试用例,编写程序来解决这些问题。比赛的时限通常有两到三个小时,选手需要在规定的时间内提交他们的解答。他们的程序将在Codeforces的在线评测系统上运行,并根据程序的正确性和效率进行评分。 该比赛被称为"educational",意味着比赛的目的是教育性的,而不是针对专业的竞争性。这种教育性比赛为选手提供了一个学习和提高他们编程技能的机会。即使选手没有在比赛中获得很高的排名,他们也可以从其他选手的解决方案中学习,并通过参与讨论获得更多的知识。 参加"educational codeforces round 103 (rated for div. 2)"对于2级选手来说是很有意义的。他们可以通过解决难度适中的问题来测试和巩固他们的算法和编程技巧。另外,这种比赛对于提高解决问题能力,锻炼思维和提高团队合作能力也是非常有帮助的。 总的来说,"educational codeforces round 103 (rated for div. 2)"是一场为2级选手设计的教育性比赛,旨在提高他们的编程技能和算法能力。参与这样的比赛可以为选手提供学习和进步的机会,同时也促进了编程社区的交流与合作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值