首页 > 其他分享 >codeforces ECR169

codeforces ECR169

时间:2024-08-16 12:15:48浏览次数:7  
标签:int mi codeforces ECR169 vector solve mol maxn

codeforces ECR 169

A

#include<bits/stdc++.h>
using namespace std;
const int maxn=50;
int a[maxn];
void solve()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    if(n==2)
    {
        if((a[2]-a[1])!=1)
        {
            cout<<"YES\n";
        }
        else
        {
            cout<<"NO\n";
        }
    }   
    else
    {
        cout<<"NO"<<'\n';
    } 
}
int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

B

#include<bits/stdc++.h>
using namespace std;
const int maxn=50;
int a[maxn];
#define   fi     first   
#define   se     second  
void solve()
{
    pair<int ,int>a[2];
    cin>>a[0].fi>>a[0].se;
    cin>>a[1].fi>>a[1].se;
    if(a[0].se<a[1].fi||a[1].se<a[0].fi)
    {
        cout<<1<<'\n';
    }
    else
    {
        int ans=min(a[0].se,a[1].se)-max(a[0].fi,a[1].fi);
        if(a[0].se!=a[1].se)ans++;
        if(a[0].fi!=a[1].fi)ans++;
        cout<<ans<<'\n';
    }
}
int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

C

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=2e5+9;
int a[maxn];
void solve()
{
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)cin>>a[i];
    sort(a+1,a+1+n);
    for(int i=n-1;i>=1;i-=2)
    {
        if(a[i+1]-a[i]<=k)
        {
            k-=a[i+1]-a[i];
            a[i]+=a[i+1]-a[i];
        }
        else
        {
            a[i]+=k;
            k=0;
            break;
        }
    }
    int cnt=1;
    int sum=0;
    for(int i=n;i>=1;i--)
    {
        if(cnt%2==1)
        {
            sum+=a[i];
        }
        else
        {
            sum-=a[i];
        }
        cnt++;
    }
    cout<<sum<<'\n';
}
signed main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0),cout.tie(0);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}

D

#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 9;
string t[maxn];
string mol[6] = {"BG", "BR", "BY", "GR", "GY", "RY"};
void solve()
{
    int n, q;
    cin >> n >> q;
    map<string, vector<int>> b;
    // BG、BR、BY、GR、GY 或 RY
    b["BG"] = vector<int>(), b["BR"] = vector<int>(), b["BY"] = vector<int>(), b["GR"] = vector<int>(), b["GY"] = vector<int>(), b["RY"] = vector<int>();
    string s;
    for (int i = 1; i <= n; i++)
    {
        cin >> s;
        t[i] = s;
        b[s].push_back(i);
    }
    for (int i = 0; i < 6; i++)
    {
        sort(b[mol[i]].begin(), b[mol[i]].end());
    }
    int x, y;
    for (int i = 1; i <= q; i++)
    {
        cin >> x >> y;
        if (x == y)
        {
            cout << 0 << '\n';
            continue;
        }
        if (t[x][0] == t[y][0] || t[x][0] == t[y][1] || t[x][1] == t[y][0] || t[x][1] == t[y][1])
        {
            int mi = abs(y - x);
            cout << mi << "\n";
        }
        else
        {
            if (x > y)
                swap(x, y);
            int mi = 0x7ffffff;
            for (int _ = 0; _ < 6; _++)
            {
                if ((mol[_].find(t[x][0]) != -1 || mol[_].find(t[x][1]) != -1) && mol[_] != t[x])
                {
                    if (b[mol[_]].size() == 0)
                        continue;
                    if (b[mol[_]][0] > y)
                    {
                        mi = min(mi, abs(2 * b[mol[_]][0] - x - y));
                    }
                    else if (b[mol[_]][b[mol[_]].size() - 1] < x)
                    {
                        mi = min(mi, abs(x + y - 2 * b[mol[_]][b[mol[_]].size() - 1]));
                    }
                    else
                    {
                        mi = min(mi, y - x);
                    }
                }
            }
            cout << ((mi == 0x7ffffff) ? -1 : mi) << '\n';
        }
    }
}
int main()
{
    std::ios::sync_with_stdio(0);
    std::cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
        solve();
    return 0;
}

