Codeforces Round #324 (Div. 2) A B C D E
A,水题不多说。
#include<bits/stdc++.h>
using namespace std; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n,t; scanf("%d%d",&n,&t);
if(t<){
for(int i = n; i--;) putchar(''+t);
}else{
if(n == ) puts("-1");
else{
putchar('');
for(int i = n; --i;) putchar('');
}
}
return ;
}
A
B,用补集算一下。
#include<bits/stdc++.h>
using namespace std; const int mod = 1e9+;
typedef long long ll;
int qpow(int a,int q)
{
int re = ;
while(q){
if(q&) re = (ll)re*a%mod;
a = (ll)a*a%mod;
q >>= ;
}
return re;
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n; scanf("%d",&n);
int ans = (qpow(,n)-qpow(,n)+mod)%mod;
printf("%d",ans);
return ;
}
B
C,当s1[i] != s2[i]的时候至少其中f值+1,效果记为10,01,11(与s1[i]和s2[i]都不同)
s1[i] == s2[i]的时候效果记为11 00。
记s[i] != s[i]有ct1个,为了保证两个f相等如果ct是奇数,单出来那个只有使得f1,f2同时加1,所以下界为low = (ct+1)/2。
其中有ct/2个对10,01 。当t<low的时候无解。
记s1[i]==s2[i]有ct2 = n-ct1个,当t>=low && t <= low+ct2的时候,只要在s1[i]==s2[i]时取相应个数个的ch,ch !=s1[i]。(11)
当t>=low+ct2的时候,需要从ct/2对中选出一些来变成 11,11
#include<bits/stdc++.h>
using namespace std; const int LEN = 1e5+;
char s[][LEN]; //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n,t; scanf("%d%d\n",&n,&t);
gets(s[]); gets(s[]);
int ct1 = ;
for(int i = ; i < n; i++){
ct1 += s[][i] == s[][i];
}
int ct2 = n-ct1;
int low = (ct2+)/;
if(t < low){
puts("-1");
}else {
int pir = low - (ct2&);
int del = t - low - ct1;
int swc = , ct, ex;
if(del > ) {
ex = ct1;
ct = (pir - del)*;
}else {
ct = (pir)*;
ex = t - low;
}
for(int i = ; i < n; i++){
if(s[][i] != s[][i]){
if(ct){ //控制 01
ct--;
putchar(s[swc ^= ][i]);
}else {
for(char c = 'a'; c <= 'z'; c++){
if(c != s[][i] && c != s[][i]) {
putchar(c); break;
}
}
}
}else {
if(ex){ //控制11
ex--;
for(char c = 'a'; c <= 'z'; c++){
if(c != s[][i] && c != s[][i]) {
putchar(c); break;
}
}
}else {
putchar(s[][i]);
}
}
}
}
return ;
}
C
D,暴力,有个事实是1e9以内的的素数间隔不超过282,sqrt(N)判断一下就好了。
#include<bits/stdc++.h>
using namespace std; const int maxn = 1e5+;
int Prim[maxn], sz ;
bool vis[maxn];
void seive(int n = maxn-)
{
int m = (int)sqrt(n+0.5);
for(int i = ; i <= m; i++){
if(!vis[i])
for(int j = i*i; j <= n; j += i){
vis[j] = true;
}
}
for(int i = ; i <= n; i++){
if(!vis[i]) Prim[sz++] = i;
}
} bool chkPrime(int x)
{
int m = (int)sqrt(x+0.5);
for(int i = ; Prim[i] <= m; i++){
if(x%Prim[i] == ) return false;
}
return true;
} //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
seive();
int n; scanf("%d",&n);
if(chkPrime(n)){
puts("");
printf("%d",n);
}else if(chkPrime(n-)){
puts("");
printf("%d %d",,n-);
}else {
puts("");
for(int i = ; ; i += ){
if(chkPrime(n-i)){
printf("%d ",n-i);
n = i;
break;
}
}
for(int i = ; Prim[i] <= n; i++){
if(chkPrime(n-Prim[i])){
printf("%d %d",Prim[i],n-Prim[i]);
break;
}
}
}
return ;
}
D
E,问交换的最小花费。看成一个置换环,最优的交换就是不断消去端点,但是这样不太好写。
一般两个排列问相对关系都可以把其中一个做映射会方便处理。把序列b映射成1...n,把a按照相同规则映射,并记录映射后元素x的位置。
从小的元素枚举,找到它在序列中的位置p[x],小的要往左边走,判断一下左边的元素是不是要往大于p[x]的位置走。如果是就交换。
p[x]的位置前面一定会有一个不小于p[x]的元素。
#include<bits/stdc++.h>
using namespace std; const int maxn = ;
int mp[maxn];
int a[maxn],p[maxn]; #define PB push_back
#define MP make_pair
#define fi first
#define se second //#define LOCAL
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
int n; scanf("%d",&n);
for(int i = ; i <= n; i++){
scanf("%d",a+i);
}
for(int i = ; i <= n; i++){
int x; scanf("%d",&x);
mp[x] = i;
}
for(int i = ; i <= n; i++){
p[ a[i] = mp[a[i]] ] = i;
} int c = ;
for(int x = ; x <= n; x++){
for(int j = p[x]; --j>=x ; ){
if(a[j] >= p[x]){
c += p[x] - j;
swap(a[j],a[p[x]]);
ans.PB(MP(j,p[x]));
p[a[j]] = p[x];
p[x] = j;
}
}
} printf("%d\n",c);
printf("%d\n",(int)ans.size());
for(auto i: ans){
printf("%d %d\n",i.fi,i.se);
}
return ;
}
E
Codeforces Round #324 (Div. 2) A B C D E的更多相关文章
- 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 ...
随机推荐
- JAVA中的工厂方法模式和抽象工厂模式
工厂方法模式: 定义:定义一个用于创建对象的接口,让子类决定实例化哪一个类,工厂方法使一个类的实例化延迟到其子类.类型:创建类模式类图: 类图知识点:1.类图分为三部分,依次是类名.属性.方法2.以& ...
- elasticsearch shard 和 replica
(1)index包含多个shard(2)每个shard都是一个最小工作单元,承载部分数据,lucene实例,完整的建立索引和处理请求的能力(3)增减节点时,shard会自动在nodes中负载均衡(4) ...
- 帝都Day3——各种dp
备注:Day1 Day2记得笔记太233,所以就不发了 备注2:Day4~Day7发不发看心情qaq (7.17持续更新中...) 动态规划A 记忆化搜索 & 动态规划初步 8点15: 杨姓d ...
- AtCoder Beginner Contest 121 题解
题目链接:https://atcoder.jp/contests/abc121 A White Cells 分析:题目数据规模很小,直接暴力修改都可以.或者可以推出公式. 代码: #include & ...
- kubernetes(安装dashboard)
https://blog.csdn.net/qq_22917163/article/details/84527420 1. 通过yaml文件安装dashboard 我们可以从https://githu ...
- 提升Exadata 计算节点本地IO性能
1.问题概述 某客户有一台Exadata X2-2,每个计算节点是4块普通的本地SAS硬盘做成的RAID5,然后在RAID5的本地硬盘上创建了一个文件系统来存放DSG数据同步软件,在后续的运维过程中, ...
- H5页面开发的touchmove事件
在做一屏滚动的H5页面的时候,必须移除touchmove事件,如果不移除,在安卓机上会触发微信原生的向下滚动拉出刷新.在IOS上出现上下都可以继续滑动,所以需要移除document的touchmove ...
- 1100 Mars Numbers(20 分)
People on Mars count their numbers with base 13: Zero on Earth is called "tret" on Mars. T ...
- c++的直接初始化与复制初始化 未完成!!!!!!!!!!!!
直接初始化:是直接调用类的构造函数进行初始化.如下: string a;//调用默认构造函数 string a("hello");//调用参数为 const char* 类型的构造 ...
- linux下各种格式软件的安装(引用http://blog.csdn.net/zyz511919766/article/details/7574040)
首先介绍两个简单的方式 第一:sudo apt-get install packagename 命令 如果我们知道我们要安装的软件的确切的名称,那么我们可以简单的通过此条命令来获取和安装软件.apt- ...