首页 > 其他分享 >Day 26 - 模拟赛

Day 26 - 模拟赛

时间:2024-08-02 14:10:01浏览次数:14  
标签:26 ch 48 text long while Day 模拟 getchar

热门景点(hot)

题目描述

输入格式

输出格式

\(\text{input1}\)

10 5
1 7 4 0 9 4 8 8 2 4
6 6
2 8
2 2
3 6
7 8

\(\text{output1}\)

Y
N
Y
N
Y

数据范围

#include<iostream>
#include<cstdio>
#include<ctime>
using namespace std;
#define MAXN 5000005

int read() {
	int x = 0; bool f = 0;
	char ch = getchar();
	while(ch < 48 || ch > 57) {
		if(ch == 45) f = 1;
		ch = getchar();
	}
	while(ch >= 48 && ch <= 57) {
		x = (x << 3) + (x << 1) + (ch - 48);
		ch = getchar();
	}
	return f ? -x : x;
}

int n, q, a[MAXN], pl[MAXN], pr[MAXN], cnt = 0, l, r;
struct node { int lm, rm; } b[MAXN];

int main() {
	freopen("hot.in", "r", stdin);
	freopen("hot.out", "w", stdout);
	
	n = read(); q = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	pl[1] = 1;
	for(int i = 2; i <= n; i ++) 
		if(a[i] <= a[i - 1]) pl[i] = pl[i - 1];
		else pl[i] = i;
	pr[n] = n;
	for(int i = n - 1; i >= 1; i --) 
		if(a[i] <= a[i + 1]) pr[i] = pr[i + 1];
		else pr[i] = i;
//	for(int i = 1; i <= n; i ++) cout << pl[i] << " ";
//	cout << "\n";
//	for(int i = 1; i <= n; i ++) cout << pr[i] << " ";
//	cout << "\n";
	while(q --) {
		l = read(); r = read();
		if(pr[l] >= pl[r]) printf("Y\n");
		else printf("N\n");
	}
//	for(int i = 1; i <= n; i ++) 
//		if(a[i] >= a[i - 1]) pl[i] = pl[i - 1] + 1;
//		else pl[i] = 1;
//	for(int i = n; i >= 1; i --) 
//		if(a[i] >= a[i + 1]) pr[i] = pr[i + 1] + 1;
//		else pr[i] = 1;
////	for(int i = 1; i <= n; i ++) cout << pl[i] << " ";
////	cout << "\n";
////	for(int i = 1; i <= n; i ++) cout << pr[i] << " ";
////	cout << "\n";
//	int tmp = 1; while(pl[tmp] > pl[tmp - 1]) tmp ++;
////	cout << tmp - 1 << "\n"; 
//	pl[n + 1] = 1;
//	for(int i = tmp - 1; i <= n; ) {
//		b[++ cnt].lm = i - pl[i] + 1, b[cnt].rm = i + pr[i] - 1;
//		i += pr[i]; while(pl[i + 1] != 1) i ++; 
//	}
////	for(int i = 1; i <= cnt; i ++) cout << b[i].lm << " " << b[i].rm << "\n"; 
//	int l = 0, r = 0;
//	while(q --) {
//		l = read(); r = read();
//		if(r - l + 1 == 1 || r - l + 1 == 2) { printf("Y\n"); continue; }
//		int ll = 1, lr = cnt, ansl = -1;
//		while(ll <= lr) {
//			int mid = (ll + lr) >> 1;
//			if(b[mid].lm <= l) ansl = mid, ll = mid + 1;
//			else lr = mid - 1;
//		}
//		int rl = 1, rr = cnt, ansr = -1;
//		while(rl <= rr) {
//			int mid = (rl + rr) >> 1;
//			if(b[mid].rm >= r) ansr = mid, rr = mid - 1;
//			else rl = mid + 1;
//		}
////		cout << ansl << " " << ansr << "\n";
//		if(ansr + 1 == ansl && b[ansr].lm <= l && b[ansr].rm >= r) printf("Y\n");
//		else if(ansl == ansr && ansl != -1) printf("Y\n");
//		else printf("N\n");
//	}
	return 0;
}