/*
1
1 1
BR 
1 1

*/

标签:int,mi,codeforces,ECR169,vector,solve,mol,maxn
From: https://www.cnblogs.com/cxjy0322/p/18362633

相关文章

  • CodeForces 1575F Finding Expected Value
    洛谷传送门CF传送门考虑单个序列如何求答案。考虑鞅与停时定理。定义一个局面的势能为\(\sum\limits_{i=0}^{K-1}f(b_i)\),其中\(f(x)\)是一个关于\(x\)的函数,\(b_i\)为\(i\)的出现次数。那么我们要构造\(f(x)\),使得每次操作,局面势能期望减少\(1\),那么期望步数......
  • Codeforces 232 B Table 题解 [ 蓝 ] [ 分组背包 ] [ 组合数学 ] [ 循环节 ]
    Codeforces232BTable。蒟蒻模拟赛上场切的一道蓝,非常难以置信我竟然能做蓝题。这题的数据范围初看还是比较坑的,\(10^{18}\)的值域很容易让人往矩阵加速那方面想。实际上在列出转移方程式后,我们发现状态是二维的,无法使用矩阵加速(或者说这样做很麻烦)。思路首先观察到每个边长......
  • Codeforces Round 966 (Div. 3) VP
    A.PrimaryTask枚举所有情况即可voidsolve(){ strings; cin>>s; if(s.substr(0,2)!="10"||s.size()<3||s[2]=='0'||(s.size()<4&&s[2]<'2')){ cout<<"NO\n"; } else{......
  • [CodeForces] F. Color Rows and Columns
    ProblemLink Basedoninitialobservation,itseemsthatgreedilypickthesmallestrow/columnlengthworks.Butthelastexampletestcaseoutputs35whilegreedygives36.  Howyoushouldgofromthere:1.checkifyourgreedyimplementationisco......
  • Codeforces Round 966 (Div. 3)
    A-PrimaryTask给一个数\(x\),判断其是否形如\(\overline{ab}\)满足\(a=10,b\ge2\)且无前导零。模拟判断即可。code#include<bits/stdc++.h>usingnamespacestd;constintmaxn=3e5+3;intT;stringn;voidsolve(){ cin>>n; if((n=="1"||n=="10......
  • Codeforces Round894.D
    题目:D.IceCreamBalls题目链接:https://codeforces.com/contest/1862/problem/D思路:二分找到当所有冰淇淋球类型不同的情况下,假设记位k,满足k(k-1)/2<=n;此时不一定就等于k,所以考虑到有重复类型的冰淇淋球。当有两个重复类型的球时,可做不同类型的冰淇淋有k(k-1)/2+1,若有......
  • Codeforces Round 966 (Div. 3)
    Abstract第二次打CodeForce。A.PrimaryTaskIdea签到题。意思就是说给一个字符串,要你判断一下前两位是不是10,除去前两位后后面的部分是不是一个大于等于2的数(不能有前导零)。Code#include<bits/stdc++.h>usingnamespacestd;voidsolve(){stringtext;......
  • Codeforces Round 947 (Div. 1 + Div. 2)
    [传送门](Dashboard-CodeforcesRound947(Div.1+Div.2)-Codeforces)###A.枚举一个位置,把他前面和后面反转一下判断就行。###B.找到最小的数和最小的不是它的倍数的数当作$i$和$j$,判断合不合法即可。###C.不知道怎么就模出来了操作长度一定小于等于3,然后......
  • Codeforces Round 946 (Div. 3)
    ###G.一眼看上去很想个背包,然后发现好像不大能做。考虑反悔贪心。对于当前的$c_i$,如果到现在攒的钱足够买这个,那就直接买了它。如果钱不够,就从之前的买过的里面把一个最大的给退掉,然后买这个,优先队列维护即可。```c++#include<bits/stdc++.h>#defineintlonglongu......
  • Codeforces Round 964 (Div. 4)
    ###A.```c++#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+7;voidsolve(){  intx;  cin>>x;  cout<<x/10+x%10<<endl;}intmain(){  intT;  cin>>T;  while(T--)solve();......