首页 > 其他分享 >Codeforces Round #617 (Div. 3) ABCD

Codeforces Round #617 (Div. 3) ABCD

时间:2022-11-10 20:46:52浏览次数:66  
标签:ABCD typedef const cout LL cin 617 Div sum

https://codeforces.com/contest/1296

临时和Juang一起组队打的这场,本来定的分开打另一场,哈哈
题目挺友好的,Juang 70min AK了,我只写了四题,剩下的题目待补

A. Array with Odd Sum

题目大意:

给定n个数字,问我们在这一种操作下:ai变成aj;

能不能让总和为奇数?
input 
5
2
2 3
4
2 2 8 8
3
3 3 3
4
5 5 5 5
4
1 1 1 1
output 
YES
NO
YES
NO
NO
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL ji=0,ou=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(a[i]%2==1) ji++;
            else ou++;
        }
        if(n%2==1&&ji>=1) cout<<"YES"<<endl;
        else if(n%2==0&&ji>=1&&ou>=1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

B. Food Buying

题目大意:

给定钱数n,每次我们花m块钱,就可以返回m/10块钱给我们

问我们最多花了多少钱?
input 
6
1
10
19
9876
12345
1000000000
output 
1
11
21
10973
13716
1111111111
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
LL a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        LL sum=n;
        while(n>=10)
        {
            sum+=n/10;

            n=n/10+n%10;
        }
        cout<<sum<<endl;
    }
    return 0;
}

C. Yet Another Walking Robot

题目大意:

一开始机器人的坐标位于(0,0);每次给定四个方向,让我们在保持最后到达的点不变的基础上,最小化删除字符串的长度。
input 
4
4
LRUD
4
LURD
5
RRUDU
5
LLDDR
output 
1 2
1 4
3 4
-1
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    cin>>T;
    while(T--)
    {
        LL n;
        cin>>n;
        string s;
        cin>>s;
        s="  "+s;
        //cout<<s<<endl;
        map<PII,LL> mp;
        LL x=0,y=0,l=0,r=0,len=1e9;
        mp[{x,y}]=1;
        for(LL i=2;i<s.size();i++)
        {
            if(s[i]=='L')
            {
                if(mp[{x-1,y}])
                {
                    if((i-mp[{x-1,y}]+1)<len)
                    {
                        len=i-mp[{x-1,y}]+1;
                        l=mp[{x-1,y}]+1,r=i;
                    }
                }
                x--;
                mp[{x,y}]=i;
            }
            else if(s[i]=='R')
            {
                if(mp[{x+1,y}])
                {
                    if((i-mp[{x+1,y}]+1)<len)
                    {
                        len=i-mp[{x+1,y}]+1;
                        l=mp[{x+1,y}]+1,r=i;
                    }
                }
                x++;
                mp[{x,y}]=i;
            }
            else if(s[i]=='U')
            {
                if(mp[{x,y+1}])
                {
                    if((i-mp[{x,y+1}]+1)<len)
                    {
                        len=i-mp[{x,y+1}]+1;
                        l=mp[{x,y+1}]+1,r=i;
                    }
                }
                y++;
                mp[{x,y}]=i;
            }
            else if(s[i]=='D')
            {
                if(mp[{x,y-1}])
                {
                    if((i-mp[{x,y-1}]+1)<len)
                    {
                        len=i-mp[{x,y-1}]+1;
                        l=mp[{x,y-1}]+1,r=i;
                    }
                }
                y--;
                mp[{x,y}]=i;
            }
            //cout<<x<<" "<<y<<endl;
        }
        if(l==0&&r==0) cout<<"-1"<<endl;
        else cout<<l-1<<" "<<r-1<<endl;
    }
    return 0;
}

D. Fight with Monsters

题目大意:

给定一个长度为n的数组s,a是我的攻击力,b是对手的攻击力,我有k次魔法;

魔法的功能是可以每次当轮到对手攻击的时候,我可以不让他动,而让我动。(自动抵消一次他的操作)

对于这些怪兽,我们每次都可以自己选择打哪一个,并不是一定要严格按照下标值来进行攻击。

每次的攻击都是我先打,然后对手再打!!

