当前位置:网站首页>Luo Gu - some interesting questions 2
Luo Gu - some interesting questions 2
2022-07-04 14:51:00 【NO.-LL】
Catalog
P5730 【 Deep base 5. example 10】 display - Character table problem
P2141 [NOIP2014 Popularization group ] Abacus mental arithmetic test - Array de duplication method
P1553 Number reversal ( Upgraded version )- details
P1205 [USACO1.2] Block conversion Transformations - Violent simulation
P5730 【 Deep base 5. example 10】 display - Character table problem

Output #1
XXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX X.X...X...X...X.X.X.X...X.....X.X.X.X.X X.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX X.X...X.X.....X...X...X.X.X...X.X.X...X XXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX
Forced manual marking :( After typing the watch, the exam is over )
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
char W[10][5][3]=//W[i][j][k] It means the first one i The third digit j OK, No k Column ,( I'm so tired from hand beating )
{
{//0
'X','X','X',
'X','.','X',
'X','.','X',
'X','.','X',
'X','X','X',
},
{//1
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//2
'X','X','X',
'.','.','X',
'X','X','X',
'X','.','.',
'X','X','X',
},
{//3
'X','X','X',
'.','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//4
'X','.','X',
'X','.','X',
'X','X','X',
'.','.','X',
'.','.','X',
},
{//5
'X','X','X',
'X','.','.',
'X','X','X',
'.','.','X',
'X','X','X',
},
{//6
'X','X','X',
'X','.','.',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//7
'X','X','X',
'.','.','X',
'.','.','X',
'.','.','X',
'.','.','X',
},
{//8
'X','X','X',
'X','.','X',
'X','X','X',
'X','.','X',
'X','X','X',
},
{//9
'X','X','X',
'X','.','X',
'X','X','X',
'.','.','X',
'X','X','X',
}
};
int n;
char s[110];
int main(){
cin>>n;// Input n
for(int i=0;i<n;i++){
cin>>s[i];// Enter the characters to print
}
for(int i=0;i<5;i++){// Enumerate each row
for(int j=0;j<n;j++){// Enumerate every number
for(int k=0;k<3;k++){// Enumerate the columns of each number
cout<<W[s[j]-'0'][i][k];// Output , because s[j] Character , So subtract '0'
}
if(j!=n-1) cout<<'.';// If the last column , You don't need to print '.'
}
cout<<endl;// Line break
}
return 0;
}Copy and paste :
#include<stdio.h>
#include<string.h>
char s[5][55] = {
"XXX...X.XXX.XXX.X.X.XXX.XXX.XXX.XXX.XXX.",
"X.X...X...X...X.X.X.X...X.....X.X.X.X.X.",
"X.X...X.XXX.XXX.XXX.XXX.XXX...X.XXX.XXX.",
"X.X...X.X.....X...X...X.X.X...X.X.X...X.",
"XXX...X.XXX.XXX...X.XXX.XXX...X.XXX.XXX.",
};
int main()
{
int n;
int len, i, x;
int j, k;
char str[110];
scanf("%d", &n);
scanf("%s", str);
len = strlen(str);
for (j = 0; j < 5; ++j)// Yes 5 That's ok
{
// Print the... Except the last character j That's ok
for (i = 0; i < len - 1; ++i)
{
x = str[i] - '0';
for (k = 4 * x; k <= 4 * x + 3; ++k)// Cut off the corresponding number 4 Column
printf("%c", s[j][k]);
}
// Devil details : The last number is 3 Column
x = str[i] - '0';
for (k = 4 * x; k <= 4 * x + 2; ++k)
printf("%c", s[j][k]);
printf("\n");
}
return 0;
}
P2141 [NOIP2014 Popularization group ] Abacus mental arithmetic test - Array de duplication method

