Luogu brush questions: P1100 high and low exchange, word square, AB number pair, birthday, platform

The rubbish, I started rubbing the rubbish again, the code is not elegant~


high and low swap

topic description

gives a less than 2 32 2^{32}23 2 non-negative integers. This number can use a32 323 2 -bit binary representation (less than32 323 2 bits use0 00 complement). We call the first16 of this binary number 161 6 bits are "high bits", after16 161 6 bits are "lower bits". By exchanging its high and low bits, we can get a new number. What is this new number (expressed in decimal).

For example, the number 1314520 13145201 3 1 4 5 2 0 is expressed in binary as0000 0000 0001 0100 0000 1110 1101 1000 0000\,0000\,0001\,0100\,0000\,1110\,1101\,100000000000000101000000111011011 0 0 0 (added11 111 1 leading0 00 complement is32 323 2 bits), where the first16 161 6 bits are high bits, that is,0000 0000 0001 0100 0000\,0000\,0001\,01000000000000010 1 0 0 ; after16 161 6 bits are low bits, that is,0000 1110 1101 1000 0000\,1110\,1101\,10000000111011011 0 0 0 . Swap its high and low bits, and we get a new binary number0000 1110 1101 1000 0000 0000 0001 0100 0000\,1110\,1101\,1000\,0000\,0000\,0001\,010000001110110110000000000000010 1 0 0 . It is249036820 in decimal 249036820249036820

input format

One is less than 2 32 2^{32}23 2 non-negative integers

output format

output the new number

Example #1

Sample Input #1

1314520

Sample output #1

249036820

code show as below

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<string.h>

int main()
{
    
    
	int a[32];
	for(int i = 0;i < 32;i++)
	{
    
    
	 	a[i] = 0;
	}

	long long num;
	scanf("%lld",&num);
	long long y , x = 1;
	int i = 31;
	while(num != 0)
	{
    
    
		y = num % 2;
		a[i] = y;
		i--;
		num /= 2;
	}
	
	long long sum = 0;
	int j = 15;
	for(int i = 0;i < 16;i++)
	{
    
    
		sum = sum + a[i]*pow(2,j);
		j--;
	}

	int m = 31;
	for(int i = 16;i < 32;i++)
	{
    
    
		sum = sum + a[i]*pow(2,m);
		m--;
	}
	printf("%lld",sum);
	return 0;
 } 

word square

topic description

give a n × nn \times nn×A letter square matrix of n , which may contain multiple yizhongwordsWords are placed consecutively along the same direction in the square matrix. Can be placed along8 8In any of the 8 directions, the direction will not change when the same word is placed, and words can cross each other, so it is possible to share letters. On output, letters that are not words are *replacedFor example:

输入:
    8                     输出:
    qyizhong              *yizhong
    gydthkjy              gy******
    nwidghji              n*i*****
    orbzsfgz              o**z****
    hhgrhwth              h***h***
    zzzzzozo              z****o**
    iwdfrgng              i*****n*
    yyyygggg              y******g

input format

Enter a number nn in the first linen。(7 ≤ n ≤ 100 7 \le n \le 1007n100)。

The second line starts to enter n × nn \times nn×Alphabetical matrix of n .

output format

highlight n × nn \times n of wordsn×n -matrix.

Example #1

Sample Input #1

7
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa
aaaaaaa

Sample output #1

*******
*******
*******
*******
*******
*******
*******

Example #2

Sample Input #2

8
qyizhong
gydthkjy
nwidghji
orbzsfgz
hhgrhwth
zzzzzozo
iwdfrgng
yyyygggg

Sample output #2

*yizhong
gy******
n*i*****
o**z****
h***h***
z****o**
i*****n*
y******g

code show as below

#include<iostream>
using namespace std;
int c[10000][2],d=0,x[9]={
    
    0,1,0,1,-1,0,-1,1,-1};
