首页 > 其他分享 >Codeforces 920 (div3)

Codeforces 920 (div3)

时间:2024-01-19 15:15:05浏览次数:26  
标签:cout int LL Codeforces long cin 920 div3

Problem - A - Codeforces

没什么问题,几个if else语句,判断一下条件;

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int k;
    cin >> k;
    
    while(k --)
    {
        int x1 , y1 , x2 , y2 , x3 , y3 , x4 , y4;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;
        
        if(x1 == x2)
        {
            int t = abs(y2 - y1);
            cout << t * t << endl;
        }
        else if(x2 == x3)
        {
            int t = abs(y2 - y3);
            cout << t * t << endl;
        }
        else if(x3 == x4)
        {
            int t = abs(y3 - y4);
            cout << t * t << endl;
        }
        else if(x4 == x1)
        {
            int t = abs(y4 - y1);
            cout << t * t << endl;
        }
        else if(x1 == x3)
        {
            int t = abs(y3 - y1);
            cout << t * t << endl;
        }
        else if(x2 == x4)
        {
            int t = abs(y2 - y4);
            cout << t * t << endl;
        }
        else if(y1 == y2)
        {
            int t = abs(x2 - x1);
            cout << t * t << endl;
        }
        else if(y2 == y3)
        {
            int t = abs(x2 - x3);
            cout << t * t << endl;
        }
        else if(y3 == y4)
        {
            int t = abs(x3 - x4);
            cout << t * t << endl;
        }
        else if(y4 == y1)
        {
            int t = abs(x4 - x1);
            cout << t * t << endl;
        }
        else if(y1 == y3)
        {
            int t = abs(x3 - x1);
            cout << t * t << endl;
        }
        else if(y2 == y4)
        {
            int t = abs(x2 - x4);
            cout << t * t << endl;
        }
    }
    
    return 0;
}

Problem - B - Codeforces

B题,看到01数组 我们首先想到贪心或者思维题(找规律),所以我们选择找规律,我们可以发现只要出现一对1和0都不匹配,我们就可以将他们交换,从而匹配,剩下的就只能进行单个修改;

include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int k;
    cin >> k;
    
    while(k --)
    {
        int n;
        cin >> n;
        string a , b;
        cin >> a >> b;
        
        if(a == b) cout << 0 << endl;
        else 
        {
            int num0 = 0 , num1 = 0;
            for(int i = 0 ; i < a.size() ; i ++)
            {
                if(a[i] == '1' && a[i] != b[i]) num1 ++;
                if(a[i] == '0' && a[i] != b[i]) num0 ++;
            }
            
            int ans = 0 ;
            if(num1 > num0)
            {
                ans += num0;
                num1 -= num0;
                ans += num1;
                cout << ans << endl;
            }
            else if(num1 < num0) 
            {
                ans += num1;
                num0 -= num1;
                ans += num0;
                cout << ans << endl;
            }
            else if(num1 == num0) 
            {
                ans = num1;
                cout << ans << endl;
            } 
        }
    }
    
    return 0;
}

Problem - C - Codeforces

C题,看完题目就可以大概猜到 是一种贪心,也算是一种模拟吧(个人觉得);

根据对几组数据的分析,我们可以知道当 持续到下一个发信息的时刻消耗的电量 <= 关机开机的电量的时候;

我们选择 待机, 否则我们就要 选择关机;最后判断 如果剩余电量 f > 0 那么就YES 否则就是NO;

注意当f = 0的时候 也是表示不成功NO;

还有就是要记得开LL,同时关闭同步流;

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int k;
    cin >> k;
    
    while(k --)
    {
        LL n , f , a ,b;
        cin >> n >> f >> a >> b;
        LL t[N];
        for(int i = 1 ; i <= n ; i ++) cin >> t[i];

        for(int i = 1 ; i <= n ; i ++)
        {
            if(f <= 0) 
                break;
            f -= min((t[i]-t[i-1])*(LL)a , b);
        }
        
        if(f > 0) cout << "YES" << endl;
        else if(f <= 0 )cout << "NO" << endl;
    }
    
    return 0;
}

Problem - D - Codeforces

这一题,也是一题贪心的思想,要求绝对值的差值最大;我们将两个数组排序后,进行贪心;

对比A数组最大的数 - B数组最小的数的 绝对值 和 A数组最小的数 - B数组最大的数 的绝对值 进行比较;