difficulty :
Data elements cannot be duplicated
PS: At first glance, the solution only thinks of adding two elements, which cannot be repeated
( Actually, I don't consider , The values of different elements may be the same , Just consider that the added elements do not represent the same variables )
The main card of this question is not only to match when counting a+b=c Of c Just count the number of , Also need to consider c Whether it has been included .
in other words , For example, there are 1 2 3 4 5,1+4 and 2+3 All equal to 5, But it can only be counted as one
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
typedef long long LL;
const int N=1e5+10;
using namespace std;
int n;
int ans[N],num[N];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>ans[i];
num[ans[i]]=1; // Used to detect whether it has been used
}
int sum=0;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(num[ans[i]+ans[j]]==1)
sum++;
num[ans[i]+ans[j]]=0; // Used , duplicate removal
}
}
cout<<sum;
return 0;
}P1553 Number reversal ( Upgraded version )- details
Give a number , Please reverse the number in each digit to get a new number .
This time with NOIp2011 The first question of the popularization group is different from : This number can be a decimal , fraction , percentage , Integers . Integer inversion is the transposition of all digits ; Decimal inversion is to invert the number of the integral part , Then invert the decimal part , Don't swap the integer part with the decimal part ; Fractional inversion is to invert the number of denominator , And then reverse the number of molecules , Don't exchange numerator and denominator ; The numerator of a percentage must be an integer , Percentages change only the numerical part . New integer numbers should also satisfy the common forms of integers , That is, unless the given original number is zero , Otherwise, the highest digit of the new number after inversion should not be zero ; The end of a new decimal number is not 0( Except for the fraction except 0 There are no other numbers , So just keep 1 individual 0); There are no approximate points , Neither numerator nor denominator is a decimal ( I'm sorry , I can't do it . Input data to ensure that the denominator is not 0), There are no negative numbers this time .
Title Description
Give a number , Please reverse the number in each digit to get a new number .
This time with NOIp2011 The first question of the popularization group is different from : This number can be a decimal , fraction , percentage , Integers .
Integer inversion is the transposition of all digits .
Decimal inversion is to invert the number of the integral part , Then invert the decimal part , Don't swap the integer part with the decimal part .
Fractional inversion is to invert the number of denominator , And then reverse the number of molecules , Don't exchange numerator and denominator .
The numerator of a percentage must be an integer , Percentages change only the numerical part .
Input format
a number s
Output format
a number , namely s Inversion number of

The core of the algorithm is Remove leading zeros .
And the integer part 、 After the decimal part is reversed , The rules for removing leading zeros are different , It needs to be discussed separately .
Integer inversion removes leading zeros : First save the integer as a string s, And then from s[s.length()-1] towards s[0] Traverse , If to s[0] still 0, It outputs 0.
Decimal inversion removes leading zeros : First save the decimal as a string s, And then from s[0] towards s[s.length()-1] Traverse , If to s[s.length()-1] still 0, It outputs 0.
Wrong writing :75 branch
Adapted from number reversal , The general idea is divided into three parts , Reverse left and right , Intermediate characters are output directly
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
typedef long long LL;
const int N = 1e5 + 10;
using namespace std;
int a[N], n;
int fz(string fzs)
{
int sz = 0,len=0;
for (int i = 0; fzs[i] != '\0'; i++)
{
len++;
}
for (int i = len - 1; i >= 0; i--)
{
sz *= 10;
sz += fzs[i] - '0';
}
return sz;
}
int main()
{
string s1, s3, s;
char s2;
int flag = 0, i, k = 0;
cin >> s;
s1 = s3 = s;
for (i = 0; i < s.length(); i++)
{
if (s[i] < '0' || s[i]>'9')
{
flag = 1;
s1[i] = '\0';
break;
}
s1[i] = s[i];
}
if (flag == 0)
{
int ret = fz(s1);
cout << ret;
}
else
{
s2 = s[i];
for (++i; s[i] != '\0'; i++)
{
s3[k++] = s[i];
}
s3[k] = '\0';
int ret1 = fz(s1);
if(s2=='%')
{
cout<<ret1<<s2;
return 0;;
}
int ret2 = fz(s3);
cout << ret1 << s2 << ret2;
}
return 0;
}
If you write like this, you will encounter 600.084 Returns the 6.480; The leading cannot be removed 0
AC How to write it :( Only step by step details )
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
char p=0;// Put symbols
int cnt=0;
cin>>s;
for(int i=0;i<s.size();i++)
{
if(s[i]>='0'&&s[i]<='9') cnt++;// Record the length of the first number
else // Encounter symbols , Record , Jump out of
{
p=s[i];
break;
}
}
int x=cnt;// Write down the last position of the first number , That is, the position of the symbol , If it's fractions or decimals, use
cnt--;
while(s[cnt]=='0'&&cnt>0) cnt--;// Remove excess preamble 0;
for(int i=cnt;i>=0;i--)// Output the first number
cout<<s[i];
if(p==0) return 0;// Unsigned return 0
else
if(p=='%') {cout<<p;return 0;}
else cout<<p;// Others continue
int m=s.size()-1;
while(s[x+1]=='0'&&x<m-1) x++;// Remove the end 0
while(s[m]=='0'&&m>x+1) m--; // Remove excess preamble 0
for(int i=m;i>x;i--)// Output the second number
cout<<s[i];
return 0;
}P1205 [USACO1.2] Block conversion Transformations - Violent simulation