管道(tunnel)

题目描述

输入格式

输出格式

\(\text{input1}\)

1 7
15 -5 100 -40 10 10 10

\(\text{output1}\)

115

\(\text{input2}\)

3 3
-10 4 -10
3 1 -10
6 2 8

\(\text{output2}\)

28

样例解释

数据范围

tunnel.zip

#include<iostream>
using namespace std;
#define MAXN 1005

long long read() {
	long long x = 0; bool f = 0;
	char ch = getchar();
	while(ch < 48 || ch > 57) {
		if(ch == 45) f = 1;
		ch = getchar();
	}
	while(ch >= 48 && ch <= 57) {
		x = (x << 3) + (x << 1) + (ch - 48);
		ch = getchar();
	}
	return f ? -x : x;
}

long long n, m, a[MAXN][MAXN], b[MAXN][MAXN], ans = 0;

void update() {
	long long res = 0;
	for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) 
		if(b[i][j] == 1) {
			if(b[i][j + 1] == 2 || b[i][j + 1] == 4) res += max(0ll, a[i][j] + a[i][j + 1]);
			if(b[i + 1][j] == 3 || b[i + 1][j] == 4) res += max(0ll, a[i][j] + a[i + 1][j]);
		}
		else if(b[i][j] == 2) {
			if(b[i][j - 1] == 1 || b[i][j - 1] == 3) res += max(0ll, a[i][j] + a[i][j - 1]);
			if(b[i + 1][j] == 3 || b[i + 1][j] == 4) res += max(0ll, a[i][j] + a[i + 1][j]);
		}
		else if(b[i][j] == 3) {
			if(b[i][j + 1] == 2 || b[i][j + 1] == 4) res += max(0ll, a[i][j] + a[i][j + 1]);
			if(b[i - 1][j] == 1 || b[i - 1][j] == 2) res += max(0ll, a[i][j] + a[i - 1][j]);
		}
		else if(b[i][j] == 4) {
			if(b[i][j - 1] == 1 || b[i][j - 1] == 3) res += max(0ll, a[i][j] + a[i][j - 1]);
			if(b[i - 1][j] == 1 || b[i - 1][j] == 2) res += max(0ll, a[i][j] + a[i - 1][j]);
		}
//	if(res / 2 > ans) {
//		for(int i = 1; i <= n; i ++) {
//			for(int j = 1; j <= m; j ++) cout << b[i][j] << " ";
//			cout << "\n";
//		} 
//		cout << res / 2 << "\n";
//	}
	ans = max(ans, res / 2); return;
}

void dfs(long long x, long long y) {
//	cout << x << " " << y << "\n"; 
	for(int i = 1; i <= 4; i ++) {
		b[x][y] = i;
		if(x == n && y == m) update();
		else if(y == m) dfs(x + 1, 1);
		else dfs(x, y + 1);
	}
	return;
}

int main() {
	freopen("tunnel.in", "r", stdin);
	freopen("tunnel.out", "w", stdout);
	
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) a[i][j] = read();
	dfs(1, 1);
	cout << ans << "\n"; 
	return 0;
}
#include<iostream>
#include<cmath>
using namespace std;
#define MAXN 1005

long long read() {
	long long x = 0; bool f = 0;
	char ch = getchar();
	while(ch < 48 || ch > 57) {
		if(ch == 45) f = 1;
		ch = getchar();
	}
	while(ch >= 48 && ch <= 57) {
		x = (x << 3) + (x << 1) + (ch - 48);
		ch = getchar();
	}
	return f ? -x : x;
}

long long n, m, a[MAXN][MAXN], f[MAXN][MAXN][2], g[MAXN][MAXN][2], ans = 0;

