链接:https://codeforces.com/contest/584


A - Olesya and Rodion - [水]

题解:注意到 $t$ 的范围是 $[2,10]$,对于位数小于 $2 \times 3 \times \cdots \times 10 = 3628800$ 的数,暴力枚举去找;否则就直接在 $3628800$ 后面补零即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int n,t;
int p10[];
int main()
{
ios::sync_with_stdio(); cin>>n>>t;
if(n>=)
{
cout<<;
for(int i=;i<=n;i++) cout<<;
cout<<endl;
}
else
{
p10[]=;
for(int i=;i<;i++) p10[i]=p10[i-]*; bool ok=;
for(int x=p10[n-];x<p10[n];x++)
{
if(x%t==)
{
cout<<x<<endl;
ok=;
break;
}
}
if(!ok) cout<<-<<endl;
}
}

B - Kolya and Tanya - [组合数]

题解:对于一个等边三角形上的三个人,有 $20$ 种方案使得和不等于 $6$,有 $7$ 种方案使得和等于 $6$,然后很容易得到公式 $\sum_{i=1}^{n} C_{n}^{i} \cdot 20^i \cdot 7^{n-i}$。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+;
int n;
ll fpow(ll a,ll n)
{
ll res=,base=a%mod;
while(n)
{
if(n&) res*=base, res%=mod;
base*=base, base%=mod;
n>>=;
}
return res%mod;
}
ll inv(ll n){return fpow(n,mod-);} int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n;
ll ans=;
ll C=1ll, A=1ll, B=fpow(7ll,n);
for(int i=;i<=n;i++)
{
C=C*(n+-i), C%=mod;
C=C*inv(i), C%=mod; A*=20ll, A%=mod;
B*=inv(), B%=mod; ans+=((C*A)%mod)*B%mod, ans%=mod;
}
cout<<ans<<endl;
}

C - Marina and Vasya - [字符串]

题解:

要有 $t$ 个不同字符,就是要有 $n-t$ 个相同字符;对于 $s_1,s_2$ 两个字符串,如果存在 $s_1[i] = s_2[i]$ 就尽量让 $s_3[i]$ 也是这个字符。如果直接就能把 $n-t$ 个要求相同的字符全搞定了,剩下的就可以乱放。

如果还剩下来 $n-t-same$(此处 $same$ 代表 $s_1,s_2$ 中相同位置且相同字符的数目),要求有这么多个相同字符。那记 $diff$ 代表 $s_1,s_2$ 中相同位置但不同字符的数目,讨论一下 $2(n-t-same)$ 与 $diff$ 的关系即可。

AC代码:

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int n,t;
string s1,s2,s3;
bool f[maxn];
int same,diff;
inline char Find(char x,char y)
{
if(x!='a' && y!='a') return 'a';
if(x!='b' && y!='b') return 'b';
if(x!='c' && y!='c') return 'c';
}
int main()
{
ios::sync_with_stdio();
cin.tie(), cout.tie(); cin>>n>>t; t=n-t;
cin>>s1>>s2; for(int i=;i<n;i++) s3+=''; int diff=;
for(int i=;i<n;i++)
{
if(s1[i]!=s2[i]) diff++;
if(s1[i]==s2[i] && t>)
{
s3[i]=s1[i];
t--;
}
} if(t>)
{
if(*t>diff) s3="-1";
else
{
int cnt=;
for(int i=;i<n;i++)
{
if(s3[i]!='') continue;
s3[i]=s1[i], cnt++;
if(cnt==t) break;
}
cnt=;
for(int i=;i<n;i++)
{
if(s3[i]!='') continue;
s3[i]=s2[i], cnt++;
if(cnt==t) break;
} for(int i=;i<n;i++)
{
if(s3[i]!='') continue;
s3[i]=Find(s1[i],s2[i]);
}
}
}
else
{
for(int i=;i<n;i++)
{
if(s3[i]!='') continue;
s3[i]=Find(s1[i],s2[i]);
}
} cout<<s3<<endl;
}

D - Dima and Lisa - [简单数论]

题解:

有一个命题:不小于 $6$ 的偶数都能表示成两个质数的和,然后 $4$ 可以表示成 $2+2$。

所以,我们只要让 $p_1 = 3$,那么剩下来 $n-3$ 必为偶数,就能找到两个质数加起来等于它,这要求最少也要筛 $1 \sim 5e8$ 的素数,会MLE。

