首页 > 其他分享 >The Last Battle —— 2023~2024 赛季考场代码合辑

The Last Battle —— 2023~2024 赛季考场代码合辑

时间:2023-11-02 16:47:23浏览次数:46  
标签:Last int 合辑 mid long 2024 textrm ans include

\[\Huge\mathfrak{CSP - S 2023} \]

\[{\color{orange}\textrm{340}}\textrm{ / 400} \]

\(\textrm{A}\;\text{密码锁}\)
\({\color{limegreen}\textrm{100}}\textrm{ / 100}\)

\(\textrm{We decide.}\)
\(\textrm{We choose.}\)
\(\textrm{As we decide and choose, so are our lives formed.}\)
\(\textrm{In the end, forming our own destiny is what ambition is about.}\)

点击查看代码
/*
We decide.
We choose.
As we decide and choose, so are our lives formed.
In the end, forming our own destiny is what ambition is about.
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 8, V = 1e5;

int n;
int cnt[V + 5];
int a[10], b[10];

int vis[V + 5], dfn;
void cpy()
{
	for (int i = 1; i <= 5; i++)
		b[i] = a[i];
	return ;
}
int calc()
{
	int res = 0;
	for (int i = 1; i <= 5; i++)
		res = res * 10 + b[i];
	return res;
}

int main()
{
	freopen("lock.in", "r", stdin);
	freopen("lock.out", "w", stdout);

	scanf("%d", &n);
	for (int T = 1; T <= n; T++)
	{
		for (int i = 1; i <= 5; i++)
			scanf("%d", a + i);

		dfn++;
		for (int i = 1; i <= 5; i++)
		{
			for (int x = 1; x <= 9; x++)
			{
				cpy();
				b[i] = (b[i] + x) % 10;
				vis[calc()] = dfn;

				cpy();
				b[i] = (b[i] + 10 - x) % 10;
				vis[calc()] = dfn;
			}
		}

		for (int i = 1; i < 5; i++)
		{
			for (int x = 1; x <= 9; x++)
			{
				cpy();
				b[i] = (b[i] + x) % 10;
				b[i + 1] = (b[i + 1] + x) % 10;
				vis[calc()] = dfn;

				cpy();
				b[i] = (b[i] + 10 - x) % 10;
				b[i + 1] = (b[i + 1] + 10 - x) % 10;
				vis[calc()] = dfn;
			}
		}

		for (int i = 0; i < V; i++)
			cnt[i] += (vis[i] == dfn);
	}

	int ans = 0;
	for (int i = 0; i < V; i++)
		ans += (cnt[i] == n);
	printf("%d\n", ans);
	return 0;
}

\(\textrm{B}\;\text{消消乐}\)
\({\color{limegreen}\textrm{100}}\textrm{ / 100}\)

\(\textrm{I believe that I am who I am}\)
\(\textrm{Unique and unstoppable}\)
\(\textrm{Not afraid of loneliness}\)
\(\textrm{Not afraid of wind and waves}\)

点击查看代码
/*
I believe that I am who I am
Unique and unstoppable
Not afraid of loneliness
Not afraid of wind and waves
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;

const int N = 2e6, V = 26;

int n;
int a[N + 5];

int match[N + 5], cnt[N + 5];
int lst[N + 5][V + 5];

int main()
{
	freopen("game.in", "r", stdin);
	freopen("game.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		char c;
		scanf(" %c", &c);
		a[i] = c - 'a' + 1;
	}

	for (int i = 1; i <= n; i++)
	{
		match[i] = lst[i - 1][a[i]];
		if (match[i])
		{
			cnt[i] = cnt[match[i] - 1] + 1;
			for (int j = 1; j <= V; j++)
				lst[i][j] = lst[match[i] - 1][j];
			lst[i][a[i]] = i;
		}
		lst[i][a[i]] = i;
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++)
		ans += cnt[i];
	printf("%lld\n", ans);
	return 0;
}

\(\textrm{C}\;\text{结构体}\)
\({\color{limegreen}\textrm{100}}\textrm{ / 100}\)

\(\textrm{Not enjoyment, and not sorrow}\)
\(\textrm{Is our destined end or way}\)
\(\textrm{But ot act, that each tomorrow}\)
\(\textrm{Finds us further than today}\)

点击查看代码
/*
Not enjoyment, and not sorrow
Is our destined end or way
But ot act, that each tomorrow
Finds us further than today
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;

const int N = 100;
const string Basic[4] = {"byte", "short", "int", "long"};

int n;

map<string, int> mp;
int tot;
int turn(string s)
{
	if (mp[s])
		return mp[s];
	mp[s] = ++tot;
	return tot;
}
long long Next(long long x, long long p)
{
	if (x % p == 0)
		return x;
	return x + p - x % p;
}

struct Child
{
	int type;
	string name;
	long long delta;
};

long long sz[N + 5], lim[N + 5];
vector<Child> g[N + 5];

string StructName;
int k;
string Type[N + 5], Name[N + 5];
void Init()
{
	for (int i = 0, j = 1; i < 4; i++, j <<= 1)
	{
		int p = turn(Basic[i]);
		sz[p] = lim[p] = j;
	}
	return ;
}
void NewStruct()
{
	int id = turn(StructName);
	for (int t = 1; t <= k; t++)
	{
		Child son;
		son.type = turn(Type[t]);
		son.name = Name[t];
		
		sz[id] = Next(sz[id], lim[son.type]);//head, 0 ~ (sz - 1)
		son.delta = sz[id];
		sz[id] += sz[son.type];

		lim[id] = max(lim[id], lim[son.type]);

		g[id].push_back(son);
	}
	sz[id] = Next(sz[id], lim[id]);

	printf("%lld %lld\n", sz[id], lim[id]);
	return ;
}

int ValueType[N + 5];
string ValueName[N + 5];
long long Head[N + 5];
int cnt;

int len;

string Query[N + 5];
void Cut()
{
	string s;
	cin >> s;

	len = 0;
	string temp = "";
	for (unsigned int i = 0; i < s.size(); i++)
	{
		if (s[i] == '.')
		{
			Query[++len] = temp;
			temp = "";
		}
		else
			temp += s[i];
	}
	Query[++len] = temp;
	return ;
}
long long GetAddress(int u, int id)
{
	for (unsigned int i = 0; i < g[u].size(); i++)
	{
		if (g[u][i].name != Query[id])
			continue;

		if (id == len)
			return g[u][i].delta;
		return g[u][i].delta + GetAddress(g[u][i].type, id + 1);
	}
	return 0ll;
}

string Path[N + 5];
bool HaveAns;
void FindPath(int u, long long beg, long long pos)
{
	if (g[u].empty())//Basic
	{
		HaveAns = true;
		return ;
	}

	for (unsigned int i = 0; i < g[u].size(); i++)
	{
		long long Begin = beg + g[u][i].delta;
		long long End = Begin + sz[g[u][i].type] - 1;
		if (!(Begin <= pos && pos <= End))
			continue;

		Path[++len] = g[u][i].name;
		FindPath(g[u][i].type, beg + g[u][i].delta, pos);
		break;
	}
	return ;
}

int main()
{
	freopen("struct.in", "r", stdin);
	freopen("struct.out", "w", stdout);

	scanf("%d", &n);

	Init();

	for (int T = 1, op; T <= n; T++)
	{
		scanf("%d", &op);

		if (op == 1)
		{
			cin >> StructName >> k;
			for (int i = 1; i <= k; i++)
				cin >> Type[i] >> Name[i];
			NewStruct();
		}

		if (op == 2)
		{
			cnt++;
			string _type;
			cin >> _type >> ValueName[cnt];
			ValueType[cnt] = turn(_type);

			if (cnt == 1)
				Head[cnt] = 0;
			else
				Head[cnt] = Next(Head[cnt - 1] + sz[ ValueType[cnt - 1] ],
								 lim[ ValueType[cnt] ]);

			printf("%lld\n", Head[cnt]);
		}

		if (op == 3)
		{
			Cut();
			long long pos = 0;
			for (int i = 1; i <= cnt; i++)
			{
				if (ValueName[i] != Query[1])
					continue;

				if (len == 1)
					pos = Head[i];
				else
					pos = Head[i] + GetAddress(ValueType[i], 2);
				break;
			}
			printf("%lld\n", pos);
		}

		if (op == 4)
		{
			long long addr;
			scanf("%lld", &addr);

			len = 0;
			HaveAns = false;
			for (int i = 1; i <= cnt; i++)
			{
				long long Begin = Head[i];
				long long End = Begin + sz[ValueType[i]] - 1;
				if (!(Begin <= addr && addr <= End))
					continue;

				Path[++len] = ValueName[i];
				FindPath(ValueType[i], Head[i], addr);
			}

			if (HaveAns)
			{
				cout << Path[1];
				for (int i = 2; i <= len; i++)
					cout << "." << Path[i];
				printf("\n");
			}
			else
				puts("ERR");
		}
	}
	return 0;
}

\(\textrm{D}\;\text{种树}\)
\({\color{orange}\textrm{40}}\textrm{ / 100}\)

\(\textrm{I shall be telling this with a sigh}\)
\(\textrm{Somewhere ages and ages hence}\)
\(\textrm{Two roads diverged in a wood, and I}\)
\(\textrm{I took the one less travelled by}\)
\(\textrm{And that has made all the difference}\)

考场 code

点击查看代码
/*
I shall be telling this with a sigh
Somewhere ages and ages hence
Two roads diverged in a wood, and I
I took the one less travelled by
And that has made all the difference
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;

const int N = 1e5, E = N << 1;
const long long Max = 1e9;

typedef pair<long long, int> pir;

int n;
long long a[N + 5], b[N + 5], c[N + 5], zero[N + 5];

int head[N + 5], to[E + 5], nxt[E + 5], tot = 1;
void add_edge(int u, int v)
{
	tot++;
	to[tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
	return ;
}
void add(int u, int v)
{
	add_edge(u, v);
	add_edge(v, u);
	return ;
}

long long d[N + 5];//limit
int sz[N + 5];

void calc_d(int u, long long ans)
{
	long long l = 1, r = ans;
	d[u] = Max * 100ll;
	while (l <= r)
	{
		long long mid = (l + r) >> 1, sum = 0;

		if (c[u] >= 0)
			sum = (ans - mid + 1) * b[u]
				 + (mid + ans) * (ans - mid + 1) / 2 * c[u];
		else
		{
			if (mid > zero[u])
				sum = ans - mid + 1;
			else
				sum = (zero[u] - mid + 1) * b[u]
					 + (mid + zero[u]) * (zero[u] - mid + 1) / 2 * c[u]
					 + ans - zero[u];
		}

		if (a[u] <= sum)
		{
			d[u] = mid;
			l = mid + 1;
		}
		else
			r = mid - 1;
	}
	return ;
}

// bool cmp(int x, int y)
// {
// 	if (d[x] + sz[x] != d[y] + sz[y])
// 		return d[x] + sz[x] < d[y] + sz[y];
// 	if (d[x] != d[y])
// 		return d[x] < d[y];
// 	return sz[x] < sz[y];
// }
// void dfs(int u, int fa)
// {
// 	vector<int> son;
// 	sz[u] = 1;

// 	for (int i = head[u]; i; i = nxt[i])
// 	{
// 		int v = to[i];
// 		if (v == fa)
// 			continue;
// 		dfs(v, u);
// 		sz[u] += sz[v];
// 		son.push_back(v);
// 	}

// 	if (son.empty())
// 		return ;
	
// 	sort(son.begin(), son.end(), cmp);
// 	long long sum = 0;
// 	for (unsigned int t = 0; t < son.size(); t++)
// 	{
// 		int v = son[t];
// 		d[u] = min(d[u], d[v] - 1 - sum);
// 		sum += sz[v];
// 	}
// 	return ;
// }

int fa[N + 5], in[N + 5];
void dfs(int u, int father)
{
	fa[u] = father;
	in[father]++;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = to[i];
		if (v == father)
			continue;
		dfs(v, u);
	}
	return ;
}

priority_queue<pir> q;
int seq[N + 5];
bool check(long long ans)
{
	for (int i = 1; i <= n; i++)
	{
		calc_d(i, ans);
		if (d[i] > Max)
			return false;
	}

	dfs(1, 0);
	for (int i = 1; i <= n; i++)
	{
		if (in[i] == 0)
			q.emplace(d[i], i);
	}

	for (int T = n; T > 0; T--)
	{
		int u = q.top().second;
		q.pop();
		seq[T] = u;

		if (fa[u])
		{
			in[fa[u]]--;
			if (in[fa[u]] == 0)
				q.emplace(d[fa[u]], fa[u]);
		}
	}

	

	// for (int i = 1; i <= n; i++)
	// {
	// 	cout << i << " " << d[i] << endl;
	// }
	// cout << endl;

	// for (int i = 1; i <= n; i++)
	// {
	// 	cout << seq[i] << " ";
	// }
	// cout << endl;




	// dfs(1, 0);


	
	// for (int i = 1; i <= n; i++)
	// {
	// 	cout << i << " " << d[i] << endl;
	// }
	// cout << endl;
	


	// if (d[1] < 1ll)
	// 	return false;
	// return true;

	for (int i = 1; i <= n; i++)
	{
		if (1ll * i > d[seq[i]])
			return false;
	}
	return true;

}

int main()
{
	freopen("tree.in", "r", stdin);
	freopen("tree.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld%lld%lld", a + i, b + i, c + i);
		if (c[i] < 0)
			zero[i] = (1ll - b[i]) / c[i];
	}
	for (int i = 1, u, v; i < n; i++)
	{
		scanf("%d%d", &u, &v);
		add(u, v);
	}


	// check(5);
	// exit(0);


	long long l = 1, r = Max, ans = 0;
	while (l <= r)
	{
		long long mid = (l + r) >> 1;
		if (check(mid))
		{
			ans = mid;
			r = mid - 1;
		}
		else
			l = mid + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

AC code

点击查看代码
/*
I shall be telling this with a sigh
Somewhere ages and ages hence
Two roads diverged in a wood, and I
I took the one less travelled by
And that has made all the difference
*/

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;

const int N = 1e5, E = N << 1;
const long long Max = 1e9;

typedef pair<long long, int> pir;

int n;
long long a[N + 5], b[N + 5], c[N + 5], zero[N + 5];

int head[N + 5], to[E + 5], nxt[E + 5], tot = 1;
void add_edge(int u, int v)
{
	tot++;
	to[tot] = v;
	nxt[tot] = head[u];
	head[u] = tot;
	return ;
}
void add(int u, int v)
{
	add_edge(u, v);
	add_edge(v, u);
	return ;
}

long long d[N + 5];//limit
int sz[N + 5];

void calc_d(int u, long long ans)
{
	long long l = 1, r = n;
	d[u] = -1ll;
	while (l <= r)
	{
		long long mid = (l + r) >> 1;
		__int128 sum = 0, one = 1;

		if (c[u] >= 0)
			sum = one * (ans - mid + 1) * b[u]
				 + one * (mid + ans) * (ans - mid + 1) / 2 * c[u];
		else
		{
			if (mid > zero[u])
				sum = ans - mid + 1;
			else if (ans > zero[u])
				sum = one * (zero[u] - mid + 1) * b[u]
					 + one * (mid + zero[u]) * (zero[u] - mid + 1) / 2 * c[u]
					 + ans - zero[u];
			else
				sum = one * (ans - mid + 1) * b[u]
					 + one * (mid + ans) * (ans - mid + 1) / 2 * c[u];
		}

		if (one * a[u] <= sum)
		{
			d[u] = mid;
			l = mid + 1;
		}
		else
			r = mid - 1;
	}
	return ;
}

