main
黄海 1 year ago
commit 88ad5ae3d0

@ -1,3 +0,0 @@
https://blog.csdn.net/qq_36230375/article/details/134725732
https://tiku.scratchor.com/paper/view/gjfvsjrgtpm30v3f

@ -4,8 +4,8 @@ const int N = 120;
int a[N], b[N];
const int INF = 0x3f3f3f3f;
/*
3
2 6 7
5
5 7 5 5 3
*/
int n, sum, avg;
int main() {
@ -13,7 +13,7 @@ int main() {
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
a[i + n] = a[i]; // 破环成链, 0 1 2-->a[3]=a[0],a[4]=a[1],a[5]=a[2]
a[i + n] = a[i]; // 破环成链
}
avg = sum / n; // 平均数
int mi = INF; // 最少次数,给初始值最大

@ -0,0 +1,33 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 31;
char a[N][N];
int n, m, cnt;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> a[i][j];
for (int e = 2; e <= min(m, n); e++) { // 枚举每个小正方形的边长
for (int i = 0; i <= n - e; i++) { // 起点i
for (int j = 0; j <= m - e; j++) { // 起点j
bool f = true;
for (int x = 0; x < e; x++) { // 遍历正方形中所有的其它位置,判断是不是与左上角的一致
for (int y = 0; y < e; y++) {
if (a[i][j] != a[i + x][j + y]) {
f = false;
break;
}
}
if (!f) break;
}
if (f) cnt++;
}
}
}
cout << cnt << endl;
return 0;
}

@ -0,0 +1,69 @@
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 110;
double a[N];
int n;
int f1[N], f2[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
// 以每棵树为保留的并且是最高的那棵树分别求出最长上升序列长度x 和 最长下降序列长度y x+y-1就是最终保留的整体序列长度
// 去掉的数量就是 n-(x+y-1)的值。然后求min()
// 需要注意的是默认值设置为-1比如 5 4 3 2 1 ,我们取哪棵为最高点都行不通,不存在左侧上侧到峰值的情况,右侧即使符合也不行的。
// 求最长上升
for (int i = 1; i <= n; i++) {
f1[i] = 1;
for (int j = 1; j < i; j++)
if (a[i] > a[j]) f1[i] = max(f1[i], f1[j] + 1);
}
// 求最长下降
for (int i = n; i >= 1; i--) {
f2[i] = 1;
for (int j = n; j > i; j--)
if (a[i] > a[j]) f2[i] = max(f2[i], f2[j] + 1);
}
// // 输出最长上升
// for (int i = 1; i <= n; i++) cout << f1[i] << " ";
// cout << endl;
// // 输出最长下降
// for (int i = 1; i <= n; i++) cout << f2[i] << " ";
// cout << endl;
bool flag = true;
for (int i = 1; i <= n; i++)
if (f1[i] != 1) {
flag = false;
break;
}
if (flag) {
cout << -1 << endl;
exit(0);
}
flag = true;
for (int i = 1; i <= n; i++)
if (f2[i] != 1) {
flag = false;
break;
}
if (flag) {
cout << -1 << endl;
exit(0);
}
int mi = -1;
for (int i = 1; i <= n; i++) {
int tmp = f1[i] + f2[i];
mi = max(mi, tmp);
}
cout << n - mi + 1 << endl;
return 0;
}

@ -0,0 +1,2 @@
10
1.0 2.3 1.2 1.7 1.1 2.0 1.8 1.8 1.2 1.9

@ -21,7 +21,7 @@ int main() {
for (int j = 1; j <= m; j++)
s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + a[i][j];
int res = -1;
int res = 0;
for (int x1 = 1; x1 <= n; x1++)
for (int y1 = 1; y1 <= m; y1++)
for (int x2 = x1; x2 <= n; x2++)

@ -0,0 +1,11 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
n %= 100;
n = n - n % 10;
n /= 10;
cout << n;
return 0;
}

@ -0,0 +1 @@
https://ccgao.blog.csdn.net/article/details/134725732

@ -0,0 +1,6 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
cout << '9' * 3 << endl;
return 0;
}

@ -0,0 +1,7 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int b = 0x212;
cout << b;
return 0;
}

@ -0,0 +1,8 @@
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n - n / 200 * 25;
return 0;
}

@ -0,0 +1,15 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, mx, pre, nxt;
int main() {
cin >> n >> pre;
for (int i = 2; i <= n; i++) {
cin >> nxt;
if (abs(nxt - pre) > mx) mx = abs(nxt - pre);
pre = nxt;
}
cout << mx;
return 0;
}

@ -0,0 +1,37 @@
#include <bits/stdc++.h>
using namespace std;
int check(int x) {
// 转9进制
string res;
while (x) {
int a = x % 9;
res += to_string(a);
x /= 9;
}
// 每个数位都是奇数
for (int i = 0; i < res.size(); i++)
if ((res[i] - '0') % 2 == 0) return 0;
// 判断转完的9进制是不是回文数
// 方法1
// string str = res;
// reverse(str.begin(), str.end());
// return str == res;
// 方法2
for (int i = 0; i < (res.size() + 1) / 2; i++)
if (res[i] != res[res.size() - 1 - i]) return 0;
return 1;
}
int main() {
int n, m;
cin >> n >> m;
int res = 0;
for (int i = n; i <= m; i++) res += check(i);
cout << res << endl;
return 0;
}

@ -0,0 +1,42 @@
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n, m, ans, st[N];
int a[N][N];
bool check(int u) {
for (int i = 1; i < u; i++)
if (st[i] && a[u][i]) return false;
return true;
}
void dfs(int u, int sum) { // 第u号钻石之前一共选了sum个钻石
if (u == n + 1) { // 如果所有钻石都找完了
ans = max(ans, sum); // 取最大值
return;
}
// 如果剩下的钻石都选也没有已有的最好情况多,返回,剪枝
// if (ans > sum + (n - u + 1)) return;
if (check(u)) { // 当前钻石与已选钻石没有冲突
st[u] = 1; // 选之
dfs(u + 1, sum + 1); // 继续下一个钻石
st[u] = 0; // 不选
}
dfs(u + 1, sum); // 继续下一个钻石
}
int main() {
cin >> n >> m;
while (m--) {
int x, y;
cin >> x >> y;
a[x][y] = a[y][x] = 1; // x<->y互相冲突
}
dfs(1, 0); // 从第一个钻石开始选目前已选0个
cout << ans << endl;
return 0;
}

@ -0,0 +1,3 @@
https://ccgao.blog.csdn.net/article/details/134725794
https://tiku.scratchor.com/paper/view/z8k4y0xsf0ue8xlh
Loading…
Cancel
Save