首页 > 其他分享 >洛谷比赛【LGR-171-Div.3】深圳科创学院基础赛 #7 &「RHOI」Round 2 赛后总结

洛谷比赛【LGR-171-Div.3】深圳科创学院基础赛 #7 &「RHOI」Round 2 赛后总结

时间:2024-01-14 20:12:18浏览次数:45  
标签:洛谷 int Big 科创 long RHOI using 操作 include

洛谷比赛【LGR-171-Div.3】深圳科创学院基础赛 #7 &「RHOI」Round 2 赛后总结

比赛链接:https://www.luogu.com.cn/contest/146495

建议先看原题再看文章。

A - Water(P10056)

有 \(n\) 个杯子,每个杯子的容积是 \(a\),且初始装有 \(b\) 体积水。
你可以进行任意次操作,每次操作选择任意两个杯子,将其中一个杯子内的水全部倒入另一个杯子中,但是过程中杯子里的水不能溢出(即不能超过其容积),如果不满足则无法进行该操作。请通过合法的操作,最大化装有最多水的杯子里水的体积。

Module 1 总结

赛时是一眼秒的。

显然把水全倒在一个杯子里,得到的答案最大,也就是 \(b \times n\)。但是可能会溢出,容量为 \(x\) 的情况下,最多能装 \(\Big\lfloor \dfrac{x}{b} \Big\rfloor\) 个初始装有 \(b\) 体积的水杯的容量。所以答案是 \(\min\Big(n \times b,\ b \times \Big\lfloor \dfrac{x}{b} \Big\rfloor\Big)\)。

记得开 long long

Module 2 代码

Code

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

using ll = long long;

const int kMaxN = 5050, kMaxM = 5e4 + 50, kInf = (((1 << 30) - 1) << 1) + 1;
const ll kLInf = 9.22e18;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll a, b, n;
	cin >> a >> b >> n;
	cout << min(n * b, b * (a / b)) << '\n';
	return 0;
}

B - Line(P10057)

在一个二维平面内,给定两条分别与 \(x\) 轴和 \(y\) 轴平行的线段 \(AB\) 和 \(CD\)。你可以选择一条线段,将其沿着平行于坐标轴(上下左右)的任意一个方向平移任意单位长度,称为一次操作。问至少进行几次操作可以使两条线段相交?

Module 1 总结

赛时思考了一会,还错了 \(3\) 次。

首先,题目中说 \(x_A<x_B\),\(x_C=x_D\),\(y_A=y_B\),\(y_C<y_D\)。所以我们发现,第一条线段是竖的,第二条是横的。所以我们先判断第一段和第二段的 \(x\) 轴是否重合(\(x_A \le x_C \le x_B\) 或 \(x_A \le x_D \le x_B\)),如果不是,答案 \(+1\)。再判断 \(y\) 轴是否重合(\(y_C \le y_A \le y_D\) 或 \(y_C \le y_B \le y_D\)),如果不是,答案 \(+1\)。

Module 2 代码

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

using ll = long long;

const int kMaxN = 5050, kMaxM = 5e4 + 50, kInf = (((1 << 30) - 1) << 1) + 1;
const ll kLInf = 9.22e18;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t, x[5], y[5];
	for (cin >> t; t; -- t) {
		for (int i = 1; i <= 4; ++ i) { // 输入,用数组方便
			cin >> x[i] >> y[i];
		}
		int ans = 0;
		if (!(x[3] >= x[1] && x[3] <= x[2])) { // x 轴是否重合
			++ ans;
		} 
		if (!(y[1] >= y[3] && y[1] <= y[4])) { // y 轴是否重合
			++ ans;
		}
		cout << ans << '\n';
	}
	return 0;
}

C - Reverse and Rotate(P10058)

给定一个字符串 \(S\) 和 \(n\) 次操作,每次操作为以下 \(3\) 种形式之一:1. < x 表示将 \(S\) 向左循环移动 \(x\) 位。例如:\(\mathtt{abcde}\) 执行 < 2 后变成 \(\mathtt{cdeab}\)。2. > x 表示将 \(S\) 向右循环移动 \(x\) 位。例如:\(\mathtt{abcde}\) 执行 > 2 后变成 \(\mathtt{deabc}\)。3. rev 表示将 \(S\) 翻转。例如:\(\mathtt{abcde}\) 执行 rev 后变成 \(\mathtt{edcba}\)。求 \(S\) 在依次执行这 \(n\) 次操作后得到的字符串 \(S'\)。

Module 1 总结

赛事想到了正解的 \(70\%\),但还是与 AC 擦肩而过。

赛时得分:\(30\),TLE #4~#10。

Module 2 赛后题解

前置知识:\(|S|\) 表示字符串 \(S\) 的长度。

首先我们发现,<> 操作为相反操作,且 \(x\) 可以对 s.size() 取模后再操作。

所以当没有 rev 操作时,可以定义一个变量 \(p\)。当 < 操作时加上 \(x \bmod |s|\),> 时反之。最后判断正负,如果是正数就执行 < p,负数则执行 > p

但现在有 rev 操作。rev 操作反转了字符串,所有操作相反。我们定义一个 \(f\) 用来记录 \(S\) 的反转次数,为反转次数 \(\bmod \ 2\)。这里要注意一点,如果 \(p < 0\) 或 \(p \ge |S|\) 时需要把 \(p\) 加上或减去 \(|S|\) 把 \(p\) 的位置调到 \(0 \sim |S| - 1\)。 最后根据 \(f\) 分类输出即可。

Moudule 3 代码

赛时代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <queue>

using namespace std;

using ll = long long;

const int kMaxN = 5050, kMaxM = 5e4 + 50, kInf = (((1 << 30) - 1) << 1) + 1;
const ll kLInf = 9.22e18;

string s, t;
int n, rmv = 0, x;
bool rev = 0;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> n;
	int m = s.size();
	for (; n; -- n) {
		cin >> t;
		if (t == "<") {
      cin >> x;
			x %= m;
			s = s.substr(x) + s.substr(0, x);
		} else if (t == ">") {
			cin >> x;
			x %= m;
			s = s.substr(m - x) + s.substr(0, m - x);
		} else {
			reverse(s.begin(), s.end());
		}
	}
	cout << s << '\n';
	return 0;
}

