AcWing第 55 场周赛

115 篇文章 3 订阅
20 篇文章 0 订阅

4479. 最长子序列

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,m;
void solve()
{
	cin>>n>>m;
	vector<int>v1,v2;
	for(int i=0;i<n;i++)
	{
	    int x;
	    cin>>x;
	    v1.pb(x);
	}
	for(int i=0;i<m;i++)
	{
	    int x;
	    cin>>x;
	    v2.pb(x);
	}
	unordered_map<int,int>mp;
	for(auto x:v2)mp[x]++;
	for(auto x:v1)
		if(mp.count(x))cout<<x<<' ';
	cout<<endl;
}
signed main()
{
	io;
//	cin>>_;
//	while(_--)
	solve();
	return 0;
}

4480. 倒垃圾

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int n,m;
const int N=2e5+10;
int one[N],zero[N],a[N];
int res[N];
void solve()
{
	cin>>n>>m;
	for(int i=0;i<n+m;i++)cin>>a[i];
	int cnt1=0,cnt2=0;
	for(int i=0;i<n+m;i++)
	{
		int x;
		cin>>x;
		if(x==1)one[++cnt1]=a[i];
		else zero[++cnt2]=a[i];
	}
	one[0]=-ll_INF,one[cnt1+1]=ll_INF;
	for(int i=1;i<=cnt2;i++)
	{
		int l=0,r=cnt1+1;
		while(l<r)
		{
			int mid=l+r>>1;
			if(one[mid]>=zero[i])r=mid;
			else l=mid+1;
		}
		if(zero[i]-one[r-1]<=one[r]-zero[i])res[r-1]++;
		else res[r]++;
	}
	for(int i=1;i<=m;i++)cout<<res[i]<<' ';
	cout<<endl;
}
signed main()
{
	io;
//	cin>>_;
//	while(_--)
	solve();
	return 0;
}

4481. 方格探索

#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
#define x first
#define y second
#define LL long long 
#define int LL
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define PII pair<int,int>
#define ll_INF 0x7f7f7f7f7f7f7f7f
#define INF 0x3f3f3f3f
#define debug(x) cerr << #x << ": " << x << endl
#define io ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
LL Mod(LL a,LL mod){return (a%mod+mod)%mod;}
LL lowbit(LL x){return x&-x;}//最低位1及其后面的0构成的数值
LL qmi(LL a,LL b,LL mod) {LL ans = 1; while(b){ if(b & 1) ans = ans * (a % mod) % mod; a = a % mod * (a % mod) % mod; b >>= 1;} return ans; }
int _;
int dx[4]={-1, 0, 1, 0};
int dy[4]={0, 1, 0, -1};
int n,m;
int r,c;
int x,y;
const int N=2010;
char g[N][N];
int dist[N][N];
bool st[N][N];
void bfs()
{
	memset(dist,0x3f,sizeof dist);
	dist[r][c]=0;
	deque<PII>q;
	q.push_back({r,c});
	while(q.size())
	{
		auto t=q.front();
		q.pop_front();
		if(st[t.x][t.y])continue;
		st[t.x][t.y]=true;
		for(int i=0;i<4;i++)
		{
			int x=dx[i]+t.x,y=dy[i]+t.y;
			if(x<=0||x>n||y<=0||y>m)continue;
			if(g[x][y]=='*')continue;
			int w=0;
			if(i==1)w=1;
			if(dist[x][y]>dist[t.x][t.y]+w)
			{
				dist[x][y]=dist[t.x][t.y]+w;
				if(w)q.push_back({x,y});
				else q.push_front({x,y});
			}
		}
	}
}
void solve()
{
	cin>>n>>m>>r>>c>>x>>y;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>g[i][j];
	bfs();
	int res=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			int b=dist[i][j];
			if(b<=y&&b-(j-c)<=x)res++;
		}
	}
	cout<<res<<endl;
}
signed main()
{
	io;
//	cin>>_;
//	while(_--)
	solve();
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

leimingzeOuO

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值