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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
随机推荐
- Netty实现的一个异步Socket代码
本人写的一个使用Netty实现的一个异步Socket代码 package test.core.nio; import com.google.common.util.concurrent.ThreadF ...
- easyUI 异步加载树
$(function () { var selected = $('#depttree').tree('getSelected'); $('#depttree').tree({ checkbox: f ...
- Install Redis 3.2 on Ubuntu
Install Redis 3.2 on Ubuntu It’s very easy to install Redis 3 on Ubuntu 16, just need to add PPA rep ...
- Base标签小记:更改当前页面的地址
一般来说,H5游戏的部署,index.html和代码资源都会放在同一个地址下然后使用iFrame导入到需要加载游戏的页面即可. 但是今天游戏项目部署遇到了一个问题,游戏自己的访问页面(index.ht ...
- logrus日志使用详解
1.logrus特点 golang标准库的日志框架很简单,logrus框架的特点: 1)完全兼容标准日志库 六种日志级别:debug, info, warn, error, fatal, panic ...
- go语言字符串的连接和截取
字符串的连接: https://studygolang.com/articles/12281?fr=sidebar 字符串的截取: https://studygolang.com/articles/9 ...
- VMware Workstation 14.1.1 精简特别版
VMware Workstation 精简特别版,由卡饭网友のcuiplay精简制作,集成许可证密钥安装即永久激活,该特别版最大特色可安装MAC OS X客户操作系统,此外添加了DELL SLIC 2 ...
- bash python获取文本中每个字符出现的次数
bash: grep -o . myfile | sort |uniq -c python: 使用collections模块 import pprint import collections f = ...
- macos下golang 1.9配置
1.golang最新版本下载地址 https://golang.org/dl/ (下载与安装过程此处省略一万字) 注意,go1.9与以往版本安装不同,直接安装到/usr/local/go目录下,而/u ...
- 【OSPF】防环机制详解
我们在提到OSPF的时候,时常喜欢说的一句话就是,OSPF能够计算出无环的路由,那么OSPF究竟是如何规避路由环路的呢?OSPF与距离矢量路由协议不同,运行OSPF的路由器之间交互并不是路由信息,而是 ...