int fa[N + 5], in[N + 5];
void dfs(int u, int father)
{
	fa[u] = father;
	in[father]++;
	for (int i = head[u]; i; i = nxt[i])
	{
		int v = to[i];
		if (v == father)
			continue;
		dfs(v, u);
	}
	return ;
}

priority_queue<pir> q;
int seq[N + 5];
bool check(long long ans)
{
	for (int i = 1; i <= n; i++)
	{
		calc_d(i, ans);
		if (d[i] < 0)
			return false;
	}

	dfs(1, 0);
	for (int i = 1; i <= n; i++)
	{
		if (in[i] == 0)
			q.emplace(d[i], i);
	}

	for (int T = n; T > 0; T--)
	{
		int u = q.top().second;
		q.pop();
		seq[T] = u;

		if (fa[u])
		{
			in[fa[u]]--;
			if (in[fa[u]] == 0)
				q.emplace(d[fa[u]], fa[u]);
		}
	}

	for (int i = 1; i <= n; i++)
	{
		if (1ll * i > d[seq[i]])
			return false;
	}
	return true;
}

int main()
{
	// freopen("tree.in", "r", stdin);
	// freopen("tree.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld%lld%lld", a + i, b + i, c + i);
		if (c[i] < 0)
			zero[i] = (1ll - b[i]) / c[i];
	}
	for (int i = 1, u, v; i < n; i++)
	{
		scanf("%d%d", &u, &v);
		add(u, v);
	}

	long long l = 1, r = Max, ans = 0;
	while (l <= r)
	{
		long long mid = (l + r) >> 1;
		if (check(mid))
		{
			ans = mid;
			r = mid - 1;
		}
		else
			l = mid + 1;
	}
	printf("%lld\n", ans);
	return 0;
}

