当前位置:网站首页>Solution: Compression Technology (original version and sequel version)
Solution: Compression Technology (original version and sequel version)
2022-07-02 13:29:00 【Pandaoxi】
List of articles
compression technique
Title Description
Let a Chinese character be composed of N × N Of 0 and 1 The dot matrix pattern of .
We generate compression codes according to the following rules . A continuous set of values : Start from the first symbol in the first line of the Chinese character dot matrix pattern , In writing order from left to right , From top to bottom . The first number represents several consecutive 0, The second number means that there are several consecutive 1, The third number is followed by several consecutive 0, The fourth number is followed by several consecutive 1, And so on ……
for example : The following Chinese character dot matrix pattern :
0001000
0001000
0001111
0001000
0001000
0001000
1111111
The corresponding compression code is : 7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 ( The first number is N , The rest of you say alternately 0 and 1 The number of , The compression code guarantees N × N= The sum of alternating numbers )
Input format
a line , Compression code .
Output format
Chinese character dot matrix ( There is no space between dot matrix symbols ).(3<=N<=200)
Examples #1
The sample input #1
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
Sample output #1
0001000
0001000
0001111
0001000
0001000
0001000
1111111
Answer key
At that time, I saw this problem , Think : Ah, it's simple , Direct output is not the end .
Do it , People are stupid . So never think of a simple problem !
sometimes , It's really “ Aware that , Lost thousands of miles ”. I haven't been right three times before , Just change one sentence of the program AC.
// Author:PanDaoxi
#include <iostream>
using namespace std;
// You don't need a two-dimensional array , Array directly once
int a[40201];
int main(){
int n,m,k=0,text,tmp=1,t;
// m*m Of the lattice
cin>>m;
while(cin>>n){
// Characters used
text=k%2;
// Next , Connect n individual text
t=tmp,tmp+=n;
for(int i=t;i<tmp;i++){
// Write array
a[i]=text;
}
// The next number
k++;
}
// Output
for(int i=1;i<=m*m;i++){
cout<<a[i];
// If the current number of characters meets the requirement of m to be divisible by , It's time for a new line
if(i%m==0) cout<<endl;
}
return 0;
}
You can use Boolean arrays , Further optimization :
// 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;
}

compression technique ( Sequel Edition )
Title Description
Let a Chinese character be composed of N × N Of 0 and 1 The dot matrix pattern of .
We generate compression codes according to the following rules . A continuous set of values : Start from the first symbol in the first line of the Chinese character dot matrix pattern , In writing order from left to right , From top to bottom . The first number represents several consecutive 0, The second number means that there are several consecutive 1, The third number is followed by several consecutive 0, The fourth number is followed by several consecutive 1, And so on ……
for example : The following Chinese character dot matrix pattern :
0001000
0001000
0001111
0001000
0001000
0001000
1111111
The corresponding compression code is : 7 3 1 6 1 6 4 3 1 6 1 6 1 3 7 ( The first number is N , The rest of you say alternately 0 and 1 The number of , The compression code guarantees N×N = The sum of alternating numbers )
Input format
Chinese character dot matrix ( There is no space between dot matrix symbols ).(3<=N<=200)
Output format
a line , Compression code .
Examples #1
The sample input #1
0001000
0001000
0001111
0001000
0001000
0001000
1111111
Sample output #1
7 3 1 6 1 6 4 3 1 6 1 6 1 3 7
Answer key
It took a lot of effort , Finally got it ( I can't )
Think of a lot of ways , Thought of a strange way
// Author:PanDaoxi
#include <iostream>
#include <cmath>
using namespace std;
int a[40200],n=0,point=0; // point Save subscript
int main(){
char x,y='0';
while(cin>>x){
// The input character
// Number of characters +1
n++;
// Judge : If the present one is the same as the previous one
if(x==y) a[point]++;
// If it's not the same , Update character
else a[point++]++,y=x;
}
// because n*n Matrix , that n= n The arithmetic square root of
cout<<sqrt(n)<<" ";
// Special value processing
a[0]--,a[point]++;
// The output is over
for(int i=0;i<=point;i++){
cout<<a[i]<<" ";
}
return 0;
}

边栏推荐
- [true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
- Numpy array calculation
- 2022零代码/低代码开发白皮书【伙伴云出品】附下载
- 屠榜多目标跟踪!BoT-SORT:稳健的关联多行人跟踪
- 基于ssm+jsp框架实现的学生选课信息管理系统【源码+数据库】
- Operation tutorial: how does easydss convert MP4 on demand files into RTSP video streams?
- [Unity]使用GB2312,打包后程序不正常解决方案
- Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
- 伙伴云表格强势升级!Pro版,更非凡!
- Embedded software development
猜你喜欢

国内首款、完全自主、基于云架构的三维CAD平台——CrownCAD(皇冠CAD)

中文姓名提取(玩具代码——准头太小,权当玩闹)
![[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials](/img/42/21f6d0fdd159faa8b63713624c95a2.png)
[true topic of the Blue Bridge Cup trials 43] scratch space flight children's programming explanation of the true topic of the Blue Bridge Cup trials
![[opencv learning] [contour detection]](/img/96/aaec61f137e4526c2c329e6fcfa1a2.jpg)
[opencv learning] [contour detection]

OpenAPI generator: simplify the restful API development process
![[error record] cannot open](/img/d3/0435ae698ad635be71729c7c047a22.jpg)
[error record] cannot open "XXX" because Apple cannot check whether it contains malware
![[opencv] [image gradient]](/img/37/1f366501e2b4e70ecee6365088167c.jpg)
[opencv] [image gradient]

挥发性有机物TVOC、VOC、VOCS气体检测+解决方案

Partner cloud form strong upgrade! Pro version, more extraordinary!

Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
随机推荐
三谈exception——错误处理
Fundamentals of face recognition (facenet)
Unity skframework framework (XX), VFX lab special effects library
Node. JS accessing PostgreSQL database through ODBC
numpy数组计算
nohup命令
JS generates 4-digit verification code
When tidb meets Flink: tidb efficiently enters the lake "new play" | tilaker team interview
[opencv] [image gradient]
Jerry's watch time synchronization [chapter]
Unity SKFramework框架(十八)、RoamCameraController 漫游视角相机控制脚本
能自动更新的万能周报模板,有手就会用!
免费SSL证书知多少?免费SSL证书和收费SSL证书的区别
科技的成就(二十七)
上海交大教授:何援军——包围盒(包容体/包围盒子)
2022 Heilongjiang provincial examination on the writing skills of Application Essays
操作教程:EasyDSS如何将MP4点播文件转化成RTSP视频流?
文件的下载与图片的预览
MySQL: Invalid GIS data provided to function st_ geometryfromtext
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials