当前位置:网站首页>题解:《压缩技术》(原版、续集版)
题解:《压缩技术》(原版、续集版)
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;
}

边栏推荐
- [opencv learning] [image filtering]
- OpenApi-Generator:简化RESTful API开发流程
- 文件的下载与图片的预览
- Explain in detail the process of realizing Chinese text classification by CNN
- MySQL: Invalid GIS data provided to function st_ geometryfromtext
- 最近公共祖先LCA的三种求法
- Ali on three sides, it's really difficult to successfully get the offer rated P7
- Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
- moon
- PXE installation UOS prompt NFS over TCP not available from 10 x.x.x
猜你喜欢

Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment

国产免费数据仓库ETL调度自动化运维专家—TASKCTL
![Jerry's watch stops ringing [article]](/img/28/8a225b77b19360d2b0077a2b8c4b6d.jpg)
Jerry's watch stops ringing [article]

The second anniversary of the three winged bird: the wings are getting richer and the take-off is just around the corner

How can attribute mapping of entity classes be without it?

Answer: can the audio be set to on by default during easydss video on demand?

Apply lnk306gn-tl converter, non isolated power supply

Research shows that "congenial" is more likely to become friends

Professor of Shanghai Jiaotong University: he Yuanjun - bounding box (containment / bounding box)

Unity skframework framework (XVII), freecameracontroller God view / free view camera control script
随机推荐
numpy数组计算
[OpenGL] notes 29. Advanced lighting (specular highlights)
Principle analysis of security rememberme
Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?
Ali was killed by two programming problems at the beginning, pushed inward again, and finally landed (he has taken an electronic offer)
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures in detail! A little six
科技的成就(二十七)
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
Web Foundation
Japan bet on national luck: Web3.0, anyway, is not the first time to fail!
Download files and preview pictures
能自动更新的万能周报模板,有手就会用!
8A Synchronous Step-Down regulator tps568230rjer_ Specification information
EasyDSS点播服务分享时间出错如何修改?
The redis development document released by Alibaba covers all redis operations
Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
Ali on three sides, it's really difficult to successfully get the offer rated P7
OpenApi-Generator:简化RESTful API开发流程
Redis数据库持久化
Unity SKFramework框架(十五)、Singleton 单例