Codeforces Round #839 (Div. 3) A~E补题

A.A+B?

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll T, n, m;
ll x, y;
ll a[N];
char s[N];
char e;
ll sum, res;
ll f, ok;
void solve () {
	cin >> x >> e >> y;
    
    cout << x + y << endl;
}
int main() {
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

B.Matrix Rotation

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll T, n, m;
ll x, y, v;
ll a[N], b[N], c[N], d[N];
char s[N];
char e;
ll sum, res;
ll f, ok;
void solve () {
    cin >> v;
    a[1] = v;
    b[2] = v;
    c[3] = v;
    d[4] = v;

    cin >> v;
    a[2] = v;
    b[3] = v;
    c[4] = v;
    d[1] = v;

    cin >> v;
    a[4] = v;
    b[1] = v;
    c[2] = v;
    d[3] = v;
    
    cin >> v;
    a[3] = v;
    b[4] = v;
    c[1] = v;
    d[2] = v;

    if (a[1] < a[2] && a[1] < a[4] && a[2] < a[3] && a[4] < a[3]) {
        cout << "YES\n";
        return;
    }

    if (b[1] < b[2] && b[1] < b[4] && b[2] < b[3] && b[4] < b[3]) {
        cout << "YES\n";
        return;
    }

    if (c[1] < c[2] && c[1] < c[4] && c[2] < c[3] && c[4] < c[3]) {
        cout << "YES\n";
        return;
    }

    if (d[1] < d[2] && d[1] < d[4] && d[2] < d[3] && d[4] < d[3]) {
        cout << "YES\n";
        return;
    }
    cout << "NO\n";
}
int main() {
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

C.Different Differences

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll T, n, m, k, j;
ll x, y;
ll a[N];
string s;
char e;
ll sum, res, num;
ll f, ok;
void solve () {
    num = 0;
    cin >> k >> n;
    for (int i = k - 1; i > 0; i--) {
        if ((i * i + i) / 2 + 1 + num <= n) {
            for (j = 0; j <= i; j++) {
                printf ("%d ", (j * j + j) / 2 + 1);
            }
            j -= 1;
            for (int l = 0; l < num; l++) {
                printf ("%d ", (j * j + j) / 2 + 2 + l);
            }
            puts("");
            return;
        }
        else {
            num++;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

D.Absolute Sorting

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn=2e5+5;
const ll inf=1e9;
ll t,n,m,x,y,k;
ll a[maxn];
int main()
{
	cin>>t;
	while(t--){
		cin>>n;
		for(ll i=1;i<=n;i++)cin>>a[i];
		ll x=-inf,y=inf;
		ll l=-inf,r=inf;
		for(ll i=2;i<=n;i++){
			if(a[i-1]<a[i])y=(a[i-1]+a[i])/2;
			else if(a[i-1]>a[i])x=ceil((a[i-1]+a[i])*1.0/2);
			l=max(l,x),r=min(r,y);
		}
		if(l>r)cout<<-1<<endl;
		else if(r>=0&&r<=1e9)cout<<r<<endl;
	}
	return 0;
}

E.Permutation Game

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e7 + 10;
ll const inf = 1e9;
ll T, n, m, k;
ll x, y, v, l, r;
ll a[N];
char s[N];
char e;
ll sum, res, num;
ll f, ok;
void solve () {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll cnt1 = 0, cnt2 = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == i) {
            cnt1++;
        }
        else if (a[i] == n - i + 1) {
            cnt2++;
        }
    }
    ll cnt = n - cnt1 - cnt2;
    if (cnt2 + cnt <= cnt1) {
        cout << "First\n";
        return;
    }
    if (cnt1 + cnt < cnt2) {
        cout << "Second\n";
        return;
    }
    cout << "Tie\n";
}
int main() {
    ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值