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

原网站

版权声明
本文为[NO.-LL]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141242070845.html