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

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. Adb connect监听指定的主机和端口/Adb监听Visual Studio Emulator for Android模拟器

    语法: adb connect <host>[:<port>] 使用实例: adb connect //如果连接成功则返回 connected to 说明 在使用Visual ...

  2. Content Providers

    Content providers manage access to a structured set of data. They encapsulate the data, and provide ...

  3. [转载]CentOS6.4+Mono3.0.7+Jexus5.2.5

    本文章来自互联网,但是本人已经在VM虚拟机里面测试成功,所以分享给大家 1.更新 yum -y update 2.安装Mono源码安装需要的库 yum -y install gcc gcc-c++ a ...

  4. ORACLE 中ROWNUM用法总结!(转)

    对于 Oracle 的 rownum 问题,很多资料都说不支持>,>=,=,between...and,只能用以上符号(<.<=.!=),并非说用>,>=,=,be ...

  5. 【转】ASP.NET MVC 入门教程列表

    ASP.NET MVC小论 2008-12-04 11:11 by T2噬菌体, 8052 visits, 网摘, 收藏, 编辑 摘要:ASP.NET MVC作为微软官方的.NET平台下MVC解决方案 ...

  6. Servlet监听器类型

    ------------------------serlvet对象监听器------------------------------------------- request监听器(ServletRe ...

  7. C++ 语法规则

    C++ 中的布尔类型:布尔类型只占用一个bit ,但是如果连续定义多个布尔类型时,编译器可能会多个布尔类型定义在一起.true  编译器用1来表示.false  编译器用0来表示. 将一个其他类型的数 ...

  8. ubuntu更新源

    源一定要找对应的版本 14.04对应 trusty deb http://mirrors.163.com/ubuntu/ trusty main restricted universe multive ...

  9. C# 进销存系统开发框架

    C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 视频下载: 百度 ...

  10. django笔记1

    最近在博客园看来越来越多的关于python的文章,我看到时感觉特别的好,因为我也是一个特别喜欢python这门语言,喜欢python的简洁.干净,简洁而不失强大. 最近在学习django的Model模 ...