BIT_201906【B - Visual Cube】

思路:

  • 画图题。初始化为 ‘.’ ,画出图形。

代码:

  • 46ms 1004KB
#include <iostream>
#include <cstring>

using namespace std;

const int maxn = 1005;

int A,B,C;
int length , height;
char mp[maxn][maxn];

int main(){
	int T;cin>>T;
	while(T--){
		cin>>A>>B>>C;
		length = 2*A + 1 + 2*B;
		height = 2*C + 1 + 2*B;
		memset(mp , '.' , sizeof(mp));
		for(int i=0;i<=B;i++){
			int row = 2*i + 1;
			int line = row;
			mp[line][row] = '+';
			for(int j=1;j<=C;j++){
				line += 2;
				mp[line][row] = '+';
				mp[line - 1][row] = '|';
			}
			line = row ;
			for(int j=1;j<=A;j++){
				row += 2;
				mp[line][row] = '+';
				mp[line][row - 1] = '-';
			}
		}
		for(int i=1;i<=C;i++){
			int line = 2*B + 1 + 2*i;
			int row = 2*B + 1;
			for(int j=1;j<=A;j++){
				row += 2;
				mp[line][row] = '+';
				mp[line][row - 1] = '-';
			}
		}
		for(int i=1;i<=B;i++){
			int line = 2*i;
			int row = line;
			for(int j=0;j<=C;j++){
				mp[line + 2*j][row] = '\\';
			}
			for(int j=0;j<=A;j++){
				mp[line][row + 2*j] = '\\';
			}
		}
		for(int i=1;i<=C;i++){
			int line = 2*B + 2*i;
			int row = 2*B + 1;
			for(int j=1;j<=A;j++){
				row += 2;
				mp[line][row] = '|';
			}
		}
		for(int i=1;i<=height;i++){
			for(int j=1;j<=length;j++)
				cout<<mp[i][j];
			cout<<endl;
		}
	}
	return 0;
}
import pygame from pygame.locals import * from OpenGL.GL import * from OpenGL.GLU import * import numpy as np # 设置方块大小 BLOCK_SIZE = 1.0 # 初始化 pygame 显示 def init_display(): pygame.init() display = (800, 600) pygame.display.set_mode(display, DOUBLEBUF | OPENGL) pygame.display.set_caption("我的世界 - 简化版") gluPerspective(45, (display[0] / display[1]), 0.1, 100.0) glTranslatef(0.0, 0.0, -5) # 初始后移观察世界 # 创建一个平面作为地面 def create_world(): world = {} for x in range(-10, 11): for z in range(-10, 11): y = 0 # 地面高度 world[(x, y, z)] = (0.2, 0.6, 0.2) # 绿色地面 return world # 绘制一个立方体(方块) def draw_cube(position, color): x, y, z = position vertices = [ [x, y, z], [x + BLOCK_SIZE, y, z], [x + BLOCK_SIZE, y + BLOCK_SIZE, z], [x, y + BLOCK_SIZE, z], [x, y, z + BLOCK_SIZE], [x + BLOCK_SIZE, y, z + BLOCK_SIZE], [x + BLOCK_SIZE, y + BLOCK_SIZE, z + BLOCK_SIZE], [x, y + BLOCK_SIZE, z + BLOCK_SIZE] ] edges = [ (0,1), (1,2), (2,3), (3,0), (4,5), (5,6), (6,7), (7,4), (0,4), (1,5), (2,6), (3,7) ] faces = [ (0,1,2,3), (4,5,6,7), (0,1,5,4), (2,3,7,6), (0,3,7,4), (1,2,6,5) ] # 绘制面(带颜色填充) glBegin(GL_QUADS) glColor3f(*color) for face in faces: for i in face: glVertex3fv(vertices[i]) glEnd() # 绘制边框(黑色轮廓) glBegin(GL_LINES) glColor3f(0.0, 0.0, 0.0) for edge in edges: for vertex in edge: glVertex3fv(vertices[vertex]) glEnd() # 主循环 def main(): init_display() world = create_world() clock = pygame.time.Clock() # 视角控制变量 angle_x, angle_y = 0, 0 pos_x, pos_y, pos_z = 0, 1, 0 # 玩家位置 mouse_locked = True pygame.mouse.set_visible(not mouse_locked) pygame.event.set_grab(mouse_locked) running = True while running: dt = clock.tick(60) / 1000.0 # 帧时间差 for event in pygame.event.get(): if event.type == QUIT: running = False if event.type == KEYDOWN: if event.key == K_ESCAPE: mouse_locked = not mouse_locked pygame.mouse.set_visible(not mouse_locked) pygame.event.set_grab(mouse_locked) if event.type == MOUSEMOTION and mouse_locked: dx, dy = event.rel angle_x += dx * 0.15 angle_y -= dy * 0.15 angle_y = max(-89, min(89, angle_y)) # 限制上下看角度 # 获取按键状态 keys = pygame.key.get_pressed() forward = np.array([ np.sin(np.radians(angle_x)), 0, np.cos(np.radians(angle_x)) ]) right = np.array([ np.sin(np.radians(angle_x + 90)), 0, np.cos(np.radians(angle_x + 90)) ]) if keys[K_w]: pos_x += forward[0] * dt * 5 pos_z += forward[2] * dt * 5 if keys[K_s]: pos_x -= forward[0] * dt * 5 pos_z -= forward[2] * dt * 5 if keys[K_a]: pos_x -= right[0] * dt * 5 pos_z -= right[2] * dt * 5 if keys[K_d]: pos_x += right[0] * dt * 5 pos_z += right[2] * dt * 5 if keys[K_SPACE]: pos_y += dt * 3 if keys[K_LSHIFT]: pos_y -= dt * 3 # 鼠标点击交互 mouse_buttons = pygame.mouse.get_pressed() if mouse_buttons[0]: # 左键破坏方块 block_pos = (int(pos_x), int(pos_y), int(pos_z)) if block_pos in world: del world[block_pos] elif mouse_buttons[2]: # 右键放置方块 block_pos = (int(pos_x + 2 * np.sin(np.radians(angle_x))), int(pos_y), int(pos_z + 2 * np.cos(np.radians(angle_x)))) if block_pos not in world: world[block_pos] = (0.6, 0.6, 0.6) # 灰色新方块 # 更新视角 glLoadIdentity() gluPerspective(45, (800 / 600), 0.1, 100.0) # 计算视线方向 rad_x = np.radians(angle_x) forward_vec = [ np.sin(rad_x), np.sin(np.radians(angle_y)), np.cos(rad_x) ] target = (pos_x + forward_vec[0], pos_y + forward_vec[1], pos_z + forward_vec[2]) glRotatef(angle_y, 1, 0, 0) glRotatef(angle_x, 0, 1, 0) glTranslatef(-pos_x, -pos_y, -pos_z) # 渲染场景 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glEnable(GL_DEPTH_TEST) for block_pos, color in world.items(): draw_cube(block_pos, color) pygame.display.flip() pygame.quit() if __name__ == "__main__": main()
12-01
内容概要:本文介绍了一套针对智能穿戴设备的跑步/骑行轨迹记录系统实战方案,旨在解决传统运动APP存在的定位漂移、数据断层和路径分析单一等问题。系统基于北斗+GPS双模定位、惯性测量单元(IMU)和海拔传感器,实现高精度轨迹采集,并通过卡尔曼滤波算法修正定位误差,在信号弱环境下利用惯性导航补位,确保轨迹连续性。系统支持跑步与骑行两种场景的差异化功能,包括实时轨迹记录、多维度路径分析(如配速、坡度、能耗)、数据可视化(地图标注、曲线图、3D回放)、异常提醒及智能优化建议,并可通过蓝牙/Wi-Fi同步数据至手机APP,支持社交分享与专业软件导出。技术架构涵盖硬件层、设备端与手机端软件层以及云端数据存储,强调低功耗设计与用户体验优化。经过实测验证,系统在定位精度、续航能力和场景识别准确率方面均达到预期指标,具备良好的实用性和扩展性。; 适合人群:具备一定嵌入式开发或移动应用开发经验,熟悉物联网、传感器融合与数据可视化的技术人员,尤其是从事智能穿戴设备、运动健康类产品研发的工程师和产品经理;也适合高校相关专业学生作为项目实践参考。; 使用场景及目标:① 开发高精度运动轨迹记录功能,解决GPS漂移与断点问题;② 实现跑步与骑行场景下的差异化数据分析与个性化反馈;③ 构建完整的“终端采集-手机展示-云端存储”系统闭环,支持社交互动与商业拓展;④ 掌握低功耗优化、多源数据融合、动态功耗调节等关键技术在穿戴设备中的落地应用。; 阅读建议:此资源以真实项目为导向,不仅提供详细的技术实现路径,还包含硬件选型、测试验证与商业扩展思路,建议读者结合自身开发环境,逐步实现各模块功能,重点关注定位优化算法、功耗控制策略与跨平台数据同步机制的设计与调优。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值