Codeforces 584 - A/B/C/D/E - (Done)
链接: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)的更多相关文章
- Codeforces Round #584 E2. Rotate Columns (hard version)
链接: https://codeforces.com/contest/1209/problem/E2 题意: This is a harder version of the problem. The ...
- Codeforces Round #584 D. Cow and Snacks
链接: https://codeforces.com/contest/1209/problem/D 题意: The legendary Farmer John is throwing a huge p ...
- Codeforces Round #584 C. Paint the Digits
链接: https://codeforces.com/contest/1209/problem/C 题意: You are given a sequence of n digits d1d2-dn. ...
- Codeforces Round #584 B. Koala and Lights
链接: https://codeforces.com/contest/1209/problem/B 题意: It is a holiday season, and Koala is decoratin ...
- Codeforces Round #584 A. Paint the Numbers
链接: https://codeforces.com/contest/1209/problem/A 题意: You are given a sequence of integers a1,a2,-,a ...
- Codeforces Round #584
传送门 A. Paint the Numbers 签到. Code #include <bits/stdc++.h> using namespace std; typedef long l ...
- Codeforces Round 584 题解
-- A,B 先秒切,C 是个毒瘤细节题,浪费了很多时间后终于过了. D 本来是个 sb 题,然而还是想了很久,不过幸好没什么大事. E1,看了一会就会了,然而被细节坑死,好久才过. 感觉 E2 很可 ...
- Codeforces Round #584 (Div. 1 + Div. 2)
Contest Page A sol 每次选最小的,然后把它的所有倍数都删掉. #include<bits/stdc++.h> using namespace std; int read( ...
- 状压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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
随机推荐
- A Sample Linker Script
from:http://www.hertaville.com/a-sample-linker-script.html A sample script file that will work with ...
- TFS online build change web.config
概要 TFS online 自动编译时如何修改web.config ref:https://dustinoprea.com/2016/05/06/using-tokenization-token-re ...
- 在Ubuntu18.04下配置HBase
HBase在HDFS基础上提供了高可靠, 列存储, 可扩展的数据库系统. HBase仅能通过主键(row key)和主键的range来检索数据, 主要用来存储非结构化和半结构化的松散数据. 与Hado ...
- 【C++】C++中的字符和字符串
目录结构: contents structure [-] 定义和初始化string string对象上的操作 处理string对象中的字符 C风格字符串 标准库类型string表示可变长的字符序列,使 ...
- [elk]kafka_elk
kafka https://www.tutorialspoint.com/apache_kafka/apache_kafka_cluster_architecture.htm https://dzon ...
- 利用pentestbox打造ms17-010移动"杀器"
本文首发Freebuf,属原创奖励计划,未经许可禁止转载. 链接:http://www.freebuf.com/articles/system/132274.html 一. 前言 前段时间Shadow ...
- 红米3 TWRP-3.2.1-0(android_7.1.2_r29) 刷8.1不提示错误 刷MIUI不再卡屏 修复无系统重启问题 更新于20180316
TWRP简介: TWRP是一个安卓平台很受欢迎的第三方REC,界面好看,功能强大. TWRP更新日志: 20180316更新: 1.使用最新android-7.1.2_r29分支源码适配. 2.更新版 ...
- SparkThriftServer 源码分析
目录 版本 起点 客户端--Beeline 服务端 Hive-jdbc TCLIService.Iface客户端请求 流程 SparkThrift 主函数HiveThriftServer2 Thrif ...
- SAP S4HANA1610/Fiori安装过程全记录
经历各种坑,从硬件到文件,终于安装成功. 有需要安装或使用S4HANA(含Fiori)的同学可以参考. 安装文件分享给大家 链接:http://pan.baidu.com/s/1mi7LfIS 密码: ...
- 使用python脚本实现iOS图片资源压缩
最近公司有一个新的需求,要把代码进行瘦身,这篇博客记录下如何对图片进行压缩的. 原理: 写一个脚本,把图片文件夹'.xcassets'的所有文件遍历出来,然后使用一个第三方的算法把图片压缩后再替换回去 ...