找到哪个比较大,进行筛选;从而确定 新数组;

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
typedef long long LL;
int a[N] , b[N];

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int k;
    cin >> k;
    
    while(k --)
    {
        int n,m;
        cin >> n >> m;
        
        for(int i = 1; i <= n ; i ++) cin >> a[i];
        for(int i = 1; i <= m ; i ++) cin >> b[i];
        
        sort(a + 1 , a + 1 + n);
        sort(b + 1 , b + 1 + m);
        
        LL ans = 0;
        int st1 = 1 , ed1 = m;
        int st2 = 1 , ed2 = n;
        
        for(int i = 1 ; i <= n ; i ++)
        {
            if(abs(a[st1] - b[ed1]) >= abs(a[ed2] - b[st2]))
            {
                ans += abs(a[st1] - b[ed1]);
                st1 ++;
                ed1 --;
            }
            else 
            {
                ans += abs(a[ed2] - b[st2]);
                st2 ++;
                ed2 --;
            }
        }
        cout << ans << endl;
    }
    
    return 0;
}

标签:cout,int,LL,Codeforces,long,cin,920,div3
From: https://www.cnblogs.com/volapex-lord/p/17974636

相关文章

  • Codeforces edu 161 (div2)
    Problem-A-Codeforces思维题,判断c字符串的每一位是否都能在相对应的a字符串或者b字符串里面找到;如果都能找到的话就输出NO;否则输出YES;#include<bits/stdc++.h>usingnamespacestd;intmain(){std::ios::sync_with_stdio(false);cin.tie(0);cout.tie......
  • Educational Codeforces Round 161 (Rated for Div. 2)
    EducationalCodeforcesRound161(RatedforDiv.2)比赛链接A.TrickyTemplate思路:貌似只要想到了就可以,我是记录了一下字符串c和字符串a和b之间的满足数,如果等于n表示一定不存在,否则就是存在的Code:#include<bits/stdc++.h>usingnamespacestd;#defineintlonglon......
  • CodeForces & AtCoder rating 规则简述
    译者:rui_er,转载请注明出处。(备份自2020年11月2日的同名博客)本博客为了方便自己查阅,同时也方便大家了解,但因为我英语很菜,所以难免有翻译错的地方,还请评论区纠正。未注明资料来源的均为常识积累。1CodeForcesrating规则1.1CodeForcesrating与名字颜色换算设\(r\)......
  • hey_left 8 Codeforces Round 871 (Div. 4)
    题目链接A.直接比较输入字符串和已知字符串有几个不同即可#include<bits/stdc++.h>usingnamespacestd;voidsolve(){strings;cin>>s;intans=0;stringt="codeforces";for(inti=0;i<10;i++){if(s[i]!=t[i])ans++;}cout<&......
  • hey_left 7 Codeforces Round 886 (Div. 4) 续
    题目链接F.记录下出现的数字和个数注意放置陷阱的位置1-n都有可能然后遍历1-n,对每个数进行因子分解,对于在因子的位置上有青蛙的,加上青蛙的个数,取最大即可#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=2e5+10;voidsolve(){int......
  • CodeForces 1466H Finding satisfactory solutions
    洛谷传送门CF传送门考虑给定\(b\)如何构造\(a\)。拎出基环树的环部分,把这些点连同它们的边删掉(这个环一定在答案中)。递归做即可。考虑我们在\(a\)的环上连一些在\(\{b_{i,n}\}\)中排得比\(a_i\)前的\(i\toj\)。可以将问题转化为,若干个环,缩点后连一些边使得它成......
  • hey_left 6 Codeforces Round 886 (Div. 4)
    题目链接A.判总和-最小值的差是否大等于10即可#include<bits/stdc++.h>usingnamespacestd;constintN=2e5+10;voidsolve(){inta,b,c;cin>>a>>b>>c;intans=a+b+c;ans-=min({a,b,c});if(ans>=10){cout<<"YES&qu......
  • CodeForces 986F Oppa Funcan Style Remastered
    洛谷传送门CF传送门有意思的。对\(k\)分解质因数,题目实际上是想让我们解一个\(\sum\limits_{i=1}^ma_ix_i=n\)的方程。考虑\(m=1\)特判,\(m=2\)exgcd。\(m=3\)时发现\(\min\limits_{i=1}^ma_i\lek^{\frac{1}{3}}\le10^5\),所以可以跑同余最短路。......
  • CodeForces 814E An unavoidable detour for home
    洛谷传送门CF传送门考虑给图分层,一层的点一一对应上一层的一些点。设\(f_{i,j}\)为考虑了前\(i\)个点,最后一层有\(j\)个点,除了最后一层点的其他点度数限制已经满足的方案数。转移系数是\(g_{i,j,k}\)表示这一层有\(i\)个点,上一层有\(j\)个\(2\)度点,\(k\)个......
  • Codeforces Round 920 (Div. 3)
    题目链接:CodeforcesRound920(Div.3)PS:很长时间没写题,状态不好,写的很差A.Square题意:给出正方形四个点的坐标,求面积解题思路:签到查看代码 voidsolve(){ vector<PII>v; for(inti=1;i<=4;i++){ intx,y; cin>>x>>y; v.push_back({x,y}); } sort......