A
Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1), problem: (A) Bear and Poker
题目大意
赌博问题,有n个人参与,都可以双倍或者三倍出价,问是否可以使得他们的出价相同
题解
既然可以双倍或者三倍 然后还要最后出价相同,那么我们就看一个数除以2或者3后的因子是否相同即可
#include<bits/stdc++.h>
using 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<n;i++){
cin>>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<n-1;i++){
if(a[i]!=a[i+1]){
ff=0;
break;
}
}
if(ff)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
return 0;
}
B
Codeforces Round #300, problem: (B) Quasi Binary
题目大意
给定一个数字,让其仅有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值 我们只需要对字符串的每一位取最大值即可
#include<bits/stdc++.h>
using 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<k;i++){
a[i]+=t;
}
t*=10;
}
cout<<kmax<<endl;
for(int i=kmax-1;i>=1;i--)
cout<<a[i]<<" ";
cout<<a[0]<<endl;
return 0;
}
C
Codeforces Round #169 (Div. 2), problem: (B) Little Girl and Game
题目大意
题目中说明字母的顺序可以打乱。即是说,abb可以重新排序成bab,构成回文,此时先手胜。
题解
博弈题
由于可以重新排列,然后双方又是最优选择,我们只需要考虑一下奇数个数的字母了,看有多少种,此时连忙想到了用mao维护一下,统计个数,最后我们只要判断一下奇数个字母的个数是否为奇数或者不存在奇数个字母,那么此时先手是必赢的,反之后手赢
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn=1e3+10;
char s[maxn];
map<char,int> mp;
map<char,int>::iterator it;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>s;
int n=strlen(s);
for(int i=0;i<n;i++)
mp[s[i]]++;
int odd=0;
for(it=mp.begin();it!=mp.end();it++){
if(it->second&1)
odd++;
}
if(odd&1||!odd) cout<<"First"<<endl;
else cout<<"Second"<<endl;
return 0;
}
D
Codeforces Round #235 (Div. 2), problem: © Team
题目大意
题目要求时给定 n 和 m 表示0和1要出现的次数,并且不能连续两个 0 或连续三个1出现
题解
贪心,每次以110为一个基准出现,在后面补0或1即可
#include<bits/stdc++.h>
#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<<endl;
return 0;
}
E
Codeforces Beta Round #26 (Codeforces format), problem: (A) Almost Prime
题目大意
题目要求是找出一个数只包含两个因子 则称这种数为几乎素数? 然后需要你统计 1 到 n 中几乎素数的个数
题解
可以用循环来做,从2开始判断 一直判断到n 然后统计是否只包含两个因子 不过要考虑一下 你的因子中是否也包含了因子~
#include<bits/stdc++.h>
using 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<i;j++){
if(prime[j]==0&&i%j==0)
prime[i]++;
}
if(prime[i]==2)
++cnt;
}
cout<<cnt<<endl;
return 0;
}
学如逆水行舟,不进则退