首页 > 其他分享 >2023冲刺国赛模拟9

2023冲刺国赛模拟9

时间:2023-05-31 19:56:41浏览次数:45  
标签:tmp p0 int ans back 冲刺 国赛 2023 push

A. 哈密顿路

考虑哈密顿路一定经过 \(1\), 那么在这里断开

\(f_s\) 表示已经走过的点集为 \(s\), 能作为最后一个点出现的点的集合

然后拼起来即可

code
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int read(){
	int x = 0; char c = getchar();
	while(!isdigit(c))c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(isdigit(c));
	return x;
}
const int maxn = 24;
char s[maxn + 5];
int n, e[1 << maxn], f[1 << maxn], ans[maxn];
int main(){
	freopen("hamilton.in","r",stdin);
	freopen("hamilton.out","w",stdout);
	n = read();
	for(int i = 0; i < n; ++i){
		scanf("%s",s);
		for(int j = 0; j < n; ++j)if(s[j] == '1')e[1 << i] |= 1 << j;
	}
	for(int s = 1; s < (1 << n); ++s)e[s] = e[s & -s] | e[s ^ (s & -s)];
	f[1] = 1;
	for(int s = 1; s < (1 << n); s += 2)
		for(int i = 0; i < n; ++i)if(!(s >> i & 1) && (e[f[s]] >> i & 1))
			f[s | (1 << i)] |= (1 << i);
	for(int s = 1; s < (1 << n); s += 2){
		int t = (((1 << n) - 1) ^ s) | 1;
		for(int i = 0; i < n; ++i)if(f[s] >> i & 1)ans[i] |= f[t];
	}
	ans[0] = f[(1 << n) - 1];
	for(int i = 0; i < n; ++i, printf("\n"))
		for(int j = 0; j < n; ++j)
			printf("%d",(ans[i] >> j & 1));
	return 0;
}

B. 统一省选

一个区间一定能写成分三段的函数

\((-\infty, a) \to -\infty\)

\([a, b) \to c\)

\((b, \infty) \to (b, \infty) + d\)

线段树维护即可。。。

code
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, int> pli;

ll read(){
	ll x = 0; char c = getchar();
	while(!isdigit(c))c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(isdigit(c));
	return x;
}
const int maxn = 1e6 + 55;
const ll inf = 1e14;
ll n, q, h0;

struct node{
	ll a, b, cov, dt;
	void init(int type, ll val){
		if(type == 1)a = val + 1, b = val + 1, cov = 1, dt = -val;
		if(type == 2)a = val, b = inf, cov = a, dt = -inf;
		if(type == 3)a = 1, b = val, cov = val, dt = 0;
	}
	ll trans(ll val){
		if(val >= b)return val + dt;
		if(val >= a)return cov;
		return -inf;
	}
	friend node operator + (const node &x, const node &y){
		if(y.a <= x.cov){
			if(y.b <= x.cov)return {x.a, x.b, x.cov + y.dt, x.dt + y.dt};
			return {x.a, y.b - x.dt, y.cov, x.dt + y.dt};
		}else return {y.a - x.dt, y.b - x.dt, y.cov, x.dt + y.dt};
	}
};
struct seg{
	node t[maxn << 2 | 1];
	void build(int x, int l, int r){
		if(l == r){int type = read(); t[x].init(type, read()); return;}
		int mid = (l + r) >> 1;
		build(x << 1, l, mid);
		build(x << 1 | 1, mid + 1, r);
		t[x] = t[x << 1] + t[x << 1 | 1];
	}
	void modify(int x, int l, int r, int pos){
		if(l == r){int type = read(); t[x].init(type, read()); return;}
		int mid = (l + r) >> 1;
		if(pos <= mid)modify(x << 1, l, mid, pos);
		else modify(x << 1 | 1, mid + 1, r, pos);
		t[x] = t[x << 1] + t[x << 1 | 1];
	}
	pli query(int x, int l, int r, int L, int R, ll val){
		if(l == r){
			if(t[x].trans(val) > 0)return pli(t[x].trans(val), l);
			return pli(-1, l - 1);
		}
		int mid = (l + r) >> 1;
		if(L > mid)return query(x << 1 | 1, mid + 1, r, L, R, val);
		if(L <= l && r <= R && t[x].trans(val) > 0)return pli(t[x].trans(val), r);
		pli res = query(x << 1, l, mid, L, R, val);
		if(res.first == -1)return res;
		return query(x << 1 | 1, mid + 1, r, L, R, res.first);
	}
}T;
int main(){
	freopen("bad.in","r",stdin);
	freopen("bad.out","w",stdout);
	n = read(), q = read(); h0 = read();
	T.build(1, 1, n);
	for(int i = 1; i <= q; ++i){
		int op = read(), x = read();
		if(op & 1)T.modify(1, 1, n, x);
		else{
			pli res = T.query(1, 1, n, x, n, h0);
			if(res.second >= x)printf("%d\n",res.second);
			else printf("-1\n");
		}
	}
	return 0;
}