问我们最优的情况下我们可以得到最多是多少分?(每次只要这个怪兽是在我的攻击下血量<=0的,那就意味着我的了一分,对手打死了的和我的得分没有关系)
input 
6 2 3 3
7 10 50 12 1 8
output 
5
input 
1 1 100 99
100
output 
1
input 
7 4 2 1
1 3 5 4 2 7 6
output 
6

读了好久的假题,我跌,不然早开出了,慢的一批

  • 每次自己可以打死的,那就直接计数,如果在我打不死这个怪兽的情况下,就看看我需要多少步能打死这个怪兽?
  • 如果我的k满足步数的话,直接计数,不然就只能让队友打死了
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL INF=1e9;
const LL N=5000200,M=2002;
LL sum[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        LL n,a,b,k;
        cin>>n>>a>>b>>k;
        LL ans=0;
        for(LL i=1;i<=n;i++)
        {
            cin>>sum[i];
            sum[i]%=(a+b);
            if(sum[i]==0) sum[i]=a+b;
        }
        sort(sum+1,sum+1+n);
        /*for(LL i=1;i<=n;i++)
        {
            cout<<sum[i]<<" ";
        }
        cout<<endl;*/
        for(LL i=1;i<=n;i++)
        {
            if(sum[i]<=a) ans++;
            else
            {
                sum[i]-=a;
                LL flag=sum[i]/a;
                if(sum[i]%a!=0) flag++;
                if(k>=flag)
                {
                    k-=flag;
                    ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

标签:ABCD,typedef,const,cout,LL,cin,617,Div,sum
From: https://www.cnblogs.com/Vivian-0918/p/16878691.html

相关文章

  • Codeforces Round #702 (Div. 3) G
    G.OldFloppyDrive维护一个前缀和再维护一个单调的前缀和因为我们后面的数花费更大只有贡献更大的时候才会有用这样就好做了对于每个查询我们知道他最少的轮数肯定......
  • Codeforces Round #704 (Div. 2) D
    D.Genius'sGambit构造要是a>=k的构造很好想出来但是a+b-1>k&&k>a时其实也可以构造出来我们考虑让中间的一些1经过减法变成0然后到高位时再与低位的1相减例如:1111......
  • 指定div滚到到指定位置
    获取页面某一元素的绝对X,Y坐标varX=$('#ElementID').offset().top;varY=$('#ElementID').offset().left;获取相对(父元素)位置:varX=$('#ElementID').position(......
  • Codeforces Round #740 (Div. 1, based on VK Cup 2021 - Final (Engine)) B
    B.UptheStrip考虑dpdp[i]表示当前i位置的cnt考虑转移我们对于第一个操作显然只用维护一个后缀和即可dp[i]+=s[i+1]对于第二个操作也很简单我们知道i的值z除一......
  • Codeforces Round #715 (Div. 1) A
    A.BinaryLiterature我们观察发现就是找两个串要是最长公共子序列大于等于n的我们就一定可以构造出一个出来但是传统的最长公共子序列是n2的我们考虑一些特殊的性质......
  • JavaScript实现滚动条滚动给div加颜色
    实现原理当滚动的距离大于某一个元素到页面顶部的距离时候,给元素设置实现步骤1.获取某一个元素到页面顶部的距离2.如果距离大于零则给div加上颜色,如果等于0,即归位的时......
  • 为什么我们必须使用div?
    那么,为什么我们必须使用div?如果您查看Mozilla的html5元素列表,则每个元素都有语义,然后我们进入<div>并显示:“表示没有特殊含义的通用容器。......
  • ABC 276 ABCDE(dfs)
    A-Rightmost#include<bits/stdc++.h>usingnamespacestd;typedeflonglongLL;typedefpair<LL,LL>PII;constLLMAXN=1e18;constLLINF=1e9;constLLN=5000......
  • vue.js3:div上添加右键菜单([email protected])
    一,js代码:<template><div><divstyle="width:800px;margin:auto;display:flex;flex-direction:column;"><div>请选择上传图片:<inputtype="......
  • CF1743 Codeforces Round #832 (Div. 2)
    A.TwoGroups签到题,把正负数分开放再相减即可.赛后从大佬们那得知也可以直接加的,最后取个abs.膜拜大佬!B.BANBAN构造.显然每次交换最多可以破坏前面一个BAN,破坏后面......