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 ...
随机推荐
- Android Studio 使用正式签名进行调试
在Android Studio中,能够使用Gradle进行打包时自己主动签名. 事实上Android Studio默认会给调试应用加上Debug签名,但有时候调一些第三方SDK时.须要正式签名才干调起 ...
- Android 通过Application 传递数据
</pre><pre> package com.example.ApplicationTest; import android.app.Application; /** * C ...
- Swift中字符串转化为Class的方法
Swift中字符串转化为Class的方法 在开发中有时候会根据字符串进行对应类的转化,这样我们就可以动态根据服务器返回的字段,动态的加载类,比如优酷,微博等APP会在节假日等动态的TabBar.这样可 ...
- weblogic启动后 登陆控制台特别慢的问题
weblogic官方文档给出的问题原因: 江湖偏方: 修改jdk:修改$JAVA_HOME/jre/lib/security/java.security文件,替换securerandom.source ...
- iOS中城市定位功能的实现
引入框架:CoreLocation .h文件 引入CoreLocation/CoreLocation.h @interface WeatherViewController :UIViewControl ...
- YTU 2456: 评委打分
2456: 评委打分 时间限制: 1 Sec 内存限制: 128 MB 提交: 283 解决: 52 题目描述 一个歌唱比赛,比赛每次会从观众中随即抽取几名观众给分(观众至少有5个,分数为0~1 ...
- LR工作原理
LoadRunner的总体架构图,包括各个组件VUGen, Controller和Analysis之间的关系. LoadRunner由四大组件组成:VuGen.控制器.负载发生器和分析器. 1.VuG ...
- stl里面的空间适配器
一般而言,如果频繁地向system heap申请和释放空间很小的内存空间块(小于128B的),就会对系统内存资源产生很多内存碎片(fragment)的问题,而C++的::operator new() ...
- HTTPS站点搭建教程:Win7/Windows Server 2008R2
本文将由笔者为各位读者介绍在win7/windows server 2008R2环境下使用SSL加密协议建立WWW站点的全过程:https SSL证书安装的搭建以及本地测试环境. 要想成功架设SSL安 ...
- ubuntu安装wine+plsql
1.在ubuntu下装了win7的虚拟机,在使用plsql进行开发的时候发现很慢很卡,经常半天反应不过来.机器是不差的,1w5的thinkstation,实在受不了这种 速度,想着在ubuntu下搞一 ...