本文共 2524 字,大约阅读时间需要 8 分钟。
A
题目大意
赌博问题,有n个人参与,都可以双倍或者三倍出价,问是否可以使得他们的出价相同
题解
既然可以双倍或者三倍 然后还要最后出价相同,那么我们就看一个数除以2或者3后的因子是否相同即可
#includeusing namespace std;const int maxn=1e5+10;typedef long long ll;ll n,a[maxn];int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=0;i >a[i]; while(a[i]%2==0) a[i]/=2; while(a[i]%3==0) a[i]/=3; } int ff=1; for(int i=0;i
B
题目大意
给定一个数字,让其仅有0,1组成的K个数构成,保证K最小。
题解
贪心
不难发现,把输入的数字想象成字符串,k的最小值就是字符串中数字的最大值,1的个数其实就是字符串每一位的数字 例如32 就是先将个位 a [ 0 ] + = 1 a [ 1 ] + = 1 然后在十位 a [ 0 ] + 10 a [ 1 ] + = 10 a [ 2 ] + = 10 整合起来就是 10 11 11 即为输出 每上升一位我们加的就增加10倍 这是很显然的 然后对于K值 我们只需要对字符串的每一位取最大值即可
#includeusing namespace std;const int maxn=100+10;char s[maxn];int n;int kmax=0,k=0;int a[maxn];int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>s; n=strlen(s); int t=1; for(int i=n-1;i>=0;i--){ k=s[i]-'0'; kmax=max(kmax,k); for(int i=0;i =1;i--) cout< <<" "; cout< <
C
题目大意
题目中说明字母的顺序可以打乱。即是说,abb可以重新排序成bab,构成回文,此时先手胜。
题解
博弈题
由于可以重新排列,然后双方又是最优选择,我们只需要考虑一下奇数个数的字母了,看有多少种,此时连忙想到了用mao维护一下,统计个数,最后我们只要判断一下奇数个字母的个数是否为奇数或者不存在奇数个字母,那么此时先手是必赢的,反之后手赢
#include#define endl '\n'using namespace std;const int maxn=1e3+10;char s[maxn];map mp;map ::iterator it;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>s; int n=strlen(s); for(int i=0;i second&1) odd++; } if(odd&1||!odd) cout<<"First"<
D
题目大意
题目要求时给定 n 和 m 表示0和1要出现的次数,并且不能连续两个 0 或连续三个1出现
题解
贪心,每次以110为一个基准出现,在后面补0或1即可
#include#define endl '\n'using namespace std;int n,m,a;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; a=n+m; if(n>m+1||n<(m-1)/2) cout<<-1; else{ while(a){ if(n==m+1){ cout<<"0"; n--,a--; }else if(m>n&&n){ cout<<"110"; n--,m-=2,a-=3; }else{ cout<<"1"; m--,a--; } } } cout<
E
题目大意
题目要求是找出一个数只包含两个因子 则称这种数为几乎素数? 然后需要你统计 1 到 n 中几乎素数的个数
题解
可以用循环来做,从2开始判断 一直判断到n 然后统计是否只包含两个因子 不过要考虑一下 你的因子中是否也包含了因子~
#includeusing namespace std;const int maxn=5e3+10;int prime[maxn],n,cnt=0;int main(){ ios::sync_with_stdio(false); cin.tie(0); cin>>n; for(int i=2;i<=n;i++){ for(int j=2;j
学如逆水行舟,不进则退
转载地址:https://chocolate.blog.csdn.net/article/details/102664337 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!