当前位置:网站首页>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;
}
边栏推荐
- Respect others' behavior
- 关于FPGA底层资源的细节问题
- LVGL 8.2 text shadow
- Halo effect - who says that those with light on their heads are heroes
- Count the running time of PHP program and set the maximum running time of PHP
- LVGL 8.2 text shadow
- Query optimizer for SQL optimization
- The failure rate is as high as 80%. What are the challenges on the way of enterprise digital transformation?
- 如何搭建一支搞垮公司的技术团队?
- LVGL 8.2 List
猜你喜欢
LVGL 8.2 Line
Implementation of macro instruction of first-order RC low-pass filter in signal processing (easy touch screen)
5g TV cannot become a competitive advantage, and video resources become the last weapon of China's Radio and television
自动控制原理快速入门+理解
Nowcoder reverse linked list
How to match chords
scratch古堡历险记 电子学会图形化编程scratch等级考试三级真题和答案解析2022年6月
Docker compose public network deployment redis sentinel mode
92. (cesium chapter) cesium building layering
函数计算异步任务能力介绍 - 任务触发去重
随机推荐
LVLG 8.2 circular scrolling animation of a label
03-存储系统
Kubernets pod exists finalizers are always in terminating state
Popular framework: the use of glide
openresty 限流
Query optimizer for SQL optimization
微博、虎牙挺进兴趣社区:同行不同路
5G电视难成竞争优势,视频资源成中国广电最后武器
Scratch Castle Adventure Electronic Society graphical programming scratch grade examination level 3 true questions and answers analysis June 2022
自动控制原理快速入门+理解
Leetcode 61: rotating linked list
C language book rental management system
SAIC Maxus officially released its new brand "mifa", and its flagship product mifa 9 was officially unveiled!
Free, easy-to-use, powerful lightweight note taking software evaluation: drafts, apple memo, flomo, keep, flowus, agenda, sidenote, workflow
LVGL 8.2 Draw label with gradient color
STM32F1与STM32CubeIDE编程实例-MAX7219驱动8位7段数码管(基于GPIO)
關於miui12.5 紅米k20pro用au或者povo2出現問題的解决辦法
Five minutes of machine learning every day: why do we need to normalize the characteristics of numerical types?
深度学习 网络正则化
LVGL 8.2 Line wrap, recoloring and scrolling