int main() {
	freopen("tunnel.in", "r", stdin);
	freopen("tunnel.out", "w", stdout);
	
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) a[i][j] = read();
	for(int i = 2; i <= n; i ++) for(int j = 1; j <= m; j ++) 
        f[i][j][0] = max(f[i - 1][j][0], f[i - 1][j][1] + max(0ll, a[i - 1][j] + a[i][j])), 
        f[i][j][1] = max(f[i - 1][j][0], f[i - 1][j][1]);
    for(int i = 1; i <= n; i ++) for(int j = 2; j <= m; j ++)
        g[i][j][0] = max(g[i][j - 1][0], g[i][j - 1][1] + max(0ll, a[i][j - 1] + a[i][j])), 
        g[i][j][1] = max(g[i][j - 1][0], g[i][j - 1][1]);
    for(int i = 1; i <= m; i ++) ans += f[n][i][0];
    for(int i = 1; i <= n; i ++) ans += g[i][m][0];
    cout << ans << "\n";
	return 0;
}

序列上的树(tree)

题目描述

输入格式

输出格式

\(\text{input1}\)

5
1 2 1 2 1

\(\text{output1}\)

8

\(\text{input2}\)

9
1 2 1 3 4 3 5 3 1

\(\text{output2}\)

15

样例解释

数据范围

tree.zip

#include<iostream>
using namespace std;
#define MAXN 200005

long long read() {
	long long x = 0; bool f = 0;
	char ch = getchar();
	while(ch < 48 || ch > 57) {
		if(ch == 45) f = 1;
		ch = getchar();
	}
	while(ch >= 48 && ch <= 57) {
		x = (x << 3) + (x << 1) + (ch - 48);
		ch = getchar();
	}
	return f ? -x : x;
}

long long n, a[MAXN], ans = 0, cnt = 0, b[MAXN], p[MAXN];
bool c[MAXN];

int main() {
	freopen("tree.in", "r", stdin);
	freopen("tree.out", "w", stdout);
	
	n = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	for(int i = 1; i <= n; i ++) {
		b[++ cnt] = a[i];
		if(b[cnt] == b[cnt - 2] && !c[b[cnt - 1]]) 
			c[b[cnt - 1]] = true, cnt -= 2;
	}
	if(cnt == 1) {
		for(int i = 1; i <= n; i ++) p[a[i]] ++;
		for(int i = 1; i <= n; i ++) ans += (p[i] - 1) * p[i] / 2;
		cout << ans + n << "\n";
		return 0;
	}
	for(int l = 1; l < n - 1; l ++) for(int r = l + 2; r <= n; r ++) {
		if(a[l] != a[r]) continue; cnt = 0;
		for(int i = l; i <= r; i ++) c[a[i]] = false;
		for(int i = l; i <= r; i ++) {
			b[++ cnt] = a[i];
			if(b[cnt] == b[cnt - 2] && !c[b[cnt - 1]]) 
				c[b[cnt - 1]] = true, cnt -= 2;
		}
		if(cnt == 1) ans ++;
	}
	cout << ans + n << "\n";
	return 0;
}

生存(survive)

题目描述

输入格式

输出格式

\(\text{input1}\)

3 2
1 2 3
1 2
2 3
1 2
2 1 2

\(\text{output1}\)

5

样例解释

数据范围

survive.zip

#include<iostream>
#include<vector>
using namespace std;
#define MAXN 1000005

long long read() {
	long long x = 0; bool f = 0;
	char ch = getchar();
	while(ch < 48 || ch > 57) {
		if(ch == 45) f = 1;
		ch = getchar();
	}
	while(ch >= 48 && ch <= 57) {
		x = (x << 3) + (x << 1) + (ch - 48);
		ch = getchar();
	}
	return f ? -x : x;
}

long long n, m, a[MAXN], ans = 0;

int main() {
	freopen("survive.in", "r", stdin);
	freopen("survive.out", "w", stdout);
	
	n = read(); m = read();
	for(int i = 1; i <= n; i ++) a[i] = read();
	for(int i = 1; i <= n; i ++) ans += a[i];
	cout << ans << "\n";
	return 0;
}

\[100 + 35 + 50 + 0 = 185 \]

标签:26,ch,48,text,long,while,Day,模拟,getchar
From: https://www.cnblogs.com/So-noSlack/p/18338616