int                 y[9]={
    
    0,0,1,1,0,-1,-1,-1,1};
char a[103][103],b,k[9]=" yizhong";
bool s[102][102];
bool f(int i,int j,int m,int n,int next){
    
    
    if(next>=8){
    
    
        s[i][j]=1;
        return 1;
    }
    if(a[i+m][j+n]==k[next])
        if(f(i+m,j+n,m,n,next+1)){
    
    
        	s[i][j]=1;
        	return 1;
        }
    return 0;
}
int main(){
    
    
    int n,i,j,o;
    cin>>n;
    for(i=1;i<=n;i++){
    
    
        for(j=1;j<=n;j++){
    
    
            cin>>b;
            if(b=='y'){
    
    
                c[++d][0]=i;
                c[d][1]=j;
            }
            a[i][j]=b;
        }
    }
    while(d){
    
    
        i=c[d][0];
        j=c[d][1];
        for(o=1;o<=8;o++){
    
    
           if(a[i+x[o]][j+y[o]]=='i')
              if(f(i+x[o],j+y[o],x[o],y[o],3))
                 s[i][j]=1;
        }
        d--;
    }
    for(i=1;i<=n;i++){
    
    
        for(j=1;j<=n;j++){
    
    
            if(s[i][j])cout<<a[i][j];
            else cout<<"*";
        }
        cout<<endl;
    }
    return 0;
}

AB pairs

topic background

Writing a question is a painful thing!

Reading too much of the same topic will cause aesthetic fatigue, so I abandoned the familiar A+B Problem and switched to AB haha!

topic description

Given a sequence of positive integers and a positive integer CCC , it is required to calculate all satisfiesA − B = CA - B = CAB=The number of pairs of numbers in C (pairs with the same numbers in different positions are counted as different pairs).

input format

Enter a total of two lines.

The first line, two positive integers N, CN, CN,C

Second line, NNN positive integers, as the string of numbers to be processed.

output format

One line, indicating that the string of positive integers contained in the string satisfies A − B = CA - B = CAB=The number of pairs of numbers in C.

Example #1

Sample Input #1

4 1
1 1 2 3

Sample output #1

3

hint

For 75 % 75\%7 5 % of the data,1 ≤ N ≤ 2000 1 \leq N \leq 20001N2000

For 100 % 100\%1 0 0 % of data,1 ≤ N ≤ 2 × 1 0 5 1 \leq N \leq 2 \times 10^51N2×105 0 ≤ a i < 2 30 0 \leq a_i <2^{30} 0ai<230, 1 ≤ C < 2 30 1 \leq C < 2^{30} 1C<230

2017/4/29 Added two sets of data

code show as below

#include<iostream>
#include<cstdio> 
#include<cmath>
#include<map>
#include<algorithm>
using namespace std;
int n,c;
long long ans;
map<int,int> a;
int num[200005];
int main()
{
    
    
    scanf("%d%d",&n,&c);
    for(int i=1;i<=n;i++)
    {
    
    
        scanf("%d",&num[i]);
        a[num[i]]++;    //当前数的个数++ 
    }
    for(int i=1;i<=n;i++)
    {
    
    
        ans+=a[num[i]+c];    //答案+=相差为c的数的个数,即a[num[i]+c]位置的数的个数 
    }
    printf("%lld",ans);
    return 0;
}

Birthday

topic description

Mr. cjf wants to investigate the birthdays of each student in the OI group of the school, and sort them in descending order of age. But Mr. cjf has a lot of homework recently and has no time, so please help her sort.

input format

Enter a total of 2 22 rows,

1st 11 behavior OI group total numbernnn

Second 2Line 2 ton + 1 n+1n+1 line is each person's namesss , year of birthyyy , monthmmm、 dayddd

output format

output a total of nnn lines,

ie nnThe names of n students with birthdays from oldest to youngest. (If two students have the same birthday, the student whose input is later will output first)

Example #1

Sample Input #1

3
Yangchu 1992 4 23
Qiujingya 1993 10 13
Luowen 1991 8 1

Sample output #1

Luowen
Yangchu
Qiujingya

hint

Data guarantee, 1 < n < 100 1<n<1001<n<100 1 ≤ ∣ s ∣ < 20 1\leq |s|<20 1s<20 . _ Guarantee that the year, month and day actually exist, and the year∈ [ 1960 , 2020 ] \in [1960,2020][1960,2020]

code show as below

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 20

typedef struct Person
//定义结构体
{
    
    
	 char name[N];
	 int year;
	 int month;
	 int day;
}Person;

int main()
{
    
    
	Person temp;//用来排序时交换顺序的中间量
	int num;
	Person birthday[101];//结构体数组
	scanf("%d",&num);
	for(int i=0;i<num;i++)
	{
    
    
		scanf("%s",birthday[i].name );
		scanf("%d",&birthday[i].year );
		scanf("%d",&birthday[i].month );
		scanf("%d",&birthday[i].day );
	}//输入完成,接下来开始排序
	if(num>1)
	{
    
    
		for(int m=0;m<num-1;m++)
		{
    
    
			for(int n=m+1;n<num;n++)
			{
    
    
				if(birthday[m].year >birthday[n].year ||(birthday[m].year ==birthday[n].year && birthday[m].month >birthday[n].month)||(birthday[m].year ==birthday[n].year&& birthday[m].month ==birthday[n].month&& birthday[m].day >=birthday[n].day))
				{
    
    
					temp=birthday[m];
					birthday[m]=birthday[n];
					birthday[n]=temp;
				}
			}
		}
	}//排序完成,直接输出
	for(int i=0;i<num;i++)
	{
    
    
		printf("%s\n",birthday[i].name);
	}
}

platform

topic description

There are some platforms in the space. Given the position of each platform, please calculate which platform it will fall on after falling from the edge of each platform. Note that if the abscissas of two edges of two platforms are the same, the object will not fall on the lower platform after falling from the upper platform. Platforms do not overlap, and no two platforms have their edges touching.

If there are two platforms of the same height and both can be dropped, then the platform with the higher number will fall.

input format

The first line has a number NNN represents the number of platforms;

Next NNThree integers in each row of N lines are the height of the platformH i H_iHi, XX of the left endpointX signL i L_iLi, XX of the right endpointX signR i R_iRi

Among them, 1 ≤ N ≤ 10 3 1 \le N \le {10}^31N103 0 ≤ H , L , R ≤ 2 × 10 4 0 \le H,L,R \le 2 \times {10}^4 0H,L,R2×104

output format

Output total NNN lines, two numbers in each line, represent:

from section iiThe number of the platform that arrives after the left edge of the i platform falls and the platform number that arrives after the right edge falls.

The serial number of the first platform in the input data is 1 11 . If there is no platform under a certain edge of a platform, output0 00

Example #1

Sample Input #1

5
2 0 2
4 1 3
3 1 3
5 3 4
1 1 5

Sample output #1

0 5
1 5
1 5
5 5
0 0

hint

code show as below

#include<iostream>
using namespace std;
int n,a[1001],b[1001],c[1001];
int main(){
    
    
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	for(int i=1;i<=n;i++){
    
    
		
		int sum1=0,sum2=0;
		for(int j=1;j<=n;j++)
			if(a[j]<a[i]&&b[j]<b[i]&&c[j]>b[i])
				if(a[sum1]<a[j])
					sum1=j;//左边下落
		cout<<sum1<<" ";
		for(int j=1;j<=n;j++)
			if(a[j]<a[i]&&b[j]<c[i]&&c[j]>c[i])
				if(a[sum2]<a[j])
					sum2=j;//右边下落
		cout<<sum2<<endl;
	}
}

Guess you like

Origin blog.csdn.net/weixin_62529383/article/details/128297186