C. 并行计算

经过一堆证明得到答案为 \(0.4n+O(1)\)

构造 \(16\) 个 用 \(6\) 歩消去 \(15\) 个

\(11\) 个 用 \(4\) 歩消去 \(10\) 个

再加上 \(8\) 个 \(3\) 歩消 \(7\) 个

等边角料处理即可

由于数据已知,所以情况写的不全

code
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int read(){
	int x = 0; char c = getchar();
	while(!isdigit(c))c = getchar();
	do{x = x * 10 + (c ^ 48); c = getchar();}while(isdigit(c));
	return x;
}
struct data{
	int a, b;
};
struct node{
	data a[4];
};
vector<node>ans;
void solve16_6(int p0){
	node tmp;
	tmp.a[0] = {p0 + 1, p0 + 2}; tmp.a[1] = {p0 + 4, p0 + 5}; tmp.a[2] = {p0 + 7, p0 + 8}; tmp.a[3] = {p0 + 10, p0 + 11}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 2, p0 + 3}; tmp.a[1] = {p0 + 5, p0 + 6}; tmp.a[2] = {p0 + 8, p0 + 9}; tmp.a[3] = {p0 + 11, p0 + 12}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 3, p0 + 4}; tmp.a[1] = {p0 + 3, p0 + 5}; tmp.a[2] = {p0 + 3, p0 + 6}; tmp.a[3] = {p0 + 13, p0 + 14}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 6, p0 + 7}; tmp.a[1] = {p0 + 6, p0 + 8}; tmp.a[2] = {p0 + 6, p0 + 9}; tmp.a[3] = {p0 + 14, p0 + 15}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 9, p0 + 10}; tmp.a[1] = {p0 + 9, p0 + 11}; tmp.a[2] = {p0 + 9, p0 + 12}; tmp.a[3] = {p0 + 15, p0 + 16}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 12, p0 + 13}; tmp.a[1] = {p0 + 12, p0 + 14}; tmp.a[2] = {p0 + 12, p0 + 15}; tmp.a[3] = {p0 + 12, p0 + 16}; ans.push_back(tmp);
}
void solve11_4(int p0){
	node tmp;
	tmp.a[0] = {p0 + 1, p0 + 2}; tmp.a[1] = {p0 + 3, p0 + 4}; tmp.a[2] = {p0 + 5, p0 + 6}; tmp.a[3] = {p0 + 8, p0 + 9}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 2, p0 + 3}; tmp.a[1] = {p0 + 2, p0 + 4}; tmp.a[2] = {p0 + 6, p0 + 7}; tmp.a[3] = {p0 + 9, p0 + 10}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 4, p0 + 5}; tmp.a[1] = {p0 + 4, p0 + 6}; tmp.a[2] = {p0 + 4, p0 + 7}; tmp.a[3] = {p0 + 10, p0 + 11}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 7, p0 + 8}; tmp.a[1] = {p0 + 7, p0 + 9}; tmp.a[2] = {p0 + 7, p0 + 10}; tmp.a[3] = {p0 + 7, p0 + 11}; ans.push_back(tmp);
}
void solve8_3(int p0){
	node tmp;
	tmp.a[0] = {p0 + 1, p0 + 2}; tmp.a[1] = {p0 + 3, p0 + 4}; tmp.a[2] = {p0 + 5, p0 + 6}; tmp.a[3] = {p0 + 7, p0 + 8}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 2, p0 + 3}; tmp.a[1] = {p0 + 2, p0 + 4}; tmp.a[2] = {p0 + 6, p0 + 7}; tmp.a[3] = {p0 + 6, p0 + 8}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 4, p0 + 5}; tmp.a[1] = {p0 + 4, p0 + 6}; tmp.a[2] = {p0 + 4, p0 + 7}; tmp.a[3] = {p0 + 4, p0 + 8}; ans.push_back(tmp);
}
void solve4_2(int p0){
	node tmp; 
	tmp.a[0] = {p0 + 1, p0 + 2}; tmp.a[1] = {p0 + 3, p0 + 4}; tmp.a[2] = {2000, 2000}; tmp.a[3] = {2000, 2000}; ans.push_back(tmp);
	tmp.a[0] = {p0 + 2, p0 + 3}; tmp.a[1] = {p0 + 2, p0 + 4}; tmp.a[2] = {2000, 2000}; tmp.a[3] = {2000, 2000}; ans.push_back(tmp);
}
void print(){
	printf("%d\n",(int)ans.size());
	for(node v : ans){
		for(int i = 0; i < 4; ++i)printf("%d %d %d ",v.a[i].b, v.a[i].a, v.a[i].b);
		printf("\n");
	}
}
int main(){
	freopen("computer.in","r",stdin);
	freopen("computer.out","w",stdout);
	int n = read();
	int i = 0;
	for(i = 0; i + 16 <= n; i += 15)solve16_6(i);
	switch(n - i){
		case 1 : break;
		case 4 : solve4_2(i); break;
		case 8 : solve8_3(i); break;
		case 9: case 10 : solve11_4(i); break;
		case 14 : solve16_6(i); break;
		case 6 : for(int c = 1; c <= 6; ++c)ans.pop_back(); i -= 15; solve11_4(i); i += 10; solve11_4(i); break;
	}
	print();
	return 0;
}

