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

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. jquery---点击弹出层

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. PHP环境搭建所遇到的问题

    下午学校的机房搭建PHP组合包appserv开发环境的时候是没有任何问题的,但是到了自己的电脑上以后下砸的32位appserve一直无法正常由浏览器的localhos或者127.0.0.1 进入其ap ...

  3. startActivityForResult和setResult详解

    http://www.cnblogs.com/lijunamneg/archive/2013/02/05/2892616.html startActivityForResult与startActivi ...

  4. PHP 开发API接口 注册,登录,查询用户资料

    服务端 <?php require 'conn.php'; header('Content-Type:text/html;charset=utf-8'); $action = $_GET['ac ...

  5. sql yog注册码

    Name: AnyRegistration Code: 26f359fc-e3f6-4727-8af1-72a1a4a0819d

  6. 浅析CSS中的haslayout

    作为一名web开发人员,最大的希望不是自己的水平有多高,而是希望浏览器厂家能够统一标准,相信任何一个只要是接触过web程序开发的人员都有那样的感受,就是浏览器之间的兼容性问题总是让我们的工作平添诸多的 ...

  7. set,multiset容器类型

    set和multiset会根据特定的排序准则,自动将元素排序.两者不同处在于multiset允许元素重复而set不允许. 一.集和多集(set 和multiset 容器类) 在使用set和multis ...

  8. VirtualBox 中的UBUNTU和java环境的配置以及各种常用说明

    本来是要ubuntu下学习C++的,但是又懒的用高手们推荐的各种记事本级的操作,所以要用IDE.(我用IDE我自豪,人类的进化就是建立在工具的使用这个基础之上的.)我选用了oracle的netbean ...

  9. SGU 186.The Chain

    看懂题就是水题... code #include <iostream> #include <algorithm> using namespace std; int a[110] ...

  10. SGU 191.Exhibition(模拟)

    时间限制:0.25s 空间限制:4M 题意: 有两个公司A.B,他们要展览物品,但是A公司的展柜要放B公司的物品,B公司的展柜要放A公司物品.最开始只有一个空柜台,从指定的一个公司开始,轮流进行操作, ...