@Dmaxiya
2018-08-17T02:18:08.000000Z
字数 3219
阅读 1196
Codeforces
Contests 链接:Educational Codeforces Round 38
过题数:2
排名:1341/9908
给定一个字符串,在字符串中如果出现连续的两个元音字母(‘a', 'e', 'i', 'o', 'u', 'y'),就用第一个元音字母代替这两个元音字母。
输入为一个只包含小写字母的字符串 。
输出最终字符串。
| 输入 | 输出 | 提示 |
|---|---|---|
| 5 weird |
werd | |
| 4 word |
word | 这个字符串中没有连续的两个元音字母。 |
| 5 aaeaa |
a | 。 |
按照题意模拟。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>using namespace std;#define LL long longconst int maxn = 200;int n;char str[maxn], ch[10] = "aeiouy";set<char> st;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyafor(int i = 0; i < 6; ++i) {st.insert(ch[i]);}while(scanf("%d%s", &n, str) != EOF) {bool flag = false;for(int i = 0; i < n; ++i) {if(st.find(str[i]) != st.end()) {if(!flag) {printf("%c", str[i]);}flag = true;} else {printf("%c", str[i]);flag = false;}}printf("\n");}return 0;}
一个人站在 的地方,另一个人站在 的地方,在这之间有 个奖品,每个奖品的位置分别为 ,且没有任何两个奖品在同一个位置,每个人的移动速度都是 ,如果某个人的位置正好和某个奖品的位置相同,他可以立即捡起这个奖品,问两人合作将所有奖品捡起的最短时间。
第一行为一个整数 ,第二行为 个整数 ,输入按升序给出。
输出两人合作捡起所有奖品需要的最少时间。
| 输入 | 输出 | 提示 |
|---|---|---|
| 3 2 3 9 |
8 | 所有奖品都由在 处的人捡起,另一个人不需要移动。 |
| 2 2 999995 |
5 | 的人捡起第一个奖品, 的人捡起第二个奖品。 |
枚举所有相邻位置的分割点,两个人捡起所有物品的时间就是 ,取最小值就是答案。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>using namespace std;#define LL long longconst int maxn = 100000 + 100;int n, ans;int num[maxn];int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyawhile(scanf("%d", &n) != EOF) {ans = INT_MAX;num[0] = 1;num[n + 1] = 1000000;for(int i = 1; i <= n; ++i) {scanf("%d", &num[i]);}for(int i = 0; i <= n; ++i) {ans = min(ans, max(num[i] - 1, 1000000 - num[i + 1]));}printf("%d\n", ans);}return 0;}
给定一个整数 ,要求构造一个 的 矩阵,使得这个矩阵中,任意一个 的子矩阵中都至少含有一个 ,且矩阵中 的数量的最大值等于 。
第一行为一个整数 ,接下去有 个整数 。
对于每个 ,都输出一行两个整数 ,要求 满足题给条件且 ,如果不存在满足条件的答案,输出 。
| 输入 | 输出 |
|---|---|
| 3 21 0 1 |
5 2 1 1 -1 |
可以发现,要使得 矩阵中的 的数量最多,就要让 的矩阵中每个 的位置都放上一个 ,因此矩阵中最多的 的数量就等于 ,可以对于 内所有的整数,二分 的值使 满足公式的值等于 。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>#include <algorithm>using namespace std;#define LL long longint T;LL x, n, m;LL judge(LL mid) {return n * n - (n / mid) * (n / mid);}int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyawhile(scanf("%d", &T) != EOF) {while(T--) {m = -1;scanf("%I64d", &x);LL sq = sqrt(x) + 1;for(n = sq; n * n <= 4000000000LL; ++n) {LL low = 1;LL high = n;LL mid;while(high - low > 1) {mid = (high + low) / 2;if(judge(mid) >= x) {high = mid;} else {low = mid;}}if(judge(high) == x) {m = high;break;}}if(m == -1) {printf("-1\n");} else {printf("%I64d %I64d\n", n, m);}}}return 0;}