当前位置:网站首页>题解:《压缩技术》(原版、续集版)
题解:《压缩技术》(原版、续集版)
2022-07-02 10:09:00 【潘道熹】
压缩技术
题目描述
设某汉字由N × N的0和1的点阵图案组成。
我们依照以下规则生成压缩码。连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下。第一个数表示连续有几个0,第二个数表示接下来连续有几个1,第三个数再接下来连续有几个0,第四个数接着连续几个1,以此类推……
例如: 以下汉字点阵图案:
0001000
0001000
0001111
0001000
0001000
0001000
1111111
对应的压缩码是: 7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 (第一个数是N ,其余各位表示交替表示0和1 的个数,压缩码保证 N × N=交替的各位数之和)
输入格式
一行,压缩码。
输出格式
汉字点阵图(点阵符号之间不留空格)。(3<=N<=200)
样例 #1
样例输入 #1
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
样例输出 #1
0001000
0001000
0001111
0001000
0001000
0001000
1111111
题解
当时我看到这道题,觉得:啊很简单啊,直接输出不就完了。
一做,人傻了。所以永远不要把问题想得很简单啊!
有的时候,真的是“差之毫厘,失之千里”。我前面三次都没对,就改了一句程序就AC。
// Author:PanDaoxi
#include <iostream>
using namespace std;
// 可以不用二维数组,直接一次数组
int a[40201];
int main(){
int n,m,k=0,text,tmp=1,t;
// m*m的方格
cin>>m;
while(cin>>n){
// 使用的字符
text=k%2;
// 接下来,连着n个text
t=tmp,tmp+=n;
for(int i=t;i<tmp;i++){
// 写入数组
a[i]=text;
}
// 下一个数
k++;
}
// 输出
for(int i=1;i<=m*m;i++){
cout<<a[i];
// 如果当前字符的数量满足被m整除,就该换行了
if(i%m==0) cout<<endl;
}
return 0;
}
可以用布尔类型的数组,进一步优化:
// Author:PanDaoxi
#include <iostream>
using namespace std;
bool a[40201],text=true;
int main(){
int n,m,tmp=1,t;
cin>>m;
while(cin>>n){
text=!text,t=tmp,tmp+=n;
for(int i=t;i<tmp;i++){
a[i]=text;
}
}
for(int i=1;i<=m*m;i++){
cout<<a[i];
if(i%m==0) cout<<endl;
}
return 0;
}

压缩技术(续集版)
题目描述
设某汉字由N × N的0和1的点阵图案组成。
我们依照以下规则生成压缩码。连续一组数值:从汉字点阵图案的第一行第一个符号开始计算,按书写顺序从左到右,由上至下。第一个数表示连续有几个0,第二个数表示接下来连续有几个1,第三个数再接下来连续有几个0,第四个数接着连续几个1,以此类推……
例如: 以下汉字点阵图案:
0001000
0001000
0001111
0001000
0001000
0001000
1111111
对应的压缩码是: 7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 (第一个数是N ,其余各位表示交替表示0和1 的个数,压缩码保证 N×N = 交替的各位数之和)
输入格式
汉字点阵图(点阵符号之间不留空格)。(3<=N<=200)
输出格式
一行,压缩码。
样例 #1
样例输入 #1
0001000
0001000
0001111
0001000
0001000
0001000
1111111
样例输出 #1
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
题解
费了好大的力气,终于搞下来了(我不行啊)
想了好多的办法,想了个奇怪的办法
// Author:PanDaoxi
#include <iostream>
#include <cmath>
using namespace std;
int a[40200],n=0,point=0; // point储存下标
int main(){
char x,y='0';
while(cin>>x){
// 输入字符
// 字符数+1
n++;
// 判断:如果现在的和刚才的一样
if(x==y) a[point]++;
// 如果不一样,更新字符
else a[point++]++,y=x;
}
// 因为n*n的矩阵,那么n= n的算术平方根
cout<<sqrt(n)<<" ";
// 特殊值处理
a[0]--,a[point]++;
// 输出就完了
for(int i=0;i<=point;i++){
cout<<a[i]<<" ";
}
return 0;
}

边栏推荐
- Jerry's watch gets the default ringtone selection list [article]
- net share
- How much do you know about free SSL certificates? The difference between free SSL certificate and charged SSL certificate
- Ltc3307ahv meets EMI standard, step-down converter qca7005-al33 phy
- Daily question: 1175 Prime permutation
- Clean up system cache and free memory under Linux
- 最近公共祖先LCA的三种求法
- [OpenGL] notes 29. Advanced lighting (specular highlights)
- JS reverse row query data decryption
- 机器学习基础(二)——训练集和测试集的划分
猜你喜欢

We sincerely invite young creators to share with investors and entrepreneurs how to make choices in life in the metauniverse
![[opencv learning] [moving object detection]](/img/2e/9b437b7fe22f1d57334529eda68e37.jpg)
[opencv learning] [moving object detection]

EasyDSS点播服务分享时间出错如何修改?

Independent and controllable 3D cloud CAD: crowncad enables innovative design of enterprises

Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本

国产免费数据仓库ETL调度自动化运维专家—TASKCTL

二、帧模式 MPLS 操作

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

Finally, someone explained the supervised learning clearly

mac(macos Monterey12.2 m1) 个人使用php开发
随机推荐
Redis数据库持久化
记忆函数的性能优化
Node.js通过ODBC访问PostgreSQL数据库
Unity SKFramework框架(十四)、Extension 扩展函数
日本赌国运:Web3.0 ,反正也不是第一次失败了!
EasyDSS点播服务分享时间出错如何修改?
Explanation of 34 common terms on the Internet
Fundamentals of face recognition (facenet)
阿里初面被两道编程题给干掉,再次内推终上岸(已拿电子offer)
上海交大教授:何援军——包围盒(包容体/包围盒子)
Ali on three sides, it's really difficult to successfully get the offer rated P7
[opencv learning] [image pyramid]
OpenAPI generator: simplify the restful API development process
Unity skframework framework (XV), singleton singleton
Numpy array calculation
Uniapp develops wechat applet Tencent map function and generates sig signature of location cloud
Download files and preview pictures
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
How to get the operating system running PHP- How to get the OS on which PHP is running?
net share