Codeforces Round #744 (Div. 3)

A. Casimir’s String Solitaire

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	while (n -- ) {
		string str;
		int a = 0, b = 0, c = 0;
		cin >> str;
		int len = str.size();
		for (int i = 0; i < len; i ++ )
			if (str[i] == 'A') a ++;
			else if (str[i] == 'B') b ++;
			else c ++;
		if (a + c == b) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

B. Shifting Sort

#include <bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
typedef pair<int, int> PII;
typedef vector<int> VI;
int a[60];
vector<PII> ans;
int main(){
	int t;
	cin >> t;
	while (t -- ) {
		ans.clear();
		int n;
		cin >> n;
		for (int i = 1; i <= n; i ++ ) cin >> a[i];
		for (int i = 1; i <= n; i ++ ) {
			int pos = i;
			int mi = a[i];
			for (int j = i + 1; j <= n; j ++ ) {
				if (a[j] < mi) {
					pos = j;
					mi = a[j];
				}
			}
			if (i != pos) {
			    ans.PB(MP(i, pos));
			    int t = a[pos];
			    int tmp = a[i];
			    for (int j = i + 1; j <= pos; j ++ ) {
			        int k = a[j];
			        a[j] = tmp;
			        tmp = k;
			    }
			    a[i] = t;
			}
		}
		cout << ans.size() << endl;
		if (ans.size() == 0) cout << endl;
		for (auto t : ans) 
			cout << t.FI << ' ' << t.SE << ' ' << t.SE - t.FI << endl;
	}
	return 0;
}

C. Ticks

#include <bits/stdc++.h>
using namespace std;
char ch[15][25];
int main(){
	int t;
	scanf("%d", &t);
	while (t -- ) {
	    int n, m, k;
	    scanf("%d%d%d", &n, &m, &k);
	    for (int i = 1; i <= n; i ++ ) 
	        scanf("%s", ch[i] + 1);
	    for (int i = 1; i <= n; i ++ ) {
	        for (int j = 1; j <= m; j ++ ) {
	            if (ch[i][j] == '*') {
	                int d = 0;
	                while (i - d >= 1 && j + d <= m && j - d >= 1 && 
	                (ch[i - d][j + d] == '*' || ch[i - d][j + d] == '!')
	                && (ch[i - d][j - d] == '*' || ch[i - d][j - d] == '!')) 
	                    d ++;
	                if (d > k) {
	                    d = 1;
	                    ch[i][j] = '!';
	                    while (i - d >= 1 && j + d <= m && j - d >= 1 && 
    	                (ch[i - d][j + d] == '*' || ch[i - d][j + d] == '!')
    	                && (ch[i - d][j - d] == '*' || ch[i - d][j - d] == '!')) 
	                        ch[i - d][j + d] = ch[i - d][j - d] = '!', d ++;
	                }
	            }
	        }
	    }
	    bool ok = 1;
	    for (int i = 1; i <= n; i ++ ) 
	        for (int j = 1; j <= m; j ++ ) 
	            if (ch[i][j] == '*') ok = 0;
	    if (ok) cout << "YES" << endl;
	    else cout << "NO" << endl;
	}
	return 0;
}

D. Productive Meeting

#include <bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 2e5 + 10;
int a[N];
vector<PII> res;
LL num[N];
int main(){
	int t;
	scanf("%d", &t);
	while (t -- ) {
	    int n;
	    res.clear();
	    memset(num, 0, sizeof num);
	    scanf("%d", &n);
	    LL sum = 0;
	    int mx = 0;
	    for (int i = 1; i <= n; i ++ ) {
	        scanf("%d", a + i);
	        sum += a[i];
	        mx = max(mx, a[i]);
	        res.PB(MP(a[i], i));
	    }
	    sum = min(sum / 2, sum - mx);
	    if (sum == 0) {
	        printf("0\n");
	        continue;
	    }
	    res.PB(MP(0, 0));
	    sort(res.begin(), res.end());
	    for (int i = 1; i <= n; i ++ ) num[i] = num[i - 1] + res[i].FI;
	    int pos = lower_bound(num + 1, num + n + 1, sum) - num;
	    int tmp = sum - num[pos - 1];
	    printf("%lld\n", sum);
	    PII k = res.back(); res.pop_back();
	    res.PB(MP(k.FI - tmp, k.SE));
	    for (int i = 1; i <= tmp; i ++ ) 
	        printf("%d %d\n", res[pos].SE, res[n].SE);
	    int l = pos - 1, r = n;
	    while (l >= 1 && r >= pos) {
	        for (int i = 1; i <= min(res[l].FI, res[r].FI); i ++ )
	        printf("%d %d\n", res[l].SE, res[r].SE);
	        int mn = min(res[l].FI, res[r].FI);
	        res[l].FI -= mn;
	        res[r].FI -= mn;
	        if (res[l].FI == 0) l --;
	        if (res[r].FI == 0) r --;
	    }
	}
	return 0;
}

E1. Permutation Minimization by Deque

#include <bits/stdc++.h>
using namespace std;
#define PB push_back
typedef vector<int> VI;
const int N = 2e5 + 10;
int a[N];
int main(){
	int t;
	scanf("%d", &t);
	while (t -- ) {
	    int n;
	    scanf("%d", &n);
	    for (int i = 1; i <= n; i ++ ) scanf("%d", a + i);
	    VI f, b;
	    if (n == 1) {
	        printf("%d\n", a[1]);
	        continue;
	    }
	    if (a[1] > a[2]) f.PB(a[2]), b.PB(a[1]);
	    else f.PB(a[1]), b.PB(a[2]);
	    for (int i = 3; i <= n; i ++ ) {
	        if (a[i] < f.back()) f.PB(a[i]);
	        else b.PB(a[i]);
	    }
	    while (f.size()) {
	        printf("%d ", f.back());
	        f.pop_back();
	    }
	    for (auto t : b) 
	        printf("%d ", t);
	    puts("");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值