链接: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. Substr与mb_substr区别

      <?php $str = substr('helloword',3,4);//从下标3开始截取截取4个字符 $str = substr('helloword',3);//从截取掉前三个字符 ...

  2. 解决 安装VMwanre tools时 Enter the path to the kernel header files for the 3.10.0-862.14.4.el7.x86_64 kernel

    1.使用ctrl+z停止安装vmtools安装 2.然后yum升级kernel-devel yum -y install kernel-devel

  3. mysql出现unblock with 'mysqladmin flush-hosts'

    朋友发来消息,说一个系统应用登录的时候提示连接超时,让帮忙处理一下.问他应用和数据库是否都正常,回复说数据库好像没有问题,但是应用日志报无法连接数据库. 数据库版本是:5.5.53 让他telnet数 ...

  4. 海外VPS

    缘由 国内从ISP拿到的只能是内网IP,当然如今IPv4地址紧张导致的也能够理解,使用免费DDNS能够同样也能将内网通过端口映射将服务发布外网.但是千万不要小瞧了ISP的觉醒,通过限制上行带宽(ADS ...

  5. maven仓库中心mirrors配置多个下载中心(执行最快的镜像)

    E:\Program FilesApache Software Foundationapache-maven-3.5.4-binconf\settings.xmlmaven仓库中心mirrors配置多 ...

  6. 应用间共享文件 FileProvider

    应用间共享文件 FileProvider 7.0及以上版本,分析文件给其他进程访问的时候,需要使用FileProvider,否则会出现崩溃: 例如:用系统下载器下载apk,然后通过Intent安装. ...

  7. github控件地址

    地址: https://github.com/wasabeef/awesome-android-ui http://www.jcodecraeer.com/plus/list.php?tid=31 h ...

  8. MySQL 表中添加 时间戳 字段

    场景: 有张表的数据需要用同步工具同步至其他库,需要 update_time 时间戳字段 来做增量同步. 解决方法: alter table quant_stk_calc_d_wxcp add upd ...

  9. C# 正则表达式判断是否是数字、是否含有中文、是否是数字字母组合

    //判断输入是否包含中文 不管你有没有输入英文,只要包含中文,就返回 true public static bool HasChinese(string content) { //判断是不是中文 st ...

  10. Web重温系列(一):利用寄宿于IIS的WCF序列化文件

    这两年一直在做WinForm,对于Web已经比较生疏了,其实之前做的也不是很多. 这两天做了一个小工具,功能很简单,就是想有个地方存放办公室同事的机器名和IP的信息,包括附加的用户名和更新时间.比较之 ...