Codeforces Global Round 2 .G题解

G. Get Ready for the Battle

借鉴网上的一种构思非常巧妙的方法。

首先我们的N如果很大,那我们只要让每个A[i]=Hp[i]就行了,然后一轮就解决,但是N<=M,每次的方案模糊。

我们希望一种方案,使得每一轮每次攻击都是“扎实的”,所谓扎实的就是每次攻击A[i]<=某个攻击的Hp[j],且又满足和为n的条件,那么只需要使Ki=(\sum_{j=1}^{i}hp[j]) \: mod\: n,且ki=0,km=n,然后排序求差分就能保证一定满足上面条件。然后暴力模拟即可。

#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000005;

int n,m,t[N],ss,a[N],v[N],sz[N],ans[N*2],tot;

int main(){
	int i,j,x,y,z;
    scanf("%d%d",&n,&m);
    for(i=1;i<=m;i++) {
    	scanf("%d",&t[i]);
    	ss+=t[i];v[i]=ss%n;
        }v[m]=n;
	sort(v,v+m+1);
	for(i=1;i<=m;i++) sz[i]=v[i]-v[i-1];

	for(i=1,j=1;i<=m;i++){
		x=t[i];
		for(;x>0;){
			ans[++tot]=i;
			x-=sz[j];
			j=(j==m)?1:(j+1); 
		}
	}
	while(tot%m>0) ans[++tot]=1;
	printf("%d\n",tot/m);	
	for(i=1;i<=m;i++) printf("%d ",sz[i]);
	puts("");
	for(i=1;i<=tot;i++){
		printf("%d ",ans[i]);	
		if(!(i%m)) puts("");
	}
//	for(;;);
	return 0;
} 

猜你喜欢

转载自blog.csdn.net/u014713777/article/details/89215384
今日推荐