@Dmaxiya
2018-08-17T02:34:02.000000Z
字数 2958
阅读 1292
Codeforces
Contests 链接:Codeforces Round #414 (Div. 1 + Div. 2)
过题数:2
排名:911/6157
有 个保险箱,第 个保险箱内有 的钱,一个小偷在位置 ,有两个保安在位置 和 ,要求小偷不能走到保安的位置,且能够偷到的最多的钱。
计算出 ,就是结果。
#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>#include <functional>#include <iomanip>using namespace std;#define LL long longconst int maxn = 100000 + 100;int n;int a, b, c;int l, r;LL ans;int num[maxn];int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCALios::sync_with_stdio(false);while(scanf("%d%d%d", &a, &b, &c) != EOF) {scanf("%d", &n);ans = 0;for(int i = 0; i < n; ++i) {scanf("%d", &num[i]);if(num[i] > b && num[i] < c) {++ans;}}printf("%I64d\n", ans);}return 0;}
将一个高为 的等腰三角形切成面积相等的 段,输出 个数字,表示每次切的位置。
推出公式 ,输出结果。
#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>#include <functional>#include <iomanip>using namespace std;#define LL long longint n;double h;int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCALios::sync_with_stdio(false);while(scanf("%d%lf", &n, &h) != EOF) {for(int i = 1; i < n; ++i) {if(i != 1) {printf(" ");}printf("%.10f", h * sqrt((double)i / n));}printf("\n");}return 0;}
和 两人玩一个游戏, 先开始,两个人各有一个长度为 的字符串,最开始有一个长度为 的只包含 的字符串,两人轮流从自己的字符串中选一个字符替换其中的一个 , 想让这个结果字符的字典序最小, 想让这个字符的字典序最大,如果两人都采取最优策略,输出所有 字符都被替换之后的字符串。
将 的字符串按从小到大排序, 的字符串从大到小排序,如果 最小的字符小于 最大的字符,就将这个最小的字符替换最前面的问号,如果 最小的字符大于等于 最大的字符,就从后面往前面放,但是仍然要使字典序最小,所以他会先放自己最后要放下的,最大的字符。 就与 相反。
#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>#include <functional>#include <iomanip>using namespace std;#define LL long longconst int maxn = 3000000 + 100;int n;char str1[maxn], str2[maxn];char ans[maxn];bool cmp(const char &a, const char &b) {return a > b;}int main() {#ifdef LOCALfreopen("test.txt", "r", stdin);// freopen("out.txt", "w", stdout);#endif // LOCALios::sync_with_stdio(false);while(scanf("%s%s", str1, str2) != EOF) {int n = strlen(str1);sort(str1, str1 + n);sort(str2, str2 + n, cmp);int who = 1;int cnt = n;int l = 0;int r = n - 1;int l2 = 0, r2 = n / 2;int l1 = 0, r1 = n - r2;--r1;--r2;memset(ans, 0, sizeof(ans));while(cnt != 0) {if(who == 1) {if(str1[l1] < str2[l2]) {ans[l++] = str1[l1++];} else {ans[r--] = str1[r1--];}} else {if(str2[l2] > str1[l1]) {ans[l++] = str2[l2++];} else {ans[r--] = str2[r2--];}}who = 3 - who;--cnt;}printf("%s\n", ans);}return 0;}