Codeforces Round #342(Div.2)


不要偷懒不要偷懒不要偷懒重要的事情说三遍


#include<cstdio>
long long n,a,b,c,ans;
int main(){
	scanf("%I64d%I64d%I64d%I64d",&n,&a,&b,&c);
	if(b-c>=a&&b>=a){
		printf("%I64d",n/a);
		return 0;
	}
	long long t=0;
	if(n>=b){
		ans+=t=(n-b)/(b-c);
		n-=(b-c)*t;
	}
	if(n>=b)n-=b,n+=c,ans++;
	ans+=n/a;
	printf("%I64d",ans);
}

#include<cstdio>
#include<iostream>
#include<queue>
#include<cstring>
using namespace std;
queue<int> q;
int ans,na,nb;
char a[100010],b[100010];
int nextt[100010];
int main(){
	scanf("%s%s",a+1,b+1);
	na=strlen(a+1);
	nb=strlen(b+1);
	int j=0;
	for(int i=2;i<=nb;i++)
	{
		while(j>0&&b[j+1]!=b[i])j=nextt[j];
		if(b[j+1]==b[i])j++;
		nextt[i]=j;
	}
	j=0;
	for(int i=1;i<=na;i++)
	{
		while(j>0&&b[j+1]!=a[i])j=nextt[j];
		if(b[j+1]==a[i])j++;
		if(j==nb)q.push(i-nb),j=nextt[j];
	}
	int t=-10000000;
	while(!q.empty()){
		if(t+nb>q.front())q.pop();
		else ans++,t=q.front();
	}
	cout<<ans;
}

#include<cstdio>
int k,n,now,ans;
int t[509][509];
int main(){
	scanf("%d%d",&n,&k);
	now=n*n;
	for(int i=1;i<=n;i++){
		for(int j=n;j>=k;j--){
			t[i][j]=now--;
			if(j==k)ans+=now+1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=k-1;j>=1;j--){
			t[i][j]=now--;
		}
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)printf("%d ",t[i][j]);
		printf("\n");
	}
}

 

此条目发表在Codeforces分类目录。将固定链接加入收藏夹。