首页 > 其他分享 >PYYZ 8.8

PYYZ 8.8

时间:2023-08-08 21:45:38浏览次数:41  
标签:ch ty int 8.8 long PYYZ define dis

8.8

比赛

80%瓜分率

A

写了个dfs荣获40pts

bfs

然后同时开一个数组 \(dis\), \(dis[i][j]\) 表示目前到 \(i, j\) 所需的最小步数

若bfs时发现枚举到的状态的dis值已经小于当前位置dis值,则无需加入队列

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define gt getchar
#define pt putchar
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=gt();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=gt();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=gt();}
    return x*f;}
inline void print(ll x){if(x<0)pt('-'),x=-x;if(x>9)print(x/10);pt(x%10+48);}
bool mp[1005][1005];
int dis[1005][1005];
int sx, sy, tx, ty, n, m, k;
int res;
struct node
{
	int x, y;
};
inline void dfs()
{
	memset(dis, 0x3f, sizeof dis);
	dis[sx][sy] = 0;
	res = dis[0][0];
	queue<node> Q;
	Q.push({sx, sy});
	while(Q.size())
	{
		node now = Q.front();Q.pop();
		int x = now.x, y = now.y;
		for(int i = 1; i <= k; ++ i)
		{
			int tx = x + i, ty = y;
			if (tx < 1 || tx > n || ty < 1 || ty > m) break;
			if (dis[tx][ty] <= dis[x][y]) break;
			if (mp[tx][ty] == 0) break;
			if (dis[tx][ty] == res) {
				dis[tx][ty] = dis[x][y] + 1;
				Q.push({tx, ty});					
			}
		}
		for(int i = 1; i <= k; ++ i)
		{
			int tx = x, ty = y + i;
			if (tx < 1 || tx > n || ty < 1 || ty > m) break;
			if (dis[tx][ty] <= dis[x][y]) break;
			if (mp[tx][ty] == 0) break;
			if (dis[tx][ty] == res) {
				dis[tx][ty] = dis[x][y] + 1;
				Q.push({tx, ty});					
			}
		}
		for(int i = 1; i <= k; ++ i)
		{
			int tx = x - i, ty = y;
			if (tx < 1 || tx > n || ty < 1 || ty > m) break;
			if (dis[tx][ty] <= dis[x][y]) break;
			if (mp[tx][ty] == 0) break;
			if (dis[tx][ty] == res) {
				dis[tx][ty] = dis[x][y] + 1;
				Q.push({tx, ty});					
			}
		}
		for(int i = 1; i <= k; ++ i)
		{
			int tx = x, ty = y - i;
			if (tx < 1 || tx > n || ty < 1 || ty > m) break;
			if (dis[tx][ty] <= dis[x][y]) break;
			if (mp[tx][ty] == 0) break;
			if (dis[tx][ty] == res) {
				dis[tx][ty] = dis[x][y] + 1;
				Q.push({tx, ty});					
			}
		}
	}
	return ;
}

int main()
{
	//freopen("expedition.in", "r", stdin);
	//freopen("expedition.out", "w", stdout);
	n = read(), m = read(), k = read();
	bool bj = 1;
	for(int i = 1; i <= n; ++ i)
		for(int j = 1; j <= m; ++ j)
		{
			char c;
			cin >> c;
			if(c == '.')mp[i][j] = 1;
			if(c == '#')bj = 0;
		}
	sx = read(), sy = read(), tx = read(), ty = read();
	dfs();
	if(dis[tx][ty] == res)return cout << -1, 0;
	cout << dis[tx][ty];
	return 0;
}

B

赛时大体思路出来了,但是没想到优先队列

开优先队列,然后不断找最小的两个判断是否合并

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define gt getchar
#define pt putchar
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=gt();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=gt();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=gt();}
    return x*f;}
inline void print(ll x){if(x<0)pt('-'),x=-x;if(x>9)print(x/10);pt(x%10+48);}
ll a[150005];
struct node
{
	ll v;
	int id;
    friend bool operator < (node x, node y){
        if(x.v != y.v) return x.v > y.v;
        return x.id > y.id;
    }
};
priority_queue<node> Q;
int main()
{
	int n = read();
	for(int i = 1; i <= n; ++ i)a[i] = read(), Q.push({a[i], i});
	node x, y;
	while(!Q.empty())
	{
		x = Q.top();Q.pop();
        if(Q.empty())break;
		y = Q.top();Q.pop();
        //cout<<x.v<<' '<<y.v<<endl;
		if(x.v == y.v)
		{
			Q.push({x.v + y.v, y.id});
			a[x.id] = -1, a[y.id] = a[y.id] + a[y.id];
			
		}
		else Q.push(y);
	}
	int k = 0;
	for(int i = 1; i <= n; ++ i)if(a[i] != -1)++ k;
	cout << k << '\n';
	for(int i = 1; i <= n; ++ i)if(a[i] != -1)cout << a[i] << ' ';
	return 0;
}

C

赛时乱搞了一个贪心,寄了

结果是状压

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define gt getchar
#define pt putchar
using namespace std;
inline ll read(){
    ll x=0,f=1;char ch=gt();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=gt();}
    while(isdigit(ch)){x=(x<<1)+(x<<3)+(ch^48);ch=gt();}
    return x*f;}
inline void print(ll x){if(x<0)pt('-'),x=-x;if(x>9)print(x/10);pt(x%10+48);}
int a[25][25];
int f[1 << 20];
int main()
{
	int n = read();
	for(int i = 1; i <= n; ++ i)
		for(int j = 1; j <= n; ++ j)
			a[i][j] = read();
	for(int i = 0; i < (1 << n); ++ i)
	{
		for(int j = 1; j <= n; ++ j)
		{
			if((i >> (j - 1)) & 1 == 1){
				int sum = 0;
				for(int k = 1;k <= n; ++ k)
				{
					if((i >> (k - 1)) & 1)sum += a[k][j];
				}
				f[i] = max(f[i], f[i ^ (1 << (j - 1))] + sum);
			}
		}
	}
	cout << f[(1 << n) - 1];
	return 0;
}
/*

*/

D

倍增lca,然后利用lca做一个类似的数组,只不过存的是前k小,然后暴力合并

代码等补

E

还没会

标签:ch,ty,int,8.8,long,PYYZ,define,dis
From: https://www.cnblogs.com/qinzh/p/17615461.html

相关文章

  • 闲话8.8
    今天放假了捏,舒服早上睡到9点20......
  • 8.8《天道》观后感
    电视剧《天道》中展示了格律诗乐器的制作过程,让我们深入了解这门古老艺术的经典之道。在这篇博客中,我们将探讨格律诗乐器的生产流程及其质量控制流程,并结合软件工程专业的知识,提取出一些有启示性的经验。让我们一起走进这个古老而神奇的世界。第一部分:格律诗乐器的生产流程需求......
  • 2023.8.8 周二:replace All
    1/*2输入格式:3输入在一行中给出一句话,即一个非空字符串,由不超过1000个英文字母、数字和空格组成,以回车结束。45输出格式:6从左到右扫描输入的句子:如果句子中有超过3个连续的6,则将这串连续的6替换成9;但如果有超过9个连续的6,则将这串连续的6替换成27......
  • 8.8
    #include<cstdio>#include<cstring>#include<string>#include<math.h>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<map>#include<set>#include<stack>#i......
  • 8.8下午 电极及出图(做直角的位置)-如果有的面删除不了的话用拉伸(改里面的实体及公差)
      ......
  • 2023.8.8
    P4310绝世好题首先可以想到的90pts做法是最长上升子序列dp,然后就考虑一下优化。这个做法要进行的转移过多,我们考虑怎么减少转移次数。由&运算我们可以发现,能转移到当前数的\(a[j]\),必然和当前数\(a[i]\)至少有一个二进制数位上同时为1。因此我们就可以定义\(bit[i]\)......
  • docker-compose快速部署elasticsearch-8.8.1集群+kibana+logstash
    安装环境centos7.98cpu16G内存vda50Gvdb100G如果您的环境是Linux,注意要做以下操作,否则es可能会启动失败用编辑工具打开文件/etc/sysctl.conf在尾部添加一行配置vm.max_map_count=262144,如果已存在就修改,数值不能低于262144修改保存,然后执行命令sudosysctl-p使其立即......
  • anolis 8.8 (CentOS 8) 环境下搭建青岛大学OJ
    #yum-yinstallpython3-pip  //systemreplied:Packagepython3-pip-9.0.3-22.an8.noarchisalreadyinstalled.#pipinstalldocker-compose //systemreplied:  bash:pip:commandnotfound...#whereispip //systemreplied:  pip:/usr/bin/pip3.6#cd/u......
  • Anolis 8.8 (CentOS 8) install snapper to support system snapshot.
    Anolis8.8(CentOS8)installsnappertosupportsystemsnapshot.cd/etc/yum.repos.d/wgethttps://download.opensuse.org/repositories/filesystems:snapper/CentOS_8/filesystems:snapper.repoyuminstallsnappersudoyuminstallpython3python3-setuptools......
  • 1.安装Rocky8.8 Ubuntu20.04版本中遇到的一些问题
    1.VMware的监视器看不到Rocky的全部图像,所以我在安装过程中改变了监视器的最大分辨率,这样不会影响系统的功能吧?2.Ubuntu系统安装中Instalcomplete界面中有个rooting运行中,我直接关机,又开机,影响不影响系统完整?3.在VMware中Ubuntu系统root登录的密码与XShell中Ubuntu系统root登录......