首页 > 编程语言 >2022-2023-1《ICPC数据结构与算法》第一次练习题

2022-2023-1《ICPC数据结构与算法》第一次练习题

时间:2023-02-23 22:44:31浏览次数:36  
标签:练习题 cout int long ICPC step 2022 include define

7-5 环形解密(简)

image-20230223222446586

image-20230223222515054

这个题直接就是取模向前移动和向后移动

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

struct data {
	string id;
	int x;
	int y;
};
struct data a[1004];
signed main () {
	ios::sync_with_stdio(false);
	char x;
	int step;
	cin >> x >> step;
	if (step < 0) { //小于0向前移动
		step = -step; //将step变成正的
		cout << (char)(((x - 'a') + step) % 26 + 'a'); //先前循环移动就可以了


	} else {
		step = 2600000000 - step; //向后移动,比如向后移动3个就相当于向前移动26-3个位置
		//让很大的一个26的倍数减去step,然后就相当于将这个向后移动改成向前移动了,26的`倍数要足够大
		cout << (char)(((x - 'a') + step) % 26 + 'a'); //打印结果


	}


	return 0;
}

7-8 考试座位号

image-20230223223558573

这个题直接用结构体储存然后,进行m次查询就可以

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

struct data {
	string id;//编号
	int x;//试机座位号
	int y;//考试座位号
};
struct data a[1004];
signed main () {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i].id >> a[i].x >> a[i].y; //读入数据
	}
	int m;
	cin >> m;
	while (m--) {
		int b;
		cin >> b;
		for (int i = 0; i < n; i++) {
			if (b == a[i].x) { //当找到试机座位号
				cout << a[i].id << ' ' << a[i].y; //打印编号和考试座位号

				cout << '\n';
				break;

			}


		}


	}


	return 0;
}

7-2 排队候饭

image-20230223223521020

image-20230223223535613

这个题直接用贪心来做,先用sort排序然后从最小的开始检查当发现但当前的不能让其高兴的时候直接假想让他排到最后

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cstring>
#include <unordered_set>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <sstream>
#include <queue>
#define int long long
#define yes cout<<"YES"<<'\n'
#define no 	cout<<"NO"<<'\n'

using namespace std;

int a[100005];


signed main () {
	ios::sync_with_stdio(false);
	string s;
	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n); //排序
	int cnt = 0;
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (cnt <= a[i]) { //当cnt小于等于a[i]的时候
			res++;//让结果加1
			cnt = cnt + a[i]; //让cnt加上当前的值
		}

	}

	cout << res; //打印


	return 0;
}

未完待续

标签:练习题,cout,int,long,ICPC,step,2022,include,define
From: https://www.cnblogs.com/harper886/p/17149745.html

相关文章

  • 复现:西湖论剑2022
    mp3用MP3stego无密码解密mp3,得到txt   用binwalk分析mp3,发现有png,用foremost提取 用zsteg分析png,发现藏有zip,提取出来   zip加密了一个47.txt,用前面得......
  • 2022.2.23Android 开发之路
    今天学习了Android开发的设置视图的对齐方式设置视图的对齐方式有两种途径:采用layout_gravity属性,它指定了当前视图相对于上级视图的对齐方式采用gravity属性,它指定了下级......
  • 华为认证 Datacom 练习题
    1(单选题)下列配置默认路由的命令中,正确的是()。A、[Huawei]iproute-static0.0.0.00.0.0.0192.168.1.1B、[Huawei-Serial0]iproute-static0.0.0.00.0.0.00.0.0.0C、[......
  • Astute Graphics for Mac(全系列ai插件合集)支持ai 2022/2023
    哪里可以下载ai插件AstuteGraphics?今天macw小编为大家带来的是包含了AstuteGraphics出品的全系列21套AI插件:astutegraphics破解版下载。其中包含了包括颜色控制、图形剪......
  • Matlab 2022a 中文破解版软件包下载及图文安装教程​
    MATLAB是美国MathWorks公司出品的商业数学软件。它在数学类科技应用软件中在数值计算方面首屈一指。行矩阵运算、绘制函数和数据、实现算法、创建用户界面、连接其他编程语......
  • Matlab 2022b 中文破解版软件包下载及图文安装教程​
    MATLAB是美国MathWorks公司出品的商业数学软件。它在数学类科技应用软件中在数值计算方面首屈一指。行矩阵运算、绘制函数和数据、实现算法、创建用户界面、连接其他编程语......
  • 关于2022年3月14日到3月18日数据库发生数次断连的一些思考与总结
    1问题记录抽样调查3月14号九点到十点左右的时候医院医生反馈患者列表获取极其缓慢3月16号九点到十点左右的时候数据库发生断连超时3月17号12点左右数据库发生断连......
  • [.Net] 解决 Oracle.DataAccess 在 VS2022 下不兼容的问题
    环境VisualStudio2022Oracle.DataAccess.dllv4.121.2.0错误信息在VS中启动 IISExpress,收到报错信息Couldnotloadfileorassembly'Oracle.DataAccess'oro......
  • 2022-2023学年第二学期-实变函数
    课程信息作业课程信息曲阜师范大学统计学院,2021级数学与应用数学专业5-6班.上课时间地点:2-18周,周二1-2节数学楼201,周四1-2节数学楼201.教材:实变函......
  • vs2022 快速搭建imgui工程
    vcpkginstallimgui[dx11-binding]:x64-windows-staticvcpkginstallimgui[win32-binding]:x64-windows-static新建console工程点击查看代码//d3d11.lib;d3dc......