Codeforces Round #324 (Div. 2)
CF的rating设置改了。。人太多了,决定开小号打,果然是明智的选择!
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f; int main(void) {
int n, t; scanf ("%d%d", &n, &t);
if (t == 10) {
if (n == 1) {
puts ("-1");
}
else {
for (int i=1; i<n; ++i) printf ("1");
puts ("0");
}
}
else {
for (int i=1; i<=n; ++i) {
printf ("%d", t);
}
puts ("");
} return 0;
}
组合数学 B - Kolya and Tanya
题意:有一个3n的圈,每个数字可以在[1, 3]中选择,问ai + ai+n + ai+2n != 6的方案数
分析:3n个点,每个点都有3种选择,而出现ai + ai+n + ai+2n != 6的组合有7种,i的位置有n种,所以答案就是:(3 ^ (3 * n) - 7 ^ (n) + MOD) % MOD
还好猜猜样例一次过掉,否则一旦卡住就不会出后面的两题了
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7; int pow_mod(int x, int n, int p) {
int ret = 1;
while (n) {
if (n & 1) {
ret = 1ll * ret * x % p;
}
x = 1ll * x * x % p;
n >>= 1;
}
return ret;
} int main(void) {
int n; scanf ("%d", &n);
if (n == 1) {
printf ("20\n");
}
else
printf ("%d\n", (pow_mod (3, n * 3, MOD) - pow_mod (7, n, MOD) + MOD) % MOD); return 0;
}
题意:问是否有一个字符串和字符串a的不同个数与和字符串b的不同个数相同
分析:将a和b的字符比较,得到它们相同的个数以及不同的个数,不同的那块可以选择与它们都不同的或者与其中一个相同的,可以自由分配,相同的那块只能相同或都不同
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
char s[N], t[N]; char f(char a, char b) {
if (a > b) swap (a, b);
char r = a + 1;
if (r == b) r++;
if (r > 'z') r = 'a';
return r;
} int main(void) {
int n, m; scanf ("%d%d", &n, &m);
scanf ("%s%s", s, t);
int dif = 0;
for (int i=0; i<n; ++i) {
if (s[i] != t[i]) dif++;
}
int low = dif / 2;
if (dif & 1) low++;
if (low > m) puts ("-1");
else {
if (m >= dif) {
int sam = m - dif;
for (int i=0; i<n; ++i) {
if (s[i] == t[i]) {
printf ("%c", sam > 0 ? f (s[i], t[i]) : s[i]);
sam--;
}
else {
printf ("%c", f (s[i], t[i]));
}
}
puts ("");
}
else {
int sam = (dif - m) * 2;
for (int i=0; i<n; ++i) {
if (s[i] == t[i]) {
printf ("%c", s[i]);
}
else {
if (sam <= 0) printf ("%c", f (s[i], t[i]));
else
printf ("%c", sam & 1 ? s[i] : t[i]);
sam--;
}
}
puts ("");
}
} return 0;
}
题意:略
分析:一个或两个很好想,三个没什么好办法,用哥德巴赫猜想,只能暴力来~
#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f; /*
素性测试,在小范围(1e5)内判素数个数以及单个数判素数有奇效,不适用于大范围判素数
*/
bool is_prime(int x) {
if (x == 2 || x == 3) return true;
if (x % 6 != 1 && x % 6 != 5) return false;
for (int i=5; i*i<=x; i+=6) {
if (x % i == 0 || x % (i + 2) == 0) return false;
}
return true;
} int main(void) {
int n; scanf ("%d", &n);
if (is_prime (n)) {
printf ("1\n%d\n", n);
}
else {
int x = n - 2;
if (is_prime (x)) {
printf ("2\n%d %d\n", 2, x);
}
else {
int k = n - 1;
while (true) {
if (is_prime (k)) break;
k--;
}
n -= k; //n >= 9
int a = n / 2;
while (a < n) {
if (is_prime (a) && is_prime (n - a)) {
printf ("3\n%d %d %d\n", k, a, n - a); return 0;
}
a++;
}
}
} return 0;
}
Codeforces Round #324 (Div. 2)的更多相关文章
- Codeforces Round #324 (Div. 2)解题报告
---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...
- Codeforces Round #324 (Div. 2) C (二分)
题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...
- Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心
E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想
D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...
- Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心
C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂
B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...
- Codeforces Round #324 (Div. 2) A. Olesya and Rodion 水题
A. Olesya and Rodion Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/p ...
- Codeforces Round #324 (Div. 2) (哥德巴赫猜想)
题目:http://codeforces.com/problemset/problem/584/D 思路: 关于偶数的哥德巴赫猜想:任一大于2的偶数都可写成两个素数之和. 关于奇数的哥德巴赫猜想:任一 ...
- Codeforces Round #324 (Div. 2) Dima and Lisa 哥德巴赫猜想
原题链接:http://codeforces.com/contest/584/problem/D 题意: 给你一个奇数,让你寻找三个以内素数,使得和为这个奇数. 题解: 这题嘛...瞎比搞搞就好,首先 ...
- Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理
原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...
随机推荐
- Drupal 7模板(主题钩子)的建议
这一块的内容很多其它的讲的是样例.所以这里请直接稳步官方站点查看吧.链接 https://drupal.org/node/1089656
- ios如何获取手机的网络状态和运营商名称
本文转载至 http://blog.csdn.net/justinjing0612/article/details/38313747 以前获取手机的网络状态和运营商名称都是似有API, 现在我们可以大 ...
- CentOS笔记-其他杂记
1.忘记密码时,可以用single模式来修改密码,为了安全,可以禁用single模式,参考网址如下 Centos服务器禁止单用户模式(single)来增强系统安全 2.远程登录:ssh root@xx ...
- Spark高级
Spark源码分析: https://yq.aliyun.com/articles/28400?utm_campaign=wenzhang&utm_medium=article&utm ...
- Safair css hack
一下方式不会影响chrome浏览器样式 _::-webkit-full-page-media, _:future, :root .class{ /*此处放css样式*/ }
- SCX-4521F一体机MAC驱动
如果您想下载SCX-4521F一体机MAC驱动,请从下面的链接中下载相应驱动:MAC打印驱动:http://org.downloadcenter.samsung.com/downloadfile/Co ...
- 51Nod 1282 时钟 —— 最小表示法 + 字符串哈希
题目链接:https://vjudge.net/problem/51Nod-1282 1282 时钟 题目来源: Codility 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难 ...
- NOT IN clause and NULL values
https://stackoverflow.com/questions/129077/not-in-clause-and-null-values This issue came up when I g ...
- mack pro常用快捷键
fn + left / right / up / down 相当于 home/end/page up /page down delete 删除光标前一个字符 fn + delete 删除当前光标后一个 ...
- vue 随笔3
在整个vue项目中index.js只能有一个 ,创建vue组件实例的代码只能写在main.js中或者index.js中,别的文件中都是使用export default 常量 或者是方法