覆盖点集
#include <iostream>
#include <cstdio>
#include <climits>
using namespace std;
int main(){
int n;
cin >> n;
int max_x = INT_MIN,max_y = INT_MIN;
int min_y = INT_MAX,min_x = INT_MAX;
for(int i = 0;i < n;i ++){
int x,y;
cin >> x >> y;
if(x == 0 && y == 0) break;
max_x = max(x,max_x);
min_x = min(x,min_x);
max_y = max(y,max_y);
min_y = min(y,min_y);
}
printf("(%d,%d)\n(%d,%d)",min_x,min_y,max_x,max_y);
}
回文串
#include <iostream>
#include <string>
#include <cstdio>
#include <stack>
using namespace std;
//递归
bool is_huiwen1(string str,int start,int end){
//先设置递归出口,若前面的指针start大于等于后面的指针end时,退出递归
if(start >= end) return true;
if(str[start] == str[end]) return is_huiwen1(str,start+1,end-1);
return false;
}
//栈
bool is_huiwen2(string str){
stack<char> charstack;
for(char ch : str){
charstack.push(ch);
}
for(char ch : str){
if(ch != charstack.top()) return false;
charstack.pop();
}
}
int main(){
string s;
getline(cin,s);
if(is_huiwen1(s,0,s.size()-1)) cout << "是回文串" << endl;
else cout << "bushi" << endl;
if(is_huiwen2(s)) cout << "是" <<endl;
else cout <<" no " <<endl;
return 0;
}
逆序对数量
//暴力解法
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int N = 100005;
int main(){
int a[N] ={0};
int n;
int num = 0;
cin >> n;
for(int i = 0;i < n;i ++){
cin >> a[i];
}
for(int i = 0;i < n;i ++){
for(int j = i + 1;j < n;j ++){
if(a[i] > a[j]) num ++;
}
}
cout << num;
}
//归并排序