@Dmaxiya
2018-08-17T02:18:40.000000Z
字数 3928
阅读 1119
Codeforces
Contests 链接:Codeforces Round #461 (Div. 2)
过题数:4
排名:230/11398
有一个可以克隆玩具的机器,如果放入一个原始玩具,则会获得一个额外的原始玩具和一个克隆玩具,如果放入一个克隆玩具,则会获得两个额外的克隆玩具, 最初有 个原始玩具,他想要获得 个克隆玩具和 个原始玩具,问他能否通过这个机器得到。
输入包含两个整数 和 。
如果可以,则输出 ,否则输出 ,大小写任意。
| 输入 | 输出 | 提示 |
|---|---|---|
| 6 3 | Yes | 可以通过放入两次原始玩具和两次克隆玩具获得 个克隆玩具和 个原始玩具。 |
| 4 2 | No | |
| 1000 1001 | Yes |
原始玩具的个数至少为 ,且如果原始玩具的个数为 ,则他不可能有克隆玩具,如果他有克隆玩具,则克隆玩具的个数至少为 ,除了通过原始玩具得到的 个克隆玩具,剩下的所有克隆玩具个数应该为偶数。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longint x, y;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d%d", &x, &y) != EOF) {if(x < y - 1 || y < 1) {printf("No\n");continue;}if(y == 1 && x != 0) {printf("No\n");continue;}x -= y - 1;if(x % 2 == 0) {printf("Yes\n");} else {printf("No\n");}}return 0;}
给定数字 ,问有多少个整数对 满足下面的条件:
- ;
- ;
- 以 为三边可以构成一个非退化的三角形。
输入包含一个整数 。
输出满足条件的整数对的个数。
| 输入 | 输出 | 提示 |
|---|---|---|
| 6 | 1 | 只有 一组整数对满足条件。 |
| 10 | 2 |
暴力从 到 枚举 和 的值,用异或得到 的值进行判断。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longint n;LL ans;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%d", &n) != EOF) {ans = 0;for(int i = 1; i <= n; ++i) {for(int j = i; j <= n; ++j) {int k = i ^ j;if(k >= j && k <= n && i + j > k) {++ans;}}}printf("%I64d\n", ans);}return 0;}
给定整数 和 ,问对于所有的 ,是否 的值都不相同。
输入包含两个整数 。
如果 和 满足条件,则输出 ,否则输出 ,大小写任意。
| 输入 | 输出 | 提示 |
|---|---|---|
| 4 4 | No | 对 和 取模的值相等。 |
| 5 3 | Yes |
从 开始, 的值一定为 ,对 取模的值要不等于 ,则只能 ,以此类推,对 取模的值必须等于 ,因此可以建立一个同余方程,可以发现要满足对 内所有的数取模都等于 , 的解是呈阶乘增长的,因此只要暴力从 到 进行判断,一旦不满足条件就跳出循环,实际需要判断的次数是很少的,远远达不到 。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longLL n, k;int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(scanf("%I64d%I64d", &n, &k) != EOF) {bool flag = true;for(LL i = 1; i <= k; ++i) {if(n % i != i - 1) {flag = false;break;}}if(flag) {printf("Yes\n");} else {printf("No\n");}}return 0;}
定义一个只包含 和 的字符串的权值为字符串中 子序列的个数,现在给定 个字符串 ,问将这些字符串按任意顺序连接起来能够得到的最大的权值。
第一行为一个整数 ,接下去 行每行一个字符串 ,每一个字符串都只包含字符 和 。
输出将所有字符串按任意顺序连接起来之后得到的最大的权值。
| 输入 | 输出 | 提示 |
|---|---|---|
| 4 ssh hs s hhhs |
18 | 最优的连接方式为 。 |
| 2 h s |
1 |
首先统计每个字符串中 和 的数量 和 ,然后贪心将所有字符串进行排序,排序的规则为:
- 如果字符串 排在 之前,可以得到 个 子序列,反之亦然,记为 ;
- 如果 ,则将 值大的放在前面,否则将 和 中值大的放在前面。
最后扫一遍排序后的字符串统计 子序列的个数。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <climits>#include <cfloat>#include <cstring>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <algorithm>using namespace std;#define LL long longconst int maxn = 100000 + 100;struct Node {int Index;LL cnts, cnth;};bool operator<(const Node &a, const Node &b) {LL aa = a.cnts * b.cnth;LL bb = b.cnts * a.cnth;if(aa == bb) {return a.cnts > b.cnts;}return aa > bb;}int n;string str[maxn];Node node[maxn];int main() {#ifdef Dmaxiyafreopen("test.txt", "r", stdin);#endif // Dmaxiyaios::sync_with_stdio(false);while(cin >> n) {for(int i = 0; i < n; ++i) {cin >> str[i];node[i].Index = i;node[i].cnts = node[i].cnth = 0;for(int j = 0; str[i][j]; ++j) {if(str[i][j] == 's') {++node[i].cnts;} else {++node[i].cnth;}}}sort(node, node + n);LL cnt = 0, ans = 0;for(int i = 0; i < n; ++i) {int ii = node[i].Index;for(int j = 0; str[ii][j]; ++j) {if(str[ii][j] == 's') {++cnt;} else {ans += cnt;}}}printf("%I64d\n", ans);}return 0;}