牛客小白月赛31 解题报告

D.坐标计数

链接:https://ac.nowcoder.com/acm/contest/10746/D

题目描述
定义一个坐标变换,坐标 ( x , y ) (x,y) (x,y) 变换后变为 ( x ⊕ y , ∣ x − y ∣ ) (x \oplus y, |x-y|) (xy,xy)

给定一片矩形区域,计算区域内有多少个整数点在经过有限次变换后变为 ( 0 , 0 ) (0,0) (0,0)
输入描述:
输入第一行一个数字 t , 1 ≤ t ≤ 50 t, 1 \le t \le 50 t,1t50 表示测试数据组数

接下来一行四个数字 1 ≤ x 1 , y 1 , x 2 , y 2 ≤ 1 0 5 1 \le x_1,y_1,x_2,y_2 \le 10^5 1x1,y1,x2,y2105代表给出的矩形区域

( x 1 , y 1 ) (x_1,y_1) (x1,y1)为矩形区域左下角, ( x 2 , y 2 ) (x_2,y_2) (x2,y2)表示矩形右上角,包含边界上的点。

输入保证有: x 1 < x 2 , y 1 < y 2 x_1<x_2,y_1<y_2 x1<x2,y1<y2
输出描述:
输出区域内满足变换要求的整数点个数

i n p u t input input

2
1 1 3 4
1 2 2 5

o u t p u t output output

12
8

题解:看完题目数据,直接算面积,一个右上角、一个左下角,
面积 = = ( y 2 − y 1 + 1 ) ∗ ( x 2 − x 1 + 1 ) == (y_2 - y_1 + 1) * (x_2 - x_1 + 1) ==(y2y1+1)(x2x1+1)

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
    
    
 int w = 1, s = 0;
 char ch = getchar();
 while (ch < '0' || ch>'9') {
    
     if (ch == '-') w = -1; ch = getchar(); }
 while (ch >= '0' && ch <= '9') {
    
     s = s * 10 + ch - '0';    ch = getchar(); }
 return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 110;
string s[N];
int a[26][N];
signed main()
{
    
    
	int t = read();
	while (t--) {
    
    
		int a = read(), b = read(), c = read(), d = read();
		printf("%lld\n", (c - a + 1) * (d - b + 1));
	}
	return 0;
}

G.简单题的逆袭

y / x y/x y/x 一直除就可以了。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
    
    
 int w = 1, s = 0;
 char ch = getchar();
 while (ch < '0' || ch>'9') {
    
     if (ch == '-') w = -1; ch = getchar(); }
 while (ch >= '0' && ch <= '9') {
    
     s = s * 10 + ch - '0';    ch = getchar(); }
 return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 110;
signed main()
{
    
    
	int t = read();
	while (t--) {
    
    
		int x = read(), y = read();
		if (x == 0 || y == 0 || x == 1) {
    
    
			printf("-1\n");
			continue;
		}
		int k = 0;
		while (true) {
    
    
			if (y / x >= 1) {
    
    
				y /= x;
				k++;
			} else {
    
    
				break;
			}
		}
		printf("%lld\n", k);
	}
	return 0;
}

H.对称之美

题目:给出n个字符串,从第1个字符串一直到第n个字符串每个串取一个字母来构成一个新字符串,新字符串的第i个字母只能从第i行的字符串中选出,这样就得到了一个新的长度为n的字符串,请问这个字符串是否有可能为回文字符串?

意思就是:有可能是回文串的意思是:如果第 i i i 行和第 n − i − 1 n - i - 1 ni1 行里面有相同的字母,就有可能是回文串。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define int ll
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
    
    
 int w = 1, s = 0;
 char ch = getchar();
 while (ch < '0' || ch>'9') {
    
     if (ch == '-') w = -1; ch = getchar(); }
 while (ch >= '0' && ch <= '9') {
    
     s = s * 10 + ch - '0';    ch = getchar(); }
 return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 110;
string s[N];
bool check(string s1, string s2) {
    
    
    int a[N] = {
    
    0};
    int b[N] = {
    
    0};
    
    for (int i = 0; i < s1.size(); i++) {
    
    
        a[s1[i] - 'a']++;
    }
    for (int i = 0; i < s2.size(); i++) {
    
    
        b[s2[i] - 'a']++;
    }
    
    for (int i = 0; i < 26; i++) {
    
    
        if (a[i] != 0 && b[i] != 0) return 1;
    }
    return 0;
}
signed main()
{
    
    
	int t = read();
	while (t--) {
    
    
		int n = read();
		for (int i = 0; i < n; i++) cin >> s[i];
		int f = 1;
		for (int i = 0; i < n / 2; i++) {
    
    
		    if (!check(s[i], s[n - i - 1])) {
    
    
		        printf("No\n");
		        f = 0;
		        break;
		    }
		}
		if (f) printf("Yes\n");
	}
	return 0;
}

I.非对称之美

最长非回文字符串包括三种情况:
① 这整个字符串不是回文字符串,那么此时最长非回文子串长度 == s.size()
② 如果这整个字符串是回文字符串,那么此时最长的非回文子串长度 == s.size()-1
③ 如果这整个字符串每个字符都一样,那么此时最长的非回文子串长度 == 0

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
int read()
{
    
    
 int w = 1, s = 0;
 char ch = getchar();
 while (ch < '0' || ch>'9') {
    
     if (ch == '-') w = -1; ch = getchar(); }
 while (ch >= '0' && ch <= '9') {
    
     s = s * 10 + ch - '0';    ch = getchar(); }
 return s * w;
}
//------------------------ 以上是我常用模板与刷题几乎无关 ------------------------//
const int N = 50010;
string s;
signed main()
{
    
    
	cin >> s;
	int l = 0, r = s.size() - 1;
	char a = s[0];
	int flag = 1;
	
	while (l <= r) {
    
    
		if (s[l] != a || s[r] != a) flag = 0;
		if (s[l] == s[r]) l++, r--;
		else break;
	}
	
	if (l > r && flag) printf("0\n");
	else if (l > r) printf("%lld\n", s.size() - 1);
	else printf("%lld\n", s.size());
	return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_46272108/article/details/112460701