当前位置:网站首页>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;
}

边栏推荐
- How to modify the error of easydss on demand service sharing time?
- [OpenGL] notes 29. Advanced lighting (specular highlights)
- 机器学习基础(二)——训练集和测试集的划分
- Unity skframework Framework (XVI), package manager Development Kit Manager
- SSL证书的分类有哪些?如何选择合适的SSL证书?
- I did it with two lines of code. As a result, my sister had a more ingenious way
- Web Foundation
- Unity SKFramework框架(十六)、Package Manager 開發工具包管理器
- Tupang multi-target tracking! BOT sort: robust correlated multi pedestrian tracking
- Ali on three sides, it's really difficult to successfully get the offer rated P7
猜你喜欢

net share

Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
![[opencv learning] [template matching]](/img/4c/7214329a34974c59b4931c08046ee8.jpg)
[opencv learning] [template matching]

Unity SKFramework框架(十三)、Question 问题模块
![[indomitable medal activity] life goes on and writing goes on](/img/c1/54e3f1b37db25af3f1998b39da301b.png)
[indomitable medal activity] life goes on and writing goes on
![[opencv learning] [Canny edge detection]](/img/8b/37694ae2f0f13f829f3c033da0605e.jpg)
[opencv learning] [Canny edge detection]

诚邀青年创作者,一起在元宇宙里与投资人、创业者交流人生如何做选择……...

What are eNB, EPC and PGW?

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

Unity skframework framework (XVII), freecameracontroller God view / free view camera control script
随机推荐
Chinese name extraction (toy code - accurate head is too small, right to play)
De4000h storage installation configuration
[indomitable medal activity] life goes on and writing goes on
Unity skframework framework (XVII), freecameracontroller God view / free view camera control script
Ruby: how to copy variables without pointing to the same object- Ruby: how can I copy a variable without pointing to the same object?
Record idea shortcut keys
每日一题:1175.质数排列
Unity skframework framework (XXI), texture filter map resource filtering tool
Why can't d link DLL
Download files and preview pictures
Domestic free data warehouse ETL dispatching automation operation and maintenance expert taskctl
Post order traversal sequence of 24 binary search tree of sword finger offer
上海交大教授:何援军——包围盒(包容体/包围盒子)
Clean up system cache and free memory under Linux
科技的成就(二十七)
Unity skframework framework (XVIII), roamcameracontroller roaming perspective camera control script
West digital decided to raise the price of flash memory products immediately after the factory was polluted by materials
What are the classifications of SSL certificates? How to choose the appropriate SSL certificate?
Numpy array calculation
自主可控三维云CAD:CrownCAD赋能企业创新设计