标签:Last,int,合辑,mid,long,2024,textrm,ans,include
From: https://www.cnblogs.com/yhk1001/p/17805721.html

相关文章

  • C4D2024+Redshift 3.5.20 三维计算机动画、建模、模拟和渲染软件_中文/英文WIN版
     Cinema4D是什么?Cinema4D2024下载:hereitis.cn/soft/c4dCinema4D是一款专业的3D建模、动画、模拟和渲染解决方案软件。它的快速、强大、灵活和稳定的工具集使设计、运动图形、VFX、AR/MR/VR、游戏开发和所有类型的可视化专业人员获得更容易和高效的3D工作流程。无......
  • docker 配置 ElasticSearch + Kibana + ik分词器
    docker配置ElasticSearch+Kibana+ik分词器下载镜像文件dockerpullelasticsearch:7.4.2#存储和检索数据dockerpullkibana:7.4.2#可视化检索数据创建实例配置外置挂在目录,echo这一行命令配置可以被任意主机访问mkdir-p/mydata/elasticsearch/configmkdir-p/......
  • 2023-2024-1 20231402《计算机基础与程序设计》第六周学习总结
    2023-2024-120231402《计算机基础与程序设计》第六周学习总结作业信息这个作业属于哪个课程2023-2024-1-计算机基础与程序设计这个作业要求在哪里2023-2024-1计算机基础与程序设计第6周作业这个作业的目标自学计算机科学概论第7章《C语言程序设计》第5章作业......
  • Microplastics in China Sea
    Researchonmicroplastic(MP)pollutioninthemarineenvironmenthasreceivedwidespreadattentioninrecentyears.ToassessthedegreeofMPcontaminationintheintertidalzoneofChina,theabundance,shape,particlesizeandcompositionofMPsinse......
  • SOLIDWORKS2024新功能发布啦!
    SOLIDWORKS2024新功能已经发布,您可以亲身体验新的用户驱动增强功能,这些增强功能旨在帮助您更智能、更快速、更协同地工作。立即加入并开始探索这些关键的发布亮点:一、工作智能化SOLIDWORKS2024新功能通过更有效地去除模型特征,减少SOLIDWORKS中的工作量。首先将组件关联地插......
  • Elasticsearch安装
    Docker单节点修改max_map_count值sysctl-wvm.max_map_count=262144创建持久化目录并配置权限mkdir/opt/elasticsearchsetfacl-mu:1000:rwx-R/opt/elasticsearch/创建配置文件mkdirconfig$cat>elasticsearch.yml<<EOFcluster.name:"docker-cluster"netw......
  • 用blast blastn进行短序列的搜索(比对)
    blastn多加上 blastn-short-task:设置比对模式,通常情况会有一个默认task,这里要设置为blastn-short-word_size:尽可能小,这里设为7-evalue:类似于p值的一个指标,越小说明越可靠 TasksTaskDescriptionblastpTraditionalBLASTPtocompareaproteinquerytoaproteindatabaseblas......
  • [转]Elasticsearch全文检索入门这一篇就够了
    本文仅针对搜索与Elasticsearch小白,先介绍了全文搜索的原理,然后介绍了Elasticsearch中的一些基本概念,接着讲解如何在Elasticsearch中插入文档构建查询索引,最后介绍Elasticsearch的线上查询API的使用方式。全文搜索原理顺序扫描如何实现全文搜索?最简单的方法就是用正则去匹配文......
  • elastic索引管理
    常用API2,索引压缩实际上是压缩的分片,并非在原有索引上压缩,而是生成了一个新的索引,由于使用了hash路由算法以及索引不可变的特性---操作步骤---reindex不会把mapping和seting复制过去 删除副本删除副本"index.numberof_replicas":0设置只读"index.blocks.write":true 案例......
  • elasticsearch运维调优-集群和冷热集群
    集群:node1-node3专用主节点node3仅投票节点 启动服务:./bin/elasticsearch后台启动守护进程./bin/elasticsearch推荐方式./bin/elasticsearch-d-ppid关闭进程ps-ef|grepelastic杀进程kill-9'catpid'pkill-Fpid常见问题:本地无法访问:关闭防火墙,生产环境建......