标签:tmp,p0,int,ans,back,冲刺,国赛,2023,push
From: https://www.cnblogs.com/Chencgy/p/17447163.html

相关文章

  • 2023湘潭邀请赛 E(容斥)
    题目跳转:E题意:输入x,k,求大小为k的不同集合个数,其中所有数的gcd+lcm=x。思路:AC代码://-----------------#include<bits/stdc++.h>#definexxfirst#defineyysecond#defineIOSios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);#definefixedf......
  • 【2023 · CANN训练营第一季】——应用开发深入讲解——模型转换的ATC工具
    前言: 做一个推理应用,首先从模型转换开始(当然先得选好一个合适的模型)。在昇腾平台做模型推理,需要将Caffe,TensorFlow等开源框架网络模型转换成Davinci架构专用模型(OM格式)。昇腾张量编译器(AscendTensorCompiler,简称ATC)是异构计算架构CANN体系下的模型转换工具,模型转换过程中,ATC会进......
  • 【2023 · CANN训练营第一季】——开发者套件进阶,玩转智能小车课程笔记
    前言:基于新款开发者套件Atlas200IDKA2的智能小车,采用人工智能的方法,对摄像头采集到实时影像进行推理,产生电机等运动机构的控制指令,在特定环境里,实现自动行驶、自动泊车、目标跟踪等功能。昇腾官方开源了“玩”小车的全部软、硬件资料,还准备了模拟环境,让还没有小车的小伙伴体验自......
  • 某书x-s算法(2023-05-30更新)
     服务器2023-05-30更新了x-s算法,主要位置如下: 将其全部复制下来,放入浏览器测试(HTML代码如下):<!DOCTYPEhtml><html><head><metacharset="utf-8"/><title>X-s,X-t算法测试,技术支持:V:byc6352,日期:2023-5-31</title><scriptsrc="xs.j......
  • 2023广东省程序设计大赛F题
    思路:我们把先把所有状态和值用线段树或树状数组记录下来(因为他是连续的区间,相当于一段区间的不同状态的和)再通过二分或者倍增找出这段区间及找出左右端点1:线段树或者着树状数组维护的有两个,一个是前缀和(不管状态),一个是颜色和就是状态2:左右端点查找:一个点对应一个颜色,我们假设从......
  • pkusc2023 d1t3
    整自闭了,快一个月后才想出来怎么做。设点\(i\)是1的概率为\(p_i\),定义\(P_i(x)=1-p_i+p_ix\)。那么\(p_i\)是\(i\)的儿子节点和自己的\(P(x)\)卷起来后取后一半的系数和。树上修改很魔怔,考虑ddp。维护每个点轻儿子和自己的\(\prodP(x)\),记为\(S_i(x)\),设一共有......
  • 【2023 · CANN训练营第一季】——搭建环境:创建ECS,下载sample仓
    前言:        本文是环境搭建的第一篇笔记。主要包括下面两方面内容:    1、在华为云上创建ECS服务器,并修改Ubuntu源和pip源为国内镜像地址。        2、为了更好的使用ECS,需要在本地安装远程连接和查看代码的工具软件,以Windows为例介绍几个常用的工具软件。......
  • CVE-2023-33246学习
    1.参考学习CVE-2023-33246https://github.com/I5N0rth/CVE-2023-332462.本地搭建环境2.1下载镜像#dockerpullapache/rocketmq:4.9.1#dockerpullapacherocketmq/rocketmq-console:2.0.02.2启动broker、namesrv、console启动namesrvdockerrun-dit-p9876:987......
  • 西门康IGBT模块存在sql注入 QTVA-2023-3632489
    网址:http://www.gl-igbt.com/product.php?id=6 漏洞描述: 西门康igbt模块,采购平台,便捷购买,专业代理,售后无忧,大量现货供应,模块齐全,可直接供货,一键下单,整流桥功率,西门康一站式采购平台,可长期稳定供货 西门康IGBT模块存在sql注入漏洞,攻击者可利用该漏洞获取数据库......
  • 2023ccpc大学生程序设计竞赛-zzh
    比赛开始没有开到签到题,看了一会别的题才开始跟榜。A题我写的,不过没有考虑到S长度为1的情况,wa了一次。然后lhy和zx把F题做了出来。接着他俩去看H,我去看B。他俩把H过了,B我想出了一个n*根n的做法,T了。lhy感觉E是DP,去看E,我和zx去看K。lhy把E过了,我俩K还没思路。接着他俩看B,想了快......