因此,我们可以找出 $1e8,2e8,\cdots,9e8$ 这些数字附近的一个素数,然后例如 $n = 5e8+6e7$ 时,我们可以选 $p_1 = 5e8+9$,这样剩下来 $n - (5e8+9)$ 这个数的范围就保证在 $1 \sim 1e8$ 之间,然后我们只需要筛 $1 \sim 1e8$ 之间的素数就可以了。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int n; const int MAX=1e8+;
int cnt,prime[MAX/];
bool isPrime[MAX+];
void Screen() //欧拉筛法求素数
{
cnt=;
memset(isPrime,,sizeof(isPrime));
isPrime[]=isPrime[]=;
for(int i=;i<=MAX;i++)
{
if(isPrime[i]) prime[cnt++]=i;
for(int j=;j<cnt;j++)
{
if(i*prime[j]>MAX) break;
isPrime[i*prime[j]]=;
if(i%prime[j]==) break;
}
}
} P Find(int sum)
{
int p1=, p2=cnt-;
while(p1<=p2 && prime[p1]+prime[p2]!=sum)
{
if(prime[p1]+prime[p2]>sum) p2--;
else p1++;
}
return make_pair(prime[p1],prime[p2]);
} int D[]={(int)9e8-,(int)8e8-,(int)7e8+,(int)6e8+,(int)5e8+,(int)4e8+,(int)3e8+,(int)2e8-,(int)1e8+}; int main()
{
Screen(); cin>>n; if(n==)
{
printf("1\n");
printf("3\n");
return ;
}
if(n==)
{
printf("2\n");
printf("2 2\n");
return ;
}
if(n==)
{
printf("2\n");
printf("2 3\n");
return ;
}
if(n==)
{
printf("3\n");
printf("2 2 2\n");
return ;
} for(int i=;i<;i++)
{
if(n-D[i]>=)
{
P res=Find(n-D[i]);
printf("3\n");
printf("%d %d %d\n",D[i],res.first,res.second);
return ;
}
} P res=Find(n-);
printf("3\n");
printf("3 %d %d\n",res.first,res.second);
}

E - Anton and Ira - [贪心]

Codeforces 584 - A/B/C/D/E - (Done)的更多相关文章

  1. Codeforces Round #584 E2. Rotate Columns (hard version)

    链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...

  2. Codeforces Round #584 D. Cow and Snacks

    链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...

  3. Codeforces Round #584 C. Paint the Digits

    链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...

  4. Codeforces Round #584 B. Koala and Lights

    链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...

  5. Codeforces Round #584 A. Paint the Numbers

    链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...

  6. Codeforces Round #584

    传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...

  7. Codeforces Round 584 题解

    -- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...

  8. Codeforces Round #584 (Div. 1 + Div. 2)

    Contest Page A sol 每次选最小的,然后把它的所有倍数都删掉. #include<bits/stdc++.h> using namespace std; int read( ...

  9. 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

随机推荐

  1. Libreoffice 各类文件转换的filtername

    LIBREOFFICE_DOC_FAMILIES = [ "TextDocument", "WebDocument", "Spreadsheet&qu ...

  2. zabbix 界面翻译不完全的处理

    zabbix是一个多语言监控系统,界面显示由对应的语言下的frontend.mo控制.当前对中文的翻译不完全,如下图 如果我们需要自己优化,将此翻译成中文,那么你需要修改zh_CN下的frontend ...

  3. 机器人关节空间轨迹规划--S型速度规划

    关节空间 VS 操作空间 关节空间与操作空间轨迹规划流程图如下(上标$i$和$f$分别代表起始位置initial和目标位置final): 在关节空间内进行轨迹规划有如下优点: 在线运算量更小,即无需进 ...

  4. iOS 可高度自定义的底部弹框

    技术: iOS Objective-C   概述 一个可以让开发者通过编写 tableView 的内容随心所欲的定制自己想要的底部弹框 详细 代码下载:http://www.demodashi.com ...

  5. Linux-进程描述符 task_struct 详解

    为了描述控制进程的运行,系统中存放进程的管理和控制信息的数据结构称为进程控制块 PCB(Process Control Block),它是进程实体的一部分,是操作系统中最重要的记录性数据结构.它是进程 ...

  6. 生成命令行接口--google开源的fire使用体验【python-fire】

    在python中,命令行接口常用的argparse 和click,但是相对于python-fire 来说灵活度太缺了,fire可以直接将python中的函数,以命令行显示. 简单的介绍几个例子: #! ...

  7. Mybatis中自定义映射xml参数传递使用

    在使用mybatis框架时,大多时候自动生成的mapper.xml文件能满足我们所需的数据库操作,但一些情况下还是需要我们自己写sql:为了加深印象,总结了下参数传递的方式以及各个关键字的含义如下: ...

  8. 安装APK失败,错误代码:INSTALL_FAILED_INVALID_APK 解决方案

    错误代码:installation failed with message failed to finalize session:INSTALL_FAILED_INVALID_APK 解决方法如下:

  9. kalman滤波

    kalman滤波原理(通俗易懂) 1. 在学习卡尔曼滤波器之前,首先看看为什么叫“卡尔曼”.跟其他著名的理论(例如傅立叶变换,泰勒级数等等)一样,卡尔曼也是一个人的名字,而跟他们不同的是,他是个现代人 ...

  10. css3 box-shadow 使用方法详解

    其用法为:  代码如下 复制代码 box-shadow: x-offset y-offset blur spread color inset; 上述六个参数含义依次是水平方向的偏移(正值向右偏移,负值 ...