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

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. Quartz.NET配置(Log4net)

    最近有个任务关于服务调度,想起以前看过Quartz.NET调度任务非常棒. 今天小试Quartz.NET,前面配置Quartz.NET很轻松,控制台也输出了.但是想配合Log4net来做日志文件,怎么 ...

  2. 安卓工程修改包名后 Failed to find provider info for...问题

    安卓工程修改包名后 Failed to find provider info for com.android...provider问题 原因: 1. 多处含包名文件须同时更改 2. Manifest里 ...

  3. Activity.startManagingCursor方法

    http://blog.sina.com.cn/s/blog_6f14deb60100wd2n.html 总结一下Activity.startManagingCursor方法: 转 我们将获得的Cur ...

  4. angularjs google map markers+ ui-gmap-windows --->增加click 事件

    jsp: <div class="modal-body viewOnMap"> <div class="cboxClose" ng-click ...

  5. 服务端配置scan ip

    节点1确认当前监听状态 SQL> show parameter listener; NAME                                 TYPE        VALUE ...

  6. java 从jar包中读取资源文件

    在代码中读取一些资源文件(比如图片,音乐,文本等等),在集成环境(Eclipse)中运行的时候没有问题.但当打包成一个可执行的jar包(将资源文件一并打包)以后,这些资源文件找不到,如下代码: Jav ...

  7. html 5的localstorag

    随着我们硬件技术的发展,浏览器本身的功能也愈发的完善,从之前的cookie到现在的本地缓存机制,再到web storage,在之前html4 的时候使用cookie具有一些明显的局限,如大小限制,co ...

  8. POJ 2391.Ombrophobic Bovines (最大流)

    实际上是求最短的避雨时间. 首先将每个点拆成两个,一个连接源点,一个连接汇点,连接源点的点的容量为当前单的奶牛数,连接汇点的点为能容纳的奶牛数. floyd求任意两点互相到达的最短时间,二分最长时间, ...

  9. spring Mvc json返回json的日期格式问题

    (一)输出json数据 springmvc中使用jackson-mapper-asl即可进行json输出,在配置上有几点: 1.使用mvc:annotation-driven 2.在依赖管理中添加ja ...

  10. 多选select实现左右添加删除

    案例:实现效果 1.选择监控城市,车辆列表显示对应城市所有车辆 2.从左边选择车辆  单击  >>   实现右侧显示添加车辆 ,左侧对应移除已选择车辆 3.右侧选中车辆     单击 &l ...