codeforces 1221 A (模拟) B(构造) C(思维)

A. 2048 Game(模拟)

题目链接:codeforces 1221A

题意:

    给n个数(每个数都是2的次幂),相同的两个数可以合成一个数(两个 4 可以合成 一个 8),问最终是否会出现 2048

题解:

   简单模拟

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, int> 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;
} 

B. Knights(构造)

题目链接:codeforces 1221B

题意:

    输入n,构造一个n*n的矩阵,矩阵只包含两种字母 ' B' ,'W' 

如果B在蓝色位置,W在红色位置时,B和W将打架,问打架次数最多的情况应该怎样放

题解:

    找规律(我当时反正没找出来)奇数行奇数列放 B,偶数行偶数列放B,其余放W就是答案

#include<cstdio>
 
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;
}

C. Perfect Team(思维)

题目链接: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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<ll, int> 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;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值