当前位置:网站首页>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;
}边栏推荐
- openresty 限流
- Alcohol driving monitoring system based on stm32+ Huawei cloud IOT design
- 潘多拉 IOT 开发板学习(RT-Thread)—— 实验3 按键实验(学习笔记)
- C language small commodity management system
- Digi restarts XBee Pro S2C production. Some differences need to be noted
- Comment configurer un accord
- 5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
- 电商系统中红包活动设计
- 深度学习7 Transformer系列实例分割Mask2Former
- 关于FPGA底层资源的细节问题
猜你喜欢

深度学习 神经网络的优化方法

LVGL 8.2 text shadow

信号处理之一阶RC低通滤波器宏指令实现(繁易触摸屏)

Digi restarts XBee Pro S2C production. Some differences need to be noted

How to match chords

LVGL 8.2 Line

如何搭建一支搞垮公司的技术团队?

Sqlserver functions, creation and use of stored procedures
![leetcode:6109. Number of people who know the secret [definition of DP]](/img/95/03e2606b249f26db052cf5075041c1.png)
leetcode:6109. Number of people who know the secret [definition of DP]

Docker compose public network deployment redis sentinel mode
随机推荐
关于miui12.5 红米k20pro用au或者povo2出现问题的解决办法
Detailed explanation of visual studio debugging methods
Programmer turns direction
Solutions aux problèmes d'utilisation de l'au ou du povo 2 dans le riz rouge k20pro MIUI 12.5
92. (cesium chapter) cesium building layering
电商系统中红包活动设计
一文概览2D人体姿态估计
金额计算用 BigDecimal 就万无一失了?看看这五个坑吧~~
函数计算异步任务能力介绍 - 任务触发去重
Introduction to asynchronous task capability of function calculation - task trigger de duplication
MySQL stored procedure exercise
信号处理之一阶RC低通滤波器宏指令实现(繁易触摸屏)
關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
如何搭建一支搞垮公司的技术团队?
Memory management summary
Digi XBee 3 RF: 4个协议,3种封装,10个大功能
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
曝光一下阿里的工资待遇和职位级别
Yyds dry goods inventory # solve the real problem of famous enterprises: continuous maximum sum
Count the running time of PHP program and set the maximum running time of PHP