---恢复内容开始---

Codeforces Round #324 (Div. 2)

Problem A

题目大意:给二个数n、t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“-1”。

数据范围: 1 ≤ n ≤ 100, 2 ≤ t ≤ 10

so easy!首先考虑无解的时候,只有当n==1,t==10是无解,其他情况都存在解。很容易想到最简单的n位数能被t整除的数是,t个n组成的数。

参考代码:

 By Royecode, contest: Codeforces Round #324 (Div. 2), problem: (A) Olesya and Rodion, Accepted, #
1 #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5+; int main()
{
int n, t;
cin >> n >> t;
if(t == )
{
if(n == )//无解
puts("-1");
else if(n == )
puts("");
else
{
cout << ;
for(int i = ; i < n - ; ++i)
cout << ;
puts("");
}

Problem B

题目大意:给一个n,表示有3n个数,每个数的取值范围是[1,3],统计有多少个i,使a[i] + a[i+1] + a[i+2] != 6,所得答案模1e9+7。

数据范围:1 ≤ n ≤ 10^5,0<=i<3*n

数学问题,通过推公式可得答案:pow(3, 3*n) - pow(7, n)

参考代码:

 By Royecode, contest: Codeforces Round # (Div. ), problem: (B) Kolya and Tanya , Accepted, #
2 #include <bits/stdc++.h> #define ll long long
#define pb push_back
#define mp make_pair
#define debug(x) cout << #x << " " << x << endl; using namespace std; const int MAXN = 1e5+;
const int INF = 2e9+;
const double EPS = 1e-;
const int MOD = 1e9+; ll quick(ll n, int i)
{
if(i != )
{
ll t = quick(n, i / ) % MOD;
if(i % == ) return t * t * n % MOD;
return t * t % MOD;
}
return n;
}
int main()
{
ll n;
cin >> n;
cout << (quick(, * n) - quick(, n) + MOD ) % MOD<< endl; //注意加上MOD,再取模
return ;
}

Problems C

题目大意:有2个长度为n的字符串s1,s2,求一个长度为n的字符串s3,让s1跟s3有t个字符不一样,s2跟s3也有t个字符不一样。答案不唯一。

数据范围:1 ≤ n ≤ 10^5, 0 ≤ t ≤ n

先统计s1跟s2相同的字符数cnt,可以通过反面来做,则需要构造表达式:n - cnt == t,n、t都是不变的,所以只能改变cnt的值。

构造s3[i] = s1[i] == s[2]? s1[i]: ' '; (0<=i<n)

分两种情况:

1、n - cnt > t,说明相同的字符数太少,导致构造出的字符串s3分别与s1、s2不同的字符太多,要使cnt++,则需在s1[i] != s2[i]处,先让s3[i] = s1[i],再找到一个s1[j] != s2[j],让s3[i] = s2[i],直到n - cnt == t,或则无解

2、n - cnt < t,说明相同的字符数太多,导致构造出的字符串s3分别与s1、s2不同的字符太少,只需将s1[i]==s2[i]==s3[i]的s3[i]变化,直到n - cnt == t,或则无解

参考代码:

 #include <bits/stdc++.h>

 #define ll long long
#define pb push_back
#define mp make_pair
#define debug(x) cout << #x << " " << x << endl; using namespace std; const int MAXN = 1e5+;
const int INF = 2e9+;
const double EPS = 1e-;
char get(char ch1, char ch2)
{ for(char j = 'a'; j <= 'z'; ++j)
{
if(ch1 != j && ch2 != j)
{
return j;
}
}
}
int main()
{
int n, t;
cin >> n >> t;
string st1, st2, st3(n, ' ');
cin >> st1 >> st2;
int cnt = ;
for(int i = ; i < n; ++i)
{
if(st1[i] == st2[i]) st3[i] = st1[i], cnt++;
else st3[i] = get(st1[i], st2[i]);
}
if(n - cnt > t)
{
bool f = false;
for(int i = ; i < n && n - cnt != t; ++i)
{
if(st1[i] != st2[i])
{
if(f) st3[i] = st1[i];
else st3[i] = st2[i];
f = !f;
if(!f)cnt++; //debug(cnt);debug(st3);
}
}
}
else
{
for(int i = ; i < n && n - cnt != t; ++i)
{
if(st1[i] == st2[i])
{
st3[i] = get(st1[i], st2[i]);
cnt--;
}
}
}
//debug(cnt);
if(n - cnt == t) cout << st3 << endl;
else cout << - << endl;
return ;
}

Problem D

题目大意:给以个奇数n,需找到k个素数,让这k个素数的和等于n,1个素数,2个素数,3个素数之和都行,题目保证有解。

数据范围:3 ≤ n < 10^9,1<=k<=3

通过简单的算,可以看出答案是不唯一的。

如:

n=27

答案一:

3

2 2 23

答案二:

3

5 11 11

将k分3种情况:

1、k等于1,若n是素数则答案是

1

n

2、k等于2,由于给的n是奇数,素数之中除了2之外都是奇数,所以要使k等于的时候有解,必然有一个数是2,另一个数n-2

3、k等于3,由于题目保证有解,并且n是奇数,所以答案之中肯定没有2。任意指定一个素数p(2<p<=n-3)为其中的答案,然后再去找另一个素数i,和另一个素数n-p-i。

只要p、i、n-p-i都是素数,则找到答案。

参考代码:

 #include <iostream>
#define ll long long
using namespace std; bool is_prime(int n)
{
for(ll i = ; i * i <= n; ++i)
if(n % i == ) return false;
return n > ? true: false;
}
int main(int argc, char **argv)
{
int n;
cin >> n;
if(is_prime(n))
cout << << endl << n << endl;
else if(is_prime(n - ))
cout << << endl << << " " << n - << endl;
else
{
int p;
for(p = n - ; ; --p)
if(is_prime(p)) break;
n -= p;
for(int i = ; ;++i)
{
if(is_prime(i) && is_prime(n - i))
{
cout << << endl << p << " " << i << " " << n - i << endl;
break;
}
}
}
return ;
}

---恢复内容结束---

Codeforces Round #324 (Div. 2)解题报告的更多相关文章

  1. Codeforces Round #382 (Div. 2) 解题报告

    CF一如既往在深夜举行,我也一如既往在周三上午的C++课上进行了virtual participation.这次div2的题目除了E题都水的一塌糊涂,参赛时的E题最后也没有几个参赛者AC,排名又成为了 ...

  2. Codeforces Round #380 (Div. 2) 解题报告

    第一次全程参加的CF比赛(虽然过了D题之后就开始干别的去了),人生第一次codeforces上分--(或许之前的比赛如果都参加全程也不会那么惨吧),终于回到了specialist的行列,感动~.虽然最 ...

  3. Codeforces Round #216 (Div. 2)解题报告

    又范低级错误! 只做了两题!一道还被HACK了,囧! A:看了很久!应该是到语文题: 代码:#include<iostream> #include<];    ,m2=;    ;i ...

  4. Codeforces Round #281 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...

  5. Codeforces Round #277 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/486 A题.Calculating Function 奇偶性判断,简单推导公式. #include<cstdio> ...

  6. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

  7. Codeforces Round #350 (Div. 2)解题报告

    codeforces 670A. Holidays 题目链接: http://codeforces.com/contest/670/problem/A 题意: A. Holidays On the p ...

  8. Codeforces Round #479 (Div. 3)解题报告

    题目链接: http://codeforces.com/contest/977 A. Wrong Subtraction 题意 给定一个数x,求n次操作输出.操作规则:10的倍数则除10,否则减1 直 ...

  9. Codeforces Round #515 (Div. 3) 解题报告(A~E)

    题目链接:http://codeforces.com/contest/1066 1066 A. Vova and Train 题意:Vova想坐火车从1点到L点,在路上v的整数倍的点上分布着灯笼,而在 ...

随机推荐

  1. node 搭建开发框架express

    参考地址: http://www.itnose.net/detail/6095003.html 开发环境 E:\project> node -v v0.10.30 E:\project> ...

  2. angularjs 遇到Error: [$injector:unpr] Unknown provider: tdpicnews-serviceProvider <- tdpicnews-service <- tdpic-controller 错误

    define(['modules/tdpic-module', 'services/news-service', 'utilities/cryto'], function (app) { 'use s ...

  3. oracle模糊查询效率可这样提高

    1.使用两边加'%'号的查询,oracle是不通过索引的,所以查询效率很低. 例如:select count(*) from lui_user_base t where t.user_name lik ...

  4. 你好,C++(3)2.1 一个C++程序的自白

    第2部分 与C++第一次亲密接触 在浏览了C++“三分天下”的世界版图之后,便对C++有了基本的了解,算是一只脚跨入了C++世界的大门.那么,怎样将我们的另外一只脚也跨入C++世界的大门呢?是该即刻开 ...

  5. excel poi 文件导出,支持多sheet、多列自动合并。

    参考博客: http://www.oschina.net/code/snippet_565430_15074 增加了多sheet,多列的自动合并. 修改了部分过时方法和导出逻辑. 优化了标题,导出信息 ...

  6. Centos下安装配置LAMP(Linux+Apache+MySQL+PHP)

    Centos下安装配置LAMP(Linux+Apache+MySQL+PHP)   关于LAMP的各种知识,还请大家自行百度谷歌,在这里就不详细的介绍了,今天主要是介绍一下在Centos下安装,搭建一 ...

  7. jQuery 自动完成文本框

    jQuery自动完成插件开源软件 http://www.oschina.net/project/tag/329/jquery-autocomplete jQuery TextExt http://te ...

  8. Unity问答——NGUI怎么使用按键模拟鼠标点击?

    这篇博客源自我在泰课在线的回答.链接:http://www.taikr.com/group/1/thread/248 问:NGUI怎么模拟用代码模拟控制点击 答: 1. 这个问题问得好.因为在使用按键 ...

  9. oracle 的一点累积

    1.  oracle用户相关 sqlplus sys/oracle as sysdba    -- sys登录 create user xxx identified by password;   -- ...

  10. X-Plosives

    uvaLive 3644:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pa ...