Codeforces Round 944 (Div. 4)A->G题解

A.My First Sorting 问题

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
 
int x, y;
void solve()
{
    cin >> x >> y;
    if (x > y) swap(x,y);
    cout << x << " " << y << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

B.Different String

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
 
string A;
void solve()
{
    cin >> A;
    int len = A.length();
    for (int i = 1;i < len;i++)
    {
        if (A[i] != A[i-1])
        {
            cout << "YES" << endl;
            swap(A[i],A[i-1]);
            cout << A << endl;
            return;
        }
    }
    cout << "NO" << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

C.Clock and Strings

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
 
int a, b, c, d;
int A[15];
void solve()
{
    memset(A,0,sizeof(A));
    cin >> a >> b >> c >> d;
    if (a > b) swap(a,b);
    if (c > d) swap(c,d);
    int op = 0;
    for (int i = a;i <= b;i++)
    {
        A[i] = 1;
    }
    for (int i = c;i <= d;i++)
    {
        if (A[i] == 1)
        {
            op++;
            break;
        }
    }
    // cout << op << endl;
    int u = 0;
    for (int i = d;i <= 12;i++)
    {
        if (A[i] == 1)
        {
            u++;
            break;
        }
    }
    for (int i = 1;i <= c;i++)                       
    {
        if (A[i] == 1)
        {
            u++;
            break;
        }
    }
    if (u) op++;
    // cout << op << endl;
    memset(A,0,sizeof(A));
    for (int i = 1;i <= a;i++)
    {
        A[i] = 1;
    }
    for (int i = b;i <= 12;i++)
    {
        A[i] = 1;
    }
    for (int i = c;i <= d;i++)
    {
        if (A[i] == 1)
        {
            op++;
            break;
        }
    }
    // cout << op << endl;
    u = 0;
    for (int i = d;i <= 12;i++)
    {
        if (A[i] == 1)
        {
            u++;
            break;
        }
    }
    for (int i = 1;i <= c;i++)
    {
        if (A[i] == 1)
        {
            u++;
            break;
        }
    }
    if (u) op++;
    // cout << op << endl;
    if (op == 4) cout << "YES" << endl;
    else cout << "NO" << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

D.Binary Cut

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
 
string A;
void solve()
{
    cin >> A;
    int len = A.length();
    int ans = 1;
    int u = 0;
    for (int i = 1;i < len;i++)
    {
        if (A[i] != A[i-1]) ans++;
    }
    for (int i = 1;i < len;i++)
    {
        if (A[i] == '1'&&A[i-1] == '0')
        {
            u = 1;
        }
    }
    cout << ans - u << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

E.Find the Car

        屎

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
int n, k ,q;
LL A[N], B[N];
void solve()
{
    cin >> n >> k >> q;
    int a, b;
    for (int i = 1;i <= k;i++)
        cin >> A[i];
    for (int i = 1;i <= k;i++)
        cin >> B[i];
    while (q--)
    {
        int x;
        cin >> x;
        int st = lower_bound(A+1,A+k+1,x)-A-1;
        int ans = B[st]+(x-A[st])*(B[st+1]-B[st])/(A[st+1]-A[st]);
		cout << ans << ' ';
    }
    cout << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

F.Circle Perimeter

不是递推,下面是官方题解

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned LLULL;
const int N = 1e5+10;
const int P = 131;

void solve()
{
    LL r;
    cin >> r;
    LL height = r;
    LL ans = 0;
    for(LL i = 0; i <= r; i++)
    {
        while(i*i+height*height >= (r+1)*(r+1))
        {
            height--;
        }
        LL cop = height;
        while(i*i+cop*cop >= r*r && cop > 0)
        {
            cop--;
            ans++;
        }
    }
    cout << ans*4 << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

G.XOUR

如果可以异或小于4,那么就可以任意交换,只需要把他们放在一起排序再一个一个放回原来的地方,官方写法太妙了

#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;
typedef unsigned LLULL;
const int N = 2e5+10;
const int P = 131;

int n, A[N];
void solve()
{
    cin >> n;
    map<int, priority_queue<int>> D;
    for (int i = 1;i <= n;i++)
    {
        cin >> A[i];
        D[A[i]>>2].push(-A[i]);
    }
    for (int i = 1;i <= n;i++)
    {
        cout << -D[A[i]>>2].top() << " ";
        D[A[i]>>2].pop();
    }
    cout << endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值