3 @[email protected] --- @@- @[email protected] @-- [email protected]
My horse , Very violent simulation problem , It's over with a rattle
《 Thoroughly understand the simulation 》
#include<bits/stdc++.h>
using namespace std;
int n;
char a[15][15],b[15][15],c[15][15],d[15][15];
bool check(char s[15][15]) {
for(int i = 1;i <= n;i++) {
for(int j = 1;j <= n;j++) {
if(s[i][j] != c[i][j])
return false;
}
}
return true;
}
bool work1()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[j][n-i+1]=a[i][j];
}
if(check(b)) return true;
return false;
}
bool work2()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[n-i+1][n-j+1]=a[i][j];
}
if(check(b)) return true;
return false;
}
bool work3()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[n-j+1][i]=a[i][j];
}
if(check(b)) return true;
return false;
}
bool work4()
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
b[i][n-j+1]=a[i][j];
}
if(check(b)) return true;
return false;
}
bool work5()
{
work4();
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work1())
return 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work2())
return 1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
a[i][j]=b[i][j];
if(work3())
return 1;
return 0;
}
bool work6()
{
if(check(b)) return true;
return false;
}
void work()
{
if(work1())
{
cout<<1;
return ;
}
if(work2())
{
cout<<2;
return ;
}
if(work3())
{
cout<<3;
return ;
}
if(work4())
{
cout<<4;
return ;
}
if(work5())
{
cout<<5;
return ;
}
if(work6())
{
cout<<6;
return ;
}
cout<<7;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
d[i][j]=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>c[i][j];
work();
return 0;
}边栏推荐
- LVGL 8.2 text shadow
- 炒股网上开户安全吗?会不会被骗。
- LVGL 8.2 Sorting a List using up and down buttons
- LVGL 8.2 Draw label with gradient color
- 如何配和弦
- Chapter 16 string localization and message Dictionary (2)
- How to match chords
- Solutions to the problems of miui12.5 red rice k20pro using Au or povo2
- 函数计算异步任务能力介绍 - 任务触发去重
- Exploration and practice of eventbridge in the field of SaaS enterprise integration
猜你喜欢

IO flow: node flow and processing flow are summarized in detail.

No servers available for service: xxxx

Transplant tinyplay for imx6q development board QT system

Comment configurer un accord

内存管理总结

Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态

为什么国产手机用户换下一部手机时,都选择了iPhone?

Leecode learning notes - Joseph problem

软件测试之测试评估
![[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control](/img/cc/70007321395afe3a9fc6b6032d30aa.png)
[MySQL from introduction to proficiency] [advanced chapter] (IV) MySQL permission management and control
随机推荐
Stm32f1 and stm32subeide programming example -max7219 drives 8-bit 7-segment nixie tube (based on GPIO)
PyTorch的自动求导机制详细解析,PyTorch的核心魔法
Expose Ali's salary and position level
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
LVGL 8.2 List
LVGL 8.2 LED
Summary of common problems in development
10. (map data) offline terrain data processing (for cesium)
UFO: Microsoft scholars have proposed a unified transformer for visual language representation learning to achieve SOTA performance on multiple multimodal tasks
LVGL 8.2 List
Halo effect - who says that those with light on their heads are heroes
炒股网上开户安全吗?会不会被骗。
Leecode learning notes - Joseph problem
LVGL 8.2 Line
Ali was laid off employees, looking for a job n day, headhunters came bad news
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
Kubernets Pod 存在 Finalizers 一直处于 Terminating 状态
微博、虎牙挺进兴趣社区:同行不同路
深度学习7 Transformer系列实例分割Mask2Former
Sqlserver functions, creation and use of stored procedures