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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
随机推荐
- 小程序学习笔记五:API
API 小程序提供了丰富的微信原生API,可以方便的调起微信提供的能力,如获取用户信息,本地存储,支付功能等. api调用格式: 1:wx.on 开头的 API 是监听某个事件发生的API接口,接受一 ...
- 中期linux课程考试题
[口头表达] 1)请描述你了解的磁盘分区的相关知识2)什么是rsync,你有什么生产环境的应用?3)在生产环境中,公司的IDC机房即将超过254台机器,请问你有什么解决方案来规划扩展IDC机房的内网网 ...
- spring boot 搭建
http://www.ityouknow.com/springboot/2018/06/12/spring-boo-java-simple.html 在http://start.spring.io/下 ...
- utf-8 编码问题
使用下面直接进行处理$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
- 全面理解Java内存模型(JMM)及volatile关键字(转载)
关联文章: 深入理解Java类型信息(Class对象)与反射机制 深入理解Java枚举类型(enum) 深入理解Java注解类型(@Annotation) 深入理解Java类加载器(ClassLoad ...
- Effective Java 第三版—— 90.考虑序列化代理替代序列化实例
Tips 书中的源代码地址:https://github.com/jbloch/effective-java-3e-source-code 注意,书中的有些代码里方法是基于Java 9 API中的,所 ...
- 基于Python37配置图片文字识别
以管理员权限打开cmd控制台. 1.如何安装PIL 输入下面命令:pip install Pillow 参考:https://www.cnblogs.com/mrgavin/p/8177841.htm ...
- React Native 从入门到原理一
React Native 从入门到原理一 React Native 是最近非常火的一个话题,介绍如何利用 React Native 进行开发的文章和书籍多如牛毛,但面向入门水平并介绍它工作原理的文章却 ...
- mybatis generator 为数据库保留字段 转义
为order 添加转义符号“ ` ” `order` <property name="autoDelimitKeywords" value="true"& ...
- flask wigs 服务器
Nginx:Hey,WSGI,我刚收到了一个请求,我需要你作些准备,然后由Flask来处理这个请求. WSGI:OK,Nginx.我会设置好环境变量,然后将这个请求传递给Flask处理. Flask: ...