相关文章

  • SPONGE常用教程:蛋白+配体模拟3
    前序课程1前序课程2目录应用场景简述;-[Done]DSDP:蛋白-配体对接;-[Done]XPONGE:蛋白-配体建模,加溶剂;-[Done]SPONGE:能量极小化-NVT-NPT-正式模拟;-[Done]XPONGE:数据简单后处理。5.XPONGE:数据简单后处理经过1ns的SPONGE分子动力学模拟,得到了轨迹文件"mdcrd.dat......
  • Day 31 贪心算法 Part05
    56.合并区间区间这类问题,不是按照左端点排序就是按照右端点排序,在思考思路的时候,就从这两个方向去下手,然后再去想贪心,以及从左侧开始遍历还是右侧开始遍历。classSolution{publicint[][]merge(int[][]intervals){if(intervals.length==1)returninterva......
  • 题解:CF1301B Motarack's Birthday
    CF1301DTimetoRun题解思维题。分析把一个格子视作一个点,每个点的度数都是偶数,所以这是一张欧拉图。而需要走遍整个方格图,可以证明只要\(k\)不超过\(4nm-2n-2m\)就一定有解。很明显存在很多种方案,这里我用的方案是:从左上角出发,向右走\(m-1\)步到头,再向左走\(m-1\)......
  • Day17 二叉树Part5
    目录任务654.最大二叉树思路617.合并二叉树思路700.二叉搜索树中的搜索思路98.验证二叉搜索树思路(错误)思路(正确)心得体会任务654.最大二叉树给定一个不重复的整数数组nums。最大二叉树可以用下面的算法从nums递归地构建:创建一个根节点,其值为nums中的最大值。递归......
  • 代码随想录day17 || 654 最大二叉树,617 合并二叉树,700 二叉搜索树搜索,98 验证二叉搜索
    645最大二叉树funcconstructMaximumBinaryTree(nums[]int)*TreeNode{ //思路,算法思路基本等同于通过中序前序构造二叉树 //1,取最大值作为根节点 //2,切割数组 //3,递归左右子树 iflen(nums)==0{ returnnil } //切割数组取最大值 max,left,right:=......
  • day16 Java基础——JavaDoc生成文档
    day16Java基础——JavaDoc生成文档目录day16Java基础——JavaDoc生成文档1.什么是JavaDoc2.生成JavaDoc2.1通过命令行生成JavaDoc2.2使用IDEA生成JavaDoc1.什么是JavaDocJavaDoc是一种标准的、用于生成Java代码API文档的工具。它通过在Java源代码中特定的......
  • x264 中多线程相关编码参数详细介绍
    多线程编码相关参数参数名称参数类型参数含义cpuuint32_tcpu型号i_threadsint并行编码线程数i_lookahead_threadsint在lookahead分析中使用多线程b_deterministicint当开启多线程时是否允许非确定性优化b_sliced_threadsint是否使用基于......
  • DAY 15 二叉树part03
      110.平衡二叉树(优先掌握递归)题目链接/文章讲解/视频讲解:https://programmercarl.com/0110.%E5%B9%B3%E8%A1%A1%E4%BA%8C%E5%8F%89%E6%A0%91.html 独立完成,感觉还比较好理解12classSolution{13public:14boolisBalanced(TreeNode*root){15if(......
  • 嵌入式软件--C语言高级 DAY 8 函数
    函数是C语言尤为重要的知识点,再嵌入式的学习过程中,对51和32的单片机的学习是重中之重。一、函数的基本概念1.介绍函数是一种可重复使用的代码块,用于执行特定的任务或操作。函数允许我们将代码逻辑组织成独立的单元,从而提高了代码的可读性、可维护性和重用性。一个C程序可......
  • 嵌入式开发C语言学习day26-华清作业8.1
    思维导图作业//使用两个线程完成两个文件的拷贝,分支线程1拷贝前一半,分支线程2拷贝后一半,主线程回收两个分支线程的资源#include<myhead.h>#defineMAX1024structBuf{charfile1[20];charfile2[20];intsize;};//进程1拷贝前半内容void*copy......