题解代码(伪代码):

Input and Define variables
string op
int x
input(op)
if (op = ">" && f = true) || (op = "<" && f = false)
  input(x)
  x %= s.size()
  p -= x
  if p < 0
    p += s.size()
else if (op = ">" && f = false) || (op = "<" && f = true) 
  input(x)
  x %= s.size()
  p += x
  if p >= s.size()
    p -= s.size()
else 
  f = !f

if f = true
  output(s[p]...s[size() - 1])
  output(s[0]...s[p - 1])
else
  output(s[p - 1]...s[0])
  output(s[s.size() - 1]...s[p])
  

D - Choose(P10059)

没做,没时间。

标签:洛谷,int,Big,科创,long,RHOI,using,操作,include
From: https://www.cnblogs.com/bc2qwq/p/17964076/LCR171contest

相关文章

  • 洛谷 P5359 [SDOI2019] 染色
    洛谷传送门LOJ传送门dp好题。首先有一个显然的状态,设\(f_{i,x,y}\)为第\(i\)列上下两格的颜色分别为\(x,y\)的方案数。但是这样做时间复杂度至少为\(O(nm^2)\),无法接受。注意到全\(0\)列的转移是重复的。我们可以试着只在两个相邻非全\(0\)列转移。这样我们需......
  • 洛谷 P5996 [PA2014] Muzeum
    洛谷传送门考虑最大权闭合子图,第\(i\)个手办建点\(i\),第\(i\)个警察建点\(i'\)。我们有一些边:\(\foralli,(S,i,v_i),(i',T,v_i)\),以及对于能看见第\(i\)个手办的第\(j\)个警察,有\((i,j',\infty)\)。手办的\(\sumv_i\)减去最小割(最大流)即为答案。考虑转换......
  • 双向广搜->字符变换(洛谷P1032)
    题意:给起始和终止串A和B,以及不超过6个字符串变换规则,求A->B能否在10步以内变换完成。分析:暴力bfs每次有6条路可以走,时间复杂度是6^10大概6e8的时间复杂度,会TLE。于是这题是一道经典的双向bfs。直接开两个队列,两个map,暴力搜1~5步即可。双向bfs的时间复杂度是2*(6^5)=1e4......
  • 洛谷 P7409 SvT
    洛谷传送门考虑对反串建SAM,设\([i,n]\)的后缀对应SAM的点是\(a_i\)。那么\(\text{lcp}(s[i:n],s[j:n])=\text{len}(\text{lca}(a_i,a_j))\)。于是问题变成了,给定一些点,统计两两\(\text{lca}\)点权之和。考虑建虚树,枚举每个点\(u\)作为\(\text{lca}\)的......
  • 洛谷火柴人
    importjava.io.BufferedReader;importjava.io.InputStreamReader;importjava.io.StreamTokenizer;publicclassMain{staticintn;staticintnumber=0;staticint[]arr=newint[20000];staticboolean[]st=newboolean[20000];sta......
  • 【LGR-170-Div.3】洛谷基础赛 #6 & Cfz Round 3 & Caféforces #2
    这套题感觉质量很高A.Battle\[x\equivr(\bmodP)\]\[P\midx-r\]因此只有第一次操作是有效的voidsolve(){ intn,m,p; cin>>n>>m>>p; m-=m%p; if(!m)puts("Alice"); else{ n-=n%p; if(!n)puts("Bob"); else......
  • 洛谷 P5311 [Ynoi2011] 成都七中
    洛谷传送门转化一下题意,变成求\(x\)在只经过编号\(\in[l,r]\)的点,能走到多少种颜色。考虑建出点分树。一个结论是原树上的一个连通块,一定存在一个点,使得它在点分树上的子树完全包含这个连通块的所有点。证明考虑点分治的过程,一个连通块如果没被其中一个点剖开就一定在同一......
  • 洛谷 P9058 [Ynoi2004] rpmtdq
    洛谷传送门类比P9062[Ynoi2002]AdaptiveHsearch&Lsearch处理区间最近点对的思路,尝试只保留可能有贡献的点对。处理树上路径容易想到点分治。设点\(u\)到分治中心的距离为\(a_u\)。我们有\(\text{dis}(u,v)\lea_u+a_v\)。考虑一个点对\((u,v)\)什么时候一定没......
  • 洛谷B3611 【模板】传递闭包 floyd/bitset
    目录floydbitset优化题目链接:https://www.luogu.com.cn/problem/B3611参考题解:https://www.luogu.com.cn/blog/53022/solution-b3611floyd#include<bits/stdc++.h>usingnamespacestd;constintmaxn=101;intn,f[maxn][maxn];intmain(){scanf("%d"......
  • 洛谷B3647 【模板】Floyd 题解 floyd算法 求 多源多汇最短路
    题目链接:https://www.luogu.com.cn/problem/B3647floyd算法:https://oi-wiki.org/graph/shortest-path/#floyd-算法示例程序:#include<bits/stdc++.h>usingnamespacestd;constintmaxn=101;intn,m,f[maxn][maxn];intmain(){scanf("%d%d",&n......