1.连续组合数字
#include<iostream>
#include<vector>
using namespace std;
int main() {
int n;
cin >> n;
int count = 0;
int m = n;
vector<int> data(n);
vector<int> set(n,0);
for (int i = 0; i < n; i++) {
cin >> data[i];
}
int max = data[0];
int min = data[0];
for (int i = 0; i < n; i++) {
if (data[i] == 0) {
count++;
}
else if (max < data[i]) max = data[i];
else if (min > data[i]) min = data[i];
}
if (count >= n - 1) {
cout << "YES" << "+" << count << endl;
}
else if (max - min != n - 1) {
}
else {
for (int i = 0; i < n; i++) {
if (data[i] != 0) {
if (set[data[i] - min] == 1) {
cout << "NO" << "+" << count << endl;
break;
}
set[data[i] - min]++;
}
}
cout << "YES" << "+" << count << endl;
}
//system("pause");
return 0;
}
2.消消乐实现
题目:
#include<iostream>
#include<vector>
using namespace std;
int main() {
int R, C;
cin >> R >> C;
char ch;
vector<vector<char> > mat(R,vector<char>(C));
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
cin >> ch;
mat[i][j] = ch;
}
}
struct point {
int x;
int y;
}pt;
vector<point> sw(2);
for (int i = 0; i < 2; i++) {
cin >> sw[i].x >> sw[i].y;
}
char temp;
temp = mat[sw[0].x][sw[0].y];
mat[sw[0].x][sw[0].y] = mat[sw[1].x][sw[1].y];
mat[sw[1].x][sw[1].y] = temp;
vector<vector<int>> flag(R,vector<int>(C,0));
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if ((i + 1 < R) && (i + 2 < R)) {
if (mat[i][j] == mat[i + 1][j] && mat[i][j] == mat[i + 2][j]) {
flag[i][j] = 1;
flag[i+1][j] = 1;
flag[i+2][j] = 1;
}
}
if ((j + 1 < C) && (j+ 2 < C)) {
if (mat[i][j] == mat[i][j+1] && mat[i][j] == mat[i][j+2]) {
flag[i][j] = 1;
flag[i][j + 1] = 1;
flag[i][j + 2] = 1;
}
}
}
}
int count = 0;
for (int i = 0; i < R; i++) {
for (int j = 0; j < C; j++) {
if (flag[i][j] == 1) {
mat[i][j] = '0';
count += 1;
}
}
}
cout << count << endl;
system("pause");
return 0;
}