题目描述
输入描述:
输入包括一个字符串s,字符串s的长度length(1 ≤ length ≤ 50),s中的每一个字符都为一个大写字母(A到Z)。
输出描述:
输出一个整数,表示小易可以有多少种方式。
示例1
输入
ABAB
输出
2
//
// Created by nexta on 2019/2/23.
// Whatever is worth doing is worth doing well.
//
#include<bits/stdc++.h>
using namespace std;
int main() {char str[50];cin >> str;int count = 1;sort(str, str + strlen(str));for (int i = 1; i < strlen(str); i++) {if (str[i] - str[i - 1] != 0)count++;}if (count > 2)cout << 0 << endl;else cout << count << endl;return 0;
}
题目描述
输入描述:
输入包括两行,第一行包含整数n(2 ≤ n ≤ 50),即数列的长度。
第二行n个元素x[i](0 ≤ x[i] ≤ 1000),即数列中的每个整数。
输出描述:
如果可以变成等差数列输出"Possible",否则输出"Impossible"。
示例1
输入
3
3 1 2
输出
Possible
//
// Created by nexta on 2019/2/23.
// Whatever is worth doing is worth doing well.
//#include <bits/stdc++.h>using namespace std;int main() {int n, i;cin >> n;int *x = new int[n];for (int i = 0; i < n; i++)cin >> x[i];sort(x, x + n);if (n == 2)cout << "Possible" << endl;for (i = 2; i < n; i++) {if (x[i] - x[i - 1] != x[i - 1] - x[i - 2]) {cout << "Impossible" << endl;break;}}if (i == n)cout << "Possible" << endl;return 0;
}
题目描述
输入描述:
输入包括字符串s,s的长度length(1 ≤ length ≤ 50),字符串中只包含’0’和’1’
输出描述:
输出一个整数,表示最长的满足要求的子串长度。
示例1
输入
111101111
输出
3
//
// Created by nexta on 2019/2/23.
// Whatever is worth doing is worth doing well.
//
#include <bits/stdc++.h>
using namespace std;
int main() {char str[60];cin >> str;int count = 1, max = -1;for (int i = 1; i < strlen(str); i++) {if (str[i] - str[i - 1] != 0) {count++;if (count > max)max = count;} else {count = 1;}}cout << (max > count ? max : count) << endl;return 0;
}
题目描述
输入描述:
输入包括两行,第一行包括一个整数n(2 ≤ n ≤ 2*10^5),即序列的长度。
第二行包括n个整数a_i(1 ≤ a_i ≤ 10^9),即序列a中的每个整数,以空格分割。
输出描述:
在一行中输出操作n次之后的b序列,以空格分割,行末无空格。
示例1
输入
4
1 2 3 4
输出
4 2 1 3
//借鉴别人的思想,这个是有规律的
//当数组个数为单数时,奇数递减,然后偶数递增
//当数组个数为双数时,偶数递减,然后奇数递增
// Created by nexta on 2019/2/23.
// Whatever is worth doing is worth doing well.
//
#include <bits/stdc++.h>
using namespace std;
int main() {int n;cin >> n;int *a = new int[n];for (int i = 0; i < n; i++)cin >> a[i];if (n % 2 == 0) {for (int i = n - 1; i > 0; i -= 2) {cout << a[i] << " ";}cout << a[0];for (int i = 2; i < n - 1; i += 2) {cout << " " << a[i];}} else {for (int i = n - 1; i > 0; i -= 2) {cout << a[i] << " ";}cout << a[0];for (int i = 1; i < n - 1; i += 2) {cout << " " << a[i];}}
}
题目描述
输入描述:
输入包括一行,四个整数x, f, d, p(1 ≤ x,f,d,p ≤ 2 * 10^9),以空格分割
输出描述:
输出一个整数, 表示小易最多能独立生活多少天。
示例1
输入
3 5 100 10
输出
11
//简单题
// Created by nexta on 2019/2/24.
// Whatever is worth doing is worth doing well.
//
#include <bits/stdc++.h>
using namespace std;
int main() {long x, f, d, p, max = -1;cin >> x >> f >> d >> p;if (d / x <= f)cout << d / x << endl;else cout << (d + f * p) / (p + x) << endl;return 0;
}
题目描述
输入描述:
输入包括三行,第一行一个整数n(1 ≤ n ≤ 50),表示棋子的个数
第二行为n个棋子的横坐标x[i](1 ≤ x[i] ≤ 10^9)
第三行为n个棋子的纵坐标y[i](1 ≤ y[i] ≤ 10^9)
输出描述:
输出n个整数,第i个表示棋盘上有一个格子至少有i个棋子所需要的操作数,以空格分割。行末无空格
如样例所示:
对于1个棋子: 不需要操作
对于2个棋子: 将前两个棋子放在(1, 1)中
对于3个棋子: 将前三个棋子放在(2, 1)中
对于4个棋子: 将所有棋子都放在(3, 1)中
示例1
输入
4
1 2 4 9
1 1 1 1
输出
0 1 3 10
//动态规划
// Created by nexta on 2019/2/24.
// Whatever is worth doing is worth doing well.
//
#include <bits/stdc++.h>
using namespace std;
int n, x[56], y[56], ans[56];
void helper();int main() {int temp = 0;cin >> n;for (int i = 0; i < n; i++)cin >> x[i];for (int i = 0; i < n; i++)cin >> y[i];for (int i = 0; i < n; i++)ans[i] = INT_MAX;helper();for (int i = 0; i < n - 1; i++)cout << ans[i] << " ";cout << ans[n - 1];
}void helper() {for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {int temp = 0;vector<int> dis(n, 0);for (int k = 0; k < n; k++)dis[k] = abs(x[i] - x[k]) + abs(y[j] - y[k]);sort(dis.begin(), d());for (int k = 0; k < n; k++) {temp += dis[k];ans[k] = min(temp, ans[k]);}}}
}
题目描述
输入描述:
输入包括两行,第一行一个整数n(1 ≤ n ≤ 50),表示学生的人数
第二行为n个整数h[i](1 ≤ h[i] ≤ 1000),表示每个学生的身高
输出描述:
输出一个整数,表示n个学生列队可以获得的最大的疯狂值。
如样例所示:
当队列排列顺序是: 25-10-40-5-25, 身高差绝对值的总和为15+30+35+20=100。
这是最大的疯狂值了。
示例1
输入
5
5 10 25 40 25
输出
100
//
// Created by nexta on 2019/2/24.
// Whatever is worth doing is worth doing well.
//
#include <bits/stdc++.h>
using namespace std;
int h[56], t[56];
int main() {int n, i = 0, j = n - 1, sum = 0, sum1 = 0;cin >> n;for (int i = 0; i < n; i++)cin >> h[i];sort(h, h + n);int min_ = h[0], max_ = h[n - 1], diff = max_ - min_;int min_Index = 1, max_Index = n - 2;while (min_Index < max_Index) {diff += max_ - h[min_Index];diff += h[max_Index] - min_;min_ = h[min_Index++];max_ = h[max_Index--];}diff += max(abs(max_ - h[min_Index]), abs(min_ - h[max_Index]));cout << diff << endl;
}
题目描述
输入描述:
输入包括两个整数n和k(1 ≤ n ≤ 10, 1 ≤ k ≤ 10^5)
输出描述:
输出一个整数,即满足要求的数列个数,因为答案可能很大,输出对1,000,000,007取模的结果。
示例1
输入
2 2
输出
3
//还没做出来
//好像是dp
本文发布于:2024-02-05 01:05:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170720555961656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |