题目链接:codeforces 1221A
题意:
给n个数(每个数都是2的次幂),相同的两个数可以合成一个数(两个 4 可以合成 一个 8),问最终是否会出现 2048
题解:
简单模拟
#include
using namespace std;
typedef long long ll;
map mp;
int main(){
int t;
cin >> t;
while(t--){
mp.clear();
int n;
cin >> n;
for(int i = 1; i <= n; i++){
ll m;
cin >> m;
mp[m]++;
}
for(int i = 1; i < 2048; i = i * 2){
mp[i*2] = mp[i*2] + mp[i] / 2;
}
if(mp[2048] > 0){
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
return 0;
}
题目链接:codeforces 1221B
题意:
输入n,构造一个n*n的矩阵,矩阵只包含两种字母 ' B' ,'W'
如果B在蓝色位置,W在红色位置时,B和W将打架,问打架次数最多的情况应该怎样放
题解:
找规律(我当时反正没找出来)奇数行奇数列放 B,偶数行偶数列放B,其余放W就是答案
#include
int main(){
int n;
scanf("%d",&n);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
if(i%2){
if(j%2) printf("W");
else printf("B");
}
else{
if(j%2) printf("B");
else printf("W");
}
}
printf("\n");
}
return 0;
}
题目链接:codeforces 1221C
题意:
多组样例,有三类人,一类是coder,一类是mathematician, 一类是 have no specialization,然后三个人一队,要求队中至少有一个coder,一个mathematician,另外一个任意,求最多能组成多少队
题解:
首先ans = min(n, m, x) n代表coder的人数,m代表mathematician的人数,x代表have no specialization的人数
这很好理解 ,如果x大于0,那么肯定是每类各一人,然后就只剩下 coder 和 mathematician
然后n = n -ans, m = m - ans (减去上一步用过的人)
如果n > m * 2 那么 ans += m (表示n的人数如果大于m的二倍,那么表示从n中取两人,从m中取一人,m小,所以加上m)
如果m > n * n 那么 ans += n 同理
否则 ans += (n + m) / 3; 这里不太好理解,有点任取三个人的意思,但是肯定是从多的一类中取2个,从少的中取一个
#include
using namespace std;
typedef long long ll;
map mp;
int main(){
int t;
cin >> t;
while(t--){
int c, m, x;
cin >> c >> m >> x;
int ans = min(c, min(m, x));
c = c - ans;
m = m - ans;
if(c * 2 <= m){
ans += c;
}
else if(c >= m * 2){
ans += m;
}
else{
ans += (c + m) / 3;
}
cout << ans << endl